Creating payments
To build your own integration with PayPro the easiest way is to use our Payments API. With this API you can create payments which your customers can pay.
If you are looking for a no code or simpler integration check our Payment page solution or our other integrations.
Basic payment flow
In the simplest form you have to perform three steps to accept payments.
- Create a Payment with our Payments API
- Redirect your customer to our hosted payment page
- Listen for webhook events
Create the Payment
The first step is to create a Payment when you want the customer to pay for something. You can do this by using Payments API.
You have to fill in an amount
, currency
, description
and although optional a return_url
will make sure the customer is redirected back to your site after the payment has been successful.
$payment = $paypro->payments->create(
[
'amount' => 500,
'currency' => 'EUR',
'description' => 'Payment description',
'return_url' => 'https://example.org/thank-you'
]
);
payment = PayPro::Payment.create(
amount: 500,
currency: 'EUR',
description: 'Payment description',
return_url: 'https://example.org/thank-you'
)
You now a have a Payment object created which you can use to interact and track your customer payment journey.
Redirect customer
In order for the customer to pay the created payment we need to redirect them to the checkout URL. You can get the checkout link from the created payment.
$checkout_url = $payment->links['checkout'];
header('Location: ' . $checkout_url);
exit();
# This assumes you are using Rails which has a redirect_to method
checkout_url = payment.links['checkout']
redirect_to checkout_url
When redirecting the customer to the checkout URL the customer will leave you site and depending on the payment method they will have to fill in additional details, and they may get sent to their bank or card issuer to authenticate the transaction.
After your customer has finished paying they will be either redirected to a PayPro hosted success page or to the return_url
specified in the Payment API call.
Listen for webhook events
It is important to note that the customer will not always return to the return_url
. There are a lot of reasons why this can happen, for instance a network error or the customer closed their browser. This however does not necessarily mean the customer did not pay.
For this reason it is important to implement our Webhooks which will sent events for various resources you create with our API including payments. You can check more about webhooks on its own page.
IMPORTANT
Since webhook events are asynchronous you cannot be sure they will arrive before the customer returns to the return_url
. This means you should take this into account when a customer returns to your site. Only when you confirm that the status of the payment is paid
should you send your confirmation mails and start order fulfilment.