Postbacks

Use postbacks to be notified about events that happen in your PayPro account.

Postbacks, also called webhooks, are a way to communicate between the PayPro servers and your servers. Postbacks are simple POST requests that are send when events occur in your PayPro account. A merchant has the ability to setup postbacks and listen to these events.


Why use postbacks

Most changes in your account happen asynchoronously and do not require an API request to trigger. This creates the problem that there is no way for you to know what happens and when.

Postbacks solve this issue by allowing you to register a URL endpoint that will be notified on new events. PayPro will send POST requests, with relevant data for the type of event that occured to the registered endpoint.

These are some example use cases:

  • Sending an email on a completed payment.
  • Sending a product when a new subscription installment has been paid.
  • Update your backend system with status changes.
  • Check when there are chargebacks for direct debits.

Configuring postbacks

There are two methods for configuring postbacks.

When creating payments

When you use create_payment, create_product_payment or create_invoice you can set the parameter postback_url. This URL will be used for all postbacks for this payment.

1
2
# Set `postback_url` to `https://www.mywebshop.nl/postback`
client.params = { postback_url: 'https://www.mywebshop.nl/postback' }
1
2
3
<?
// Set `postback_url` to `https://www.mywebshop.nl/postback`
$client->setParams(["postback_url" => "https://www.mywebshop.nl/postback"]);

User postbacks

If you want to use one single postback URL for your whole account, you can set the postback URL in the PayPro Dashboard settings.

The postback_url parameter takes precedence over the account settings.


Types of postbacks

There are several types of postbacks you can receive. Each postback type is a different type of event in the PayPro system.

Verkoop

When you create a new payment or subscription there will be a Verkoop postback. This postback contains information about the payment or subscription.

Termijn

The Termijn postback gets sent when a new installment is created for a payment or subscription. For single payments you will only get one, but for subscriptions you can get several.

Termijnstatus

When an installment changes its status, a postback will be sent with the type Termijnstatus. You can use this with subscriptions to check if an installment is already paid.

Factuur

This postback will be sent when you create an invoice.

Pauzeren

When a subscription or recurring payment gets paused, you will receive this postback.

Hervatten

When a subscription or recurring payment is resumed, you will receive this postback.


Handeling postbacks

In order to handle postbacks we need an URL endpoint. This can be a simple file on your server or if you use a framework, you probably need to add a new route/controller to setup an endpoint.

The examples below will only show the postback handeling code and not the code to create a page.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Setup client that we can use later. Use your own API key here.
client = PayPro::Client('YOUR_API_KEY')

# params contain the POST variables, like in Rails.

# Postback type is the type of the postback.
type = params[:type]

# Handle different postback types. In this example we handle `Verkoop` and `Termijnstatus` postbacks.
# For `Verkoop` we will show the current payment status.
# For `Termijnstatus` we will show the status of an individual installment from a subscription.
case type
when 'Verkoop'
  # Get the payment hash.
  payment_hash = params[:payment_hash]

  # Use `get_sale` command to get additional information of the payment.
  client.command = 'get_sale'
  client.params = { payment_hash: payment_hash }
  response = client.execute

  # Show the status of the payment.
  puts "Payment has status #{response['current_status']}"
when 'Termijnstatus'
  # Get payment/subscription id.
  id = params[:id]

  # Get the installment number.
  period_number = params[:period_number]

  # Get the installment status.
  status = params[:period_state]

  # Show the status of the installment.
  puts "Installment #{period_number} of subscription #{id} has the status #{status}"
else
  puts "Invalid postback type"
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?
// Setup client that we can use later. Use your own API key here.
$client = new \PayPro\Client('YOUR_API_KEY');

// $_POST contains the POST variables.

// Postback type is the type of the postback.
$type = $_POST["type"];

// Handle different postback types. In this example we handle `Verkoop` and `Termijnstatus` postbacks.
// For `Verkoop` we will show the current payment status.
// For `Termijnstatus` we will show the status of an individual installment from a subscription.
switch($type) {
  case 'Verkoop':
    // Get payment hash.
    $payment_hash = $_POST['payment_hash'];

    // Use `get_sale` command to get additional information of the payment.
    $client->setCommand('get_sale');
    $client->setParams(["payment_hash" => $payment_hash]);
    $response = $client->execute();

    // Show the status of the payment.
    echo "Payment hash the status {$response['current_status']}";
    break;
  case 'Termijnstatus':
    // Get payment/subscription id.
    $id = $_POST['id'];

    // Get the installment number.
    $period_number = $_POST['period_number'];

    // Get the installment status.
    $status = $_POST['period_state'];

    // Show the status of the installment
    echo "Installment $period_number of subscription $id has the status $status";
    break;
  default:
    echo "Invalid postback type";
    break;
}

Placeholders

The postback URL also allows placeholders to be set. These placeholders will contain information about the payment and will be inserted into the URL when the postback is sent.

The following placeholders are allowed for the postback URL:

  • {CUSTOM} Tracker variable or custom field for the merchant. Will be inserted in the affiliate link.
  • {AMOUNT} Amount of the payment, in cents.
  • {AMOUNT_EURO} Amount of the payment, in euro's. (500 cents becomes 5.00)
  • {AMOUNT_AFFILIATE} Amount of the affiliate commission, in cents.
  • {AMOUNT_AFFILIATE_EURO} Amount of the affiliate commission, in euro's. (500 cents becomes 5.00)
  • {NET} Net amount added to the merchant' account. Only available for merchants.
  • {ID} ID of the payment.

Some examples:

  • https://webshop.nl/postback?custom={CUSTOM}
  • https://webshop.nl/postback/{CUSTOM}
  • https://webshop.nl/postback?amount={AMOUNT}&affiliate_amount={AFFILIATE_AMOUNT}

Guidelines

Using the postback_url parameter.

When using these placeholders with the postback_url parameter, you have to make sure that the query parameters are URL encoded. This means the above examples become:

  • https://webshop.nl/postback?custom=%7BCUSTOM%7D
  • https://webshop.nl/postback/%7BCUSTOM%7D
  • https://webshop.nl/postback?amount=%7BAMOUNT%7D&affiliate_amount=%7BAFFILIATE_AMOUNT%7d