Table of content
- What is pre-approved payment?
- How does pre-approved payment work?
- Initial authorization
- Making recurring or multiple payments
- Flexibility for the customer
- Typical uses of pre-approved payment
- Subscriptions
- Automatic billing
- Deferred payments
- How to integrate PayPal pre-approved payment on your website?
- 1. Set up a PayPal Business account
- 2. Enable PayPal Payments API
- 3. Configure the development environment
- 4. Create a pre-approved payment
- 5. Capture future payments
- 6. Test the integration
- 7. Go to production
Do you want to integrate PayPal pre-approved payment on your website? That's good, in this article, we will see together how to do it. As you know, if you are a business and want to sell subscriptions on your website, pre-approved payment is the option you need. Indeed, it allows you to request payment from your customers without being constantly behind them for complaints. In this article, we will briefly see what pre-approved payment is. Then, we will explain how it works. Finally, we will see how you can integrate it on your website. If you want ready-to-use code, you can click on this link and contact us .
What is pre-approved payment?
It is a mechanism used by platforms like PayPal that allows a merchant or service provider to automatically charge a customer's account. You can do this without asking for their explicit approval for each transaction after the initial authorization. This type of payment is commonly used for recurring payments. Businesses use it for subscriptions or for multiple purchases where the user has given a one-time authorization for future transactions.
How does pre-approved payment work?
The way pre-approved payments work is as follows:
Initial authorization
The customer gives consent for their PayPal account to be automatically charged in the future. This is usually done by agreeing to a Billing Agreement with the merchant. In this step, PayPal asks the customer to confirm that they authorize future payments.
Making recurring or multiple payments
After this initial authorization, the merchant can trigger automatic payments without the customer needing to approve each time. This is useful for services like
- monthly subscriptions,
- due invoices,
- or delivery services with deferred payments.
Flexibility for the customer
The customer retains control over these payments by being able to cancel the billing agreement at any time through their PayPal account.
Typical uses of pre-approved payment
If you consume online services, you have certainly had the opportunity to use recurring payments.
Subscriptions
For services that require monthly, weekly or annual payments (like Netflix, Spotify).
Automatic billing
For utilities or other regular bills where the amount may vary (telephone, electricity).
Deferred payments
For services that allow the customer to make multiple purchases without having to approve each payment (e.g., ride-sharing or home rental platforms). In short, a pre-approved payment allows a customer to give consent once for a series of future transactions, facilitating automated payments without requiring manual intervention each time.
How to integrate PayPal pre-approved payment on your website?
To integrate a PayPal pre-approved payment on your website, you need to follow the steps below:
1. Set up a PayPal Business account
- Make sure you have a PayPal Business account. If you don't have one yet, you can create one through the official PayPal website.
2. Enable PayPal Payments API
- Go to your PayPal Developer Dashboard ( developer.paypal.com ).
- Log in with your Business account.
- Under My Apps & Credentials , generate the credentials (Client ID and Secret) for the Sandbox (for testing) or Live (for production) environment.
- Enable the Reference Transactions API to enable pre-approved payments. This feature is not enabled by default, and you may need to contact PayPal to enable it.
3. Configure the development environment
- Install a PayPal SDK or library to make integration easier. For example, you can use the PayPal PHP or JS SDK.
For PHP , you can use Composer to install the PayPal SDK:
composer require paypal/rest-api-sdk-php
For JavaScript , simply include the PayPal script on your page:
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID"><script>
4. Create a pre-approved payment
Use the PayPal API to create a pre-approved payment. Here are the main steps to follow:
- Create a Billing Agreement that allows the customer to pre-approve future payments.
- Generate payment token from billing agreement.
- When the customer approves the payment, you can then make recurring or pre-approved payments without having to ask the customer for approval each time.
Example API call to create a Billing Agreement:
$agreement = new Agreement(); $agreement->setName('Payment Agreement') ->setDescription('Agreement for future payments') ->setStartDate('2023-12-20T10:00:00Z'); $plan = new Plan(); $plan->setId('P-xxxxxxxxxxxx'); $agreement->setPlan($plan); $payer = new Payer(); $payer->setPaymentMethod('paypal'); $agreement->setPayer($payer); try { $agreement->create($apiContext); $approvalUrl = $agreement->getApprovalLink(); echo "Redirect user to: " . $approvalUrl; } catch (Exception $ex) { // Handle exception }
5. Capture future payments
Once the customer is redirected to the PayPal confirmation URL, you can use the returned token to capture payments in the future. Example to capture a pre-approved payment:
$agreement = new Agreement(); $agreement->execute($token, $apiContext);
6. Test the integration
Before going to production, use the Sandbox environment to test all transactions. Ensure that payments are captured correctly and that you can run recurring or pre-approved transactions.
7. Go to production
Once testing is complete, replace the Sandbox credentials with the Live credentials in your code. This integration allows you to charge the customer's PayPal account automatically without requiring new authorizations after the initial approval.
Leave a comments: