> ## 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 One-Time Transactions

For the PayPal payment method, the status of a transaction after an `authCapture()` call is `AuthorizationPending`. The payment flow for PayPal-based real-time transactions proceeds as follows:

1. When a customer clicks the PayPal button on your site, create a `Transaction` object that specifies PayPal as the payment method, and make a `Transaction.authCapture()` call.
2. When that call returns, examine the status of the returned `Transaction` object. If the status is not a failure (`Cancelled`), it is `AuthorizationPending`, which means that the transaction is in the Subscribe and PayPal systems, and that it requires further action from the customer for completion.
3. PayPal notifies Subscribe of the successful creation of the Transaction by issuing a PayPal token, which keeps the transaction valid for the next few hours.
4. The returned `Transaction` object contains a PayPal-specific status along with a URL, which contains the token information. Redirect the customer to that URL to complete PayPal’s payment process.
5. Depending on the customer’s success or failure in completing the payment process, PayPal redirects the customer to a Subscribe landing page, along with an indication of whether the payment succeeded or failed. That landing page in turn redirects the customer to a success or failure URL on your site. (Provide Subscribe the success and failure URLs as attributes `returnUrl` and `cancelUrl` of the PayPal payment method for the transaction.) From this page, make a call to Subscribe to finalize the PayPal authorization so that Subscribe can update the status of the transaction. This call requires you to pass in the ID of the transaction, which you can find in the redirected URL. It is value-associated with name: `vindicia_vid` in the redirect URL.

## Use PayPal for a one-time transaction

```

 $tx = new Transaction();
  
 // populate the transaction as shown in earlier examples
  
 $paymentMethod = new PaymentMethod();
 $paymentMethod->setType('PayPal');
  
 $payPal = new PayPal();
  
 // request a ReferenceId from PayPal
 $payPal->setRequestReferenceId('true');
  
 // Set the URL to which the customer will be redirected after 
 // completing the payment process at PayPal’s site, and 
 // returning to Vindicia’s landing page.
  
 $payPal->setReturnUrl('http://myshoppingcart.merchant.com'); 
  
 // specify the bank routing number
 $payPal->setCancelUrl('http://tryagain.merchant.com');
  
 $paymentMethod->setPayPal($payPal);
  
 $tx->setSourcePaymentMethod($paymentMethod);
  
 $sendEmailNotification = false;
 $response = $tx->authCapture($sendEmailNotification);
  
 if($response['returnCode']==200) {
  
 if($tx->statusLog[0]->status=='AuthorizationPending') {
 $payPalUrl = $tx->statusLog[0]->payPalStatus->redirectUrl;
  
 // send customer to this URL for completion of payment 
 // formalities at PayPal's site
 }
 else if($tx->statusLog[0]->status=='Cancelled') {
 // The transaction was not accepted by PayPal 
 }
 }
```

After successfully completing the payment process, the customer is redirected to the return URL in the PayPal-based object.`PaymentMethod`From this page, finalize the Transaction to update its status in Subscribe.

```

 $soap_caller = new Transaction();
  
 // obtain id of the PayPal 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, from the cancelUrl it should
 // be set to false. Let’s assume success here:
  
 $success = true;
 $response = 
 $soap_caller->finalizePayPalAuth($payPalTxId, $success);
  
 if($response['returnCode'] == 200) {
 printLog "Transaction authorized";
 }
```

Subscribe updates the Transaction status to `Authorized`, which changes to `Captured` after Subscribe has finished processing this and other PayPal transactions in a batch.

**Note:** If you request that PayPal return a `referenceId` for the Transaction, its `paymentMethod` may be used for recurring payments. For more information, see [Using PayPal for Recurring Billing](Using_PayPal_for_Recurri#), and the Using Subscribe with PayPal white paper, available from Vindicia Client Services.

**Parent topic:**[Working with One-Time Transactions](../topics/ProgGuide_Transactions)


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