> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slm.m1amdocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using PayPal for Recurring Billing

To set up AutoBill-based recurring billing with PayPal, you must be preapproved by PayPal to conduct `reference transactions`. Contact Vindicia Client Services for more information.

**Note:** Not all merchants will be authorized to obtain the `referenceId` from PayPal. Work with your PayPal representative to obtain the right to use this process.

If the `PaymentMethod` exists and contains a `ReferenceID` for PayPal, Subscribe uses that `PaymentMethod`. If the`PaymentMethod` does not exist, or does not contain a Reference ID for PayPal, Subscribe returns a URL in the `authStatus` field. The consumer can be redirected to the URL to make a payment.

## Set up recurring billing in an AutoBill

1. Set the following for the PayPal payment method (`PaymentMethod` object and its `payPal` attribute) on `AutoBill`, or on the `Account` object if the settings are not specified on `AutoBill`:
   1. Set `emailAddress` to the subscriber’s email address.
   2. Set `returnUrl` to an existing URL on your site to which the customer will be redirected after a successful authentication with PayPal.
   3. Set `cancelUrl` to an existing URL on your site to which the customer will be redirected after a failed authentication, that is, if PayPal does not authorize the payment information.
2. Call `update()` to create the `AutoBill` object, and return a `TransactionStatus` object. The `TransactionStatus` object must contain a URL in the `redirectUrl` field, to which the customer will be redirected to complete the PayPal payment process. Without completion of this step, recurring billing will not begin.

## Retrieve the redirectUrl

```
 
 $minChargebackProbability = 90;
  
 $duplicateBehavior = 'Fail';
  
 // Call update to update or create the autobill on Vindicia servers
  
 $response = $autobill->update($duplicateBehavior,
       $validatePaymentMethod, $minChargebackProbability);
  
 if($response['returnCode'] == 200) {
    printLog "AutoBill created \n";
  
    $txnStatus = $response['data']->refundsauthStatus;
    $redirectUrl = $txnStatus->payPalStatus->redirectUrl
    print "Visit " . $redirectUrl . 
       " to complete payment at PayPal site"
 }
```

While waiting for the customer to complete payment at PayPal, the `AutoBill` object will have status: `PendingCustomerAction`. The object is dormant and will not perform any billing.

At the PayPal site, the customer logs in and agrees to the contract for recurring billing. When the process is complete, the customer clicks a button that takes them to your success page (`returnUrl`) or failure page (`cancelUrl`). From the success page, make the `finalizePayPalAuth()` call to inform Subscribe of successful authorization of the PayPal-based payment method. After receiving the successful authorization, the status of the `AutoBill` object changes to `New` , indicating that the subscription has started and that the `AutoBill` will start billing the customer according to the specified dates.

## Finalize the PayPal payment method authorization

```

...
$soap_caller = new AutoBill();
  
 // obtain id of the PayPal validation transaction
 // from the redirect URL. It is the value associated with name
 // 'vindicia_vid'
  
 $payPalTxId = … ;
  
 // if calling from return URL which is reached when the PayPal
 // transaction is successfully authorized you should set the
 // success input parameter to true
  
 $success = true;
 $response = 
       $soap_caller->finalizePayPalAuth($payPalTxId, $success);
  
 if($response['data']->refunds['returnCode'] == 200) {
    printLog "PayPal validation transaction successful";
    printLog "- subscription started";
 }
```

For every subsequent transaction performed by the `AutoBill` object, no action will be required from the customer. PayPal will notify the customer when the transaction is complete. That notification is in addition to any communication issued by your organization through the Subscribe email notification system.

For more information, see the Using Subscribe with PayPal white paper, available from Vindicia Client Services.

**Parent topic:**[Working with AutoBills](../topics/ProgGuide_AutoBills)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.