Make your first API Call
Retrieve Payment API URL and Key from Settings in OnlineFundraising.
|PAYMENT_API_URL||Payment API URL|
|PAYMENT_API_KEY||Payment API Key specific to your organisation|
|CONTACT_GUID||A Contact GUID from an existing record in OnlineFundraising|
Run this in your terminal:
curl --location --request GET 'PAYMENT_API_URL/contact/CONTACT_GUID' \ --header 'Content-Type: application/json; charset=utf-8' \
--header 'Authorization: PAYMENT_API_KEY'
Please note that you may have to use " instead of '.
Compile and debug the following code:
var client = new RestClient("PAYMENT_API_URL/contact/CONTACT_GUID"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Content-Type", " application/json; charset=utf-8"); request.AddHeader("Authorization", "PAYMENT_API_KEY"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content);
Send your First Webhook
Configuration of webhooks is currently performed by the OnlineFundraising-team. Please contact firstname.lastname@example.org to request webhook configuration. Provide an endpoint, as this is required to setup webhooks.
Once your webhook setup is done, perform the event in OnlineFundraising to trigger the webhook. Read on for a walk-through guide of sending your first webhook.
Walk-through of sending your first webhook
Follow this example to send your first webhook when a Payment is created as a result of a submitted form.
Step 1. Configure Webhook
To start off, you have to ensure that a webhook is setup for Payments.
Step 2. Create and configure a Form
Create and configure a form like the picture below. It is important that you learn how to build forms from scratch. Once you have completed this guide we recommend that you get to know the FormBuilder more in-depth.
- Purpose (Will be hidden in the form):
- Accounting code: test
- Payments are tax deductible: True (Checked)
- Configure default field: Amount
- Input type: Radio
- Save as: Amount
- Options: 50, 100 and 150
- Reference: amount
- Add another field: Phone Number
- Input type: Number
- Save as: Phone
- Reference: phone
- Add another field: Select Payment Method
- Input type: Radio
- Save as: Payment method type
- Reference: paymentMethodType
- Add another field: Payment type
- Input type: Radio
- Save as: Payment type
- Reference: paymentType
- Read only: True (Checked)
- Hide: True (Checked)
- Add another button: Donate
- Input type: Button
- Save as: Custom field
- Reference: button
The transactional settings are found in the right column of the FormBuilder. The settings should fulfil:
- Payment types: Payment
- Payment method types: Test gateway by SMS
Scroll up and select Publish. Once the form is published, you can view the form. It should look like the form in the picture above. Note that purpose and payment type are hidden for the end-user.
Step 3. Test Form
Once the form is published, you can view the form. To test the form:
- Select an amount
- Fill out a phone number (valid for testing)
- Click Donate
- Select link: Open Payment Session (see image below)
- Select an action: Charge, Reject or Fail
- Option: Abandon the session. The result is a DataSet with result Not completed.
The payment session opens in a new window and looks like this:
Once the action is performed, the payment session ends.
Step 4. Receive Webhook
As a result of the form being submitted, the following records are created and stored in OnlineFundraising:
- Payment - Triggers webhook!
- Payment method
- DataSet (points to all of the above records)
The webhook will look something like this:
You have now received your first webhook! Parse the webhook payload and determine how to handle it in your integration.
Example - Check for Contact Duplicates based on Payment State
Often the organisation wishes to execute logic based on the outcome of a Payment. Upon receiving a Payment webhook, it is possible to fetch the Payment via the API and check if certain conditions are met.
For instance, if a Payment was successfully charged (state), the organisation may wish to ensure the Contact is unique. The Payment object looks something like this (truncated object):
"createdTs": "2019-01-01 00:00:00 +0100",
"chargedTs": "2019-01-01 00:00:00 +0100",
Use the contactGuid to fetch the Contact via the API. The resulting Contact object contains all the Contact data which is stored in OnlineFundraising.
Use the Contact data to check for duplicates in an external system such as a CRM-system. In case you identify one or more duplicates, you may wish to merge the duplicate Contacts in OnlineFundraising (and your CRM-system).