Introduction

By using this plugin you can process or refund payments and handle IPN (Instant Payment Notification) from PayPal in your Laravel application.

Note

This documentation assumes you are using Laravel 5.1+. However, you can use this package inside other frameworks & PHP application utilizing Composer.

 

PayPal API

This plugin uses the latest PayPal Rest API

Installation

Through this section, you will learn how to install & configure the package inside your Laravel applications.

Installation

For Laravel 5.1 to 5.8
								composer require srmklive/paypal:~2.0
							
For Laravel 6, 7, & 8
								composer require srmklive/paypal:~3.0
							

Publish Assets

After installation, you can use the following commands to publish the assets:

								php artisan vendor:publish --provider "Srmklive\PayPal\Providers\PayPalServiceProvider"
							

Configuration

After publishing the assets, add the following to your .env files .

								
#PayPal API Mode
# Values: sandbox or live (Default: live)
PAYPAL_MODE=

#PayPal Setting & API Credentials - sandbox
PAYPAL_SANDBOX_CLIENT_ID=
PAYPAL_SANDBOX_CLIENT_SECRET=

#PayPal Setting & API Credentials - live
PAYPAL_LIVE_CLIENT_ID=
PAYPAL_LIVE_CLIENT_SECRET=
                                
							

Configuration File

The configuration file paypal.php is located in the config folder. Following are its contents when published:

								
return [
    'mode'    => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
    'sandbox' => [
        'client_id'         => env('PAYPAL_SANDBOX_CLIENT_ID', ''),
        'client_secret'     => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''),
        'app_id'            => 'APP-80W284485P519543T',
    ],
    'live' => [
        'client_id'         => env('PAYPAL_LIVE_CLIENT_ID', ''),
        'client_secret'     => env('PAYPAL_LIVE_CLIENT_SECRET', ''),
        'app_id'            => '',
    ],

    'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order'
    'currency'       => env('PAYPAL_CURRENCY', 'USD'),
    'notify_url'     => env('PAYPAL_NOTIFY_URL', ''), // Change this accordingly for your application.
    'locale'         => env('PAYPAL_LOCALE', 'en_US'), // force gateway language  i.e. it_IT, es_ES, en_US ... (for express checkout only)
    'validate_ssl'   => env('PAYPAL_VALIDATE_SSL', true), // Validate SSL when creating api client.
];
                                
							

Usage

Initialization

								
// Import the class namespaces first, before using it directly
use Srmklive\PayPal\Services\PayPal as PayPalClient;

$provider = new PayPalClient;

// Through facade. No need to import namespaces
$provider = \PayPal::setProvider();
                                
                            

Override Configuration

You can override PayPal API configuration by calling setApiCredentials method:

								
$config = [
    'mode'    => 'live',
    'live' => [
        'client_id'         => 'some-client-id',
        'client_secret'     => 'some-client-secret',
        'app_id'            => 'APP-80W284485P519543T',
    ],

    'payment_action' => 'Sale',
    'currency'       => 'USD',
    'notify_url'     => 'https://your-app.com/paypal/notify',
    'locale'         => 'en_US',
    'validate_ssl'   => true,
];

$provider->setApiCredentials($config);
                                
                            

Change Currency

By default the currency used is USD. If you wish to change it, you may call setCurrency method to set a different currency before calling any respective API methods:

								
$provider->setCurrency('EUR');
                                
                            

Get Access Token

After setting the PayPal API configuration, you need to get access token before performing any API calls

								
$provider->getAccessToken();
                                
                            

Integrations

Create Recurring Daily Subscription

                  
                    $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
                    ->addPlanTrialPricing('DAY', 7)
                    ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50)
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Create Recurring Weekly Subscription

                  
                    $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
                    ->addPlanTrialPricing('DAY', 7)
                    ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30)
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Create Recurring Monthly Subscription

                  
                    $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
                    ->addPlanTrialPricing('DAY', 7)
                    ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100)
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Create Recurring Annual Subscription

                  
                    $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
                    ->addPlanTrialPricing('DAY', 7)
                    ->addAnnualPlan('Demo Plan', 'Demo Plan', 600)
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Create Recurring Subscription With Custom Intervals

                  
                    $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
                    ->addCustomPlan('Demo Plan', 'Demo Plan', 150, 'MONTH', 3)
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Create Subscription With Existing Product & Billing Plan

                  
                    $response = $this->client->addProductById('PROD-XYAB12ABSB7868434')
                    ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Custom: Add Setup Fee When Creating Subscription

                  
                    $response = $this->client->addSetupFee(9.99)
                    ->addProductById('PROD-XYAB12ABSB7868434')
                    ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Custom: Add Shipping Address When Creating Subscription

                  
                    $response = $this->client->addShippingAddress('John Doe', 'House no. 123', 'Street 456', 'Test Area', 'Test Area', 10001, 'US')
                    ->addProductById('PROD-XYAB12ABSB7868434')
                    ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Custom: Add Payment Failure Threshold When Creating Subscription

                  
                    $response = $this->client->addPaymentFailureThreshold(5)
                    ->addProductById('PROD-XYAB12ABSB7868434')
                    ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
                    ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
                    ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
                  
                

Custom: Update Pricing Schemes for a Billing Plan

                  
                    $response = $this->client->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
                    ->addPricingScheme('DAY', 7, 0, true)
                    ->addPricingScheme('MONTH', 1, 100)
                    ->processBillingPlanPricingUpdates();
                  
                

Billing Plans

The following snippets lists code snippets for interacting with Billing Plans API.

List Plans

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list

                                
$plans = $provider->listPlans();
                                
                            

By default, the API returns a paginated response. However if you pass your own parameters, you can do writing the following:

                                
$fields = ['id', 'product_id', 'name', 'description'];
$plans = $provider->listPlans(1, 30, true, $fields);
                                
                            

In the above snippet, we are returning the plans containing upto 30 items in each paginated response along with count details.

Create Plan

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create

                                
$data = json_decode('{
  "product_id": "PROD-XXCD1234QWER65782",
  "name": "Video Streaming Service Plan",
  "description": "Video Streaming Service basic plan",
  "status": "ACTIVE",
  "billing_cycles": [
    {
      "frequency": {
        "interval_unit": "MONTH",
        "interval_count": 1
      },
      "tenure_type": "TRIAL",
      "sequence": 1,
      "total_cycles": 2,
      "pricing_scheme": {
        "fixed_price": {
          "value": "3",
          "currency_code": "USD"
        }
      }
    },
    {
      "frequency": {
        "interval_unit": "MONTH",
        "interval_count": 1
      },
      "tenure_type": "TRIAL",
      "sequence": 2,
      "total_cycles": 3,
      "pricing_scheme": {
        "fixed_price": {
          "value": "6",
          "currency_code": "USD"
        }
      }
    },
    {
      "frequency": {
        "interval_unit": "MONTH",
        "interval_count": 1
      },
      "tenure_type": "REGULAR",
      "sequence": 3,
      "total_cycles": 12,
      "pricing_scheme": {
        "fixed_price": {
          "value": "10",
          "currency_code": "USD"
        }
      }
    }
  ],
  "payment_preferences": {
    "auto_bill_outstanding": true,
    "setup_fee": {
      "value": "10",
      "currency_code": "USD"
    },
    "setup_fee_failure_action": "CONTINUE",
    "payment_failure_threshold": 3
  },
  "taxes": {
    "percentage": "10",
    "inclusive": false
  }
}', true);

$plan = $provider->createPlan($data);
                                
                            

Update Plan

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#plans_patch

                                
$data = json_decode('[
  {
    "op": "replace",
    "path": "/payment_preferences/payment_failure_threshold",
    "value": 7
  }
]', true);

$plan_id = 'P-7GL4271244454362WXNWU5NQ';

$plan = $provider->updatePlan($plan_id, $data);
                                
                            

Get Plan Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get

                                
$plan_id = 'P-7GL4271244454362WXNWU5NQ';

$plan = $provider->showPlanDetails($plan_id);
                                
                            

Activate Plan

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate

                                
$plan_id = 'P-7GL4271244454362WXNWU5NQ';

$plan = $provider->activatePlan($plan_id);
                                
                            

Deactivate Plan

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate

                                
$plan_id = 'P-7GL4271244454362WXNWU5NQ';

$plan = $provider->deactivatePlan($plan_id);
                                
                            

Update Plan Pricing

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes

                                
$pricing = json_decode('{
  "pricing_schemes": [
    {
      "billing_cycle_sequence": 2,
      "pricing_scheme": {
        "fixed_price": {
          "value": "50",
          "currency_code": "USD"
        }
      }
    }
  ]
}', true);

$plan_id = 'P-7GL4271244454362WXNWU5NQ';

$plan = $provider->updatePlanPricing($plan_id, $pricing);
                                
                            

Catalog Products

The following snippets lists code snippets for interacting with Catalog Products API.

List Products

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/catalog-products/v1/#products_list

                                
$products = $provider->listProducts();
                                
                            

By default, the API returns a paginated response. However if you pass your own parameters, you can do writing the following:

                                
$products = $provider->listProducts(1, 30, true);
                                
                            

In the above snippet, we are returning the plans containing upto 30 items in each paginated response along with count details.

Create Product

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/catalog-products/v1/#products_create

                                
$data =  json_decode('{
  "name": "Video Streaming Service",
  "description": "Video streaming service",
  "type": "SERVICE",
  "category": "SOFTWARE",
  "image_url": "https://example.com/streaming.jpg",
  "home_url": "https://example.com/home"
}', true);

$request_id = 'create-product-'.time();

$product = $provider->createProduct($data, $request_id);
                                
                            

Update Product

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch

                                
$data = json_decode('[
  {
    "op": "replace",
    "path": "/description",
    "value": "Premium video streaming service"
  }
]', true);

$product_id = '72255d4849af8ed6e0df1173';

$product = $provider->updateProduct($product_id, $data);
                                
                            

Get Product Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/catalog-products/v1/#products_get

                                
$product_id = '72255d4849af8ed6e0df1173';

$product = $provider->showProductDetails($product_id);
                                
                            

Disputes

The following snippets lists code snippets for interacting with Disputes API.

List Disputes

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_list

                                
$products = $provider->listDisputes();
                                
                            

Update Dispute

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_patch

                                
$data = json_decode('[
  {
    "op": "add",
    "path": "/partner_actions/-",
    "value": {
      "id": "AMX-22345",
      "name": "ACCEPT_DISPUTE",
      "create_time": "2018-01-12T10:41:35.000Z",
      "status": "PENDING"
    }
  }
]', true);

$dispute_id = 'PP-D-27803';

$dispute = $provider->updateDispute($dispute_id, $data);
                                
                            

Get Dispute Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_get

                                
$dispute_id = 'PP-D-27803';

$dispute = $provider->showDisputeDetails($dispute_id);
                                
                            

Disputes Actions

The following snippets lists code snippets for interacting with Disputes Actions API.

Accept Claim

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_accept-claim

                                
$dispute_id = 'PP-D-27803';
$dispute_note = 'Dispute claim accepted due to wrong item being shipped';

$dispute = $provider->acceptDisputeClaim($dispute_id, $dispute_note);
                                
                            

Accept Offer to Resolve Dispute

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_patch

                                
$dispute_id = 'PP-D-27803';
$dispute_note = 'Accepting merchant offer of discount for next purchase';

$dispute = $provider->acceptDisputeOfferResolution($dispute_id, $dispute_note);
                                
                            

Acknowledge Returned Items

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_acknowledge-return-item

                                
$dispute_id = 'PP-D-27803';
$dispute_note = 'Items have been returned by the customer';
$acknowledgement_type = 'ITEM_RECEIVED';

$dispute = $provider->acknowledgeItemReturned($dispute_id, $dispute_note, $acknowledgement_type);
                                
                            

Invoices

The following snippets lists code snippets for interacting with Invoices API.

Generate Invoice Number

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-next-invoice-number

                                
$invoice_no = $provider->generateInvoiceNumber();
                                
                            

List Invoices

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list

                                
$invoices = $provider->listInvoices();
                                
                            

By default, a paginated response is returned containing 20 records. If you wish to provide a different page number or limit, you may do it using:

                                
$invoices = $provider->listInvoices(2, 50);
                                
                            

Create Draft Invoice

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_create

                                
$data = json_decode('{
  "detail": {
    "invoice_number": "#123",
    "reference": "deal-ref",
    "invoice_date": "2018-11-12",
    "currency_code": "USD",
    "note": "Thank you for your business.",
    "term": "No refunds after 30 days.",
    "memo": "This is a long contract",
    "payment_term": {
      "term_type": "NET_10",
      "due_date": "2018-11-22"
    }
  },
  "invoicer": {
    "name": {
      "given_name": "David",
      "surname": "Larusso"
    },
    "address": {
      "address_line_1": "1234 First Street",
      "address_line_2": "337673 Hillside Court",
      "admin_area_2": "Anytown",
      "admin_area_1": "CA",
      "postal_code": "98765",
      "country_code": "US"
    },
    "email_address": "merchant@example.com",
    "phones": [
      {
        "country_code": "001",
        "national_number": "4085551234",
        "phone_type": "MOBILE"
      }
    ],
    "website": "www.test.com",
    "tax_id": "ABcNkWSfb5ICTt73nD3QON1fnnpgNKBy- Jb5SeuGj185MNNw6g",
    "logo_url": "https://example.com/logo.PNG",
    "additional_notes": "2-4"
  },
  "primary_recipients": [
    {
      "billing_info": {
        "name": {
          "given_name": "Stephanie",
          "surname": "Meyers"
        },
        "address": {
          "address_line_1": "1234 Main Street",
          "admin_area_2": "Anytown",
          "admin_area_1": "CA",
          "postal_code": "98765",
          "country_code": "US"
        },
        "email_address": "bill-me@example.com",
        "phones": [
          {
            "country_code": "001",
            "national_number": "4884551234",
            "phone_type": "HOME"
          }
        ],
        "additional_info_value": "add-info"
      },
      "shipping_info": {
        "name": {
          "given_name": "Stephanie",
          "surname": "Meyers"
        },
        "address": {
          "address_line_1": "1234 Main Street",
          "admin_area_2": "Anytown",
          "admin_area_1": "CA",
          "postal_code": "98765",
          "country_code": "US"
        }
      }
    }
  ],
  "items": [
    {
      "name": "Yoga Mat",
      "description": "Elastic mat to practice yoga.",
      "quantity": "1",
      "unit_amount": {
        "currency_code": "USD",
        "value": "50.00"
      },
      "tax": {
        "name": "Sales Tax",
        "percent": "7.25"
      },
      "discount": {
        "percent": "5"
      },
      "unit_of_measure": "QUANTITY"
    },
    {
      "name": "Yoga t-shirt",
      "quantity": "1",
      "unit_amount": {
        "currency_code": "USD",
        "value": "10.00"
      },
      "tax": {
        "name": "Sales Tax",
        "percent": "7.25"
      },
      "discount": {
        "amount": {
          "currency_code": "USD",
          "value": "5.00"
        }
      },
      "unit_of_measure": "QUANTITY"
    }
  ],
  "configuration": {
    "partial_payment": {
      "allow_partial_payment": true,
      "minimum_amount_due": {
        "currency_code": "USD",
        "value": "20.00"
      }
    },
    "allow_tip": true,
    "tax_calculated_after_discount": true,
    "tax_inclusive": false,
    "template_id": "TEMP-19V05281TU309413B"
  },
  "amount": {
    "breakdown": {
      "custom": {
        "label": "Packing Charges",
        "amount": {
          "currency_code": "USD",
          "value": "10.00"
        }
      },
      "shipping": {
        "amount": {
          "currency_code": "USD",
          "value": "10.00"
        },
        "tax": {
          "name": "Sales Tax",
          "percent": "7.25"
        }
      },
      "discount": {
        "invoice_discount": {
          "percent": "5"
        }
      }
    }
  }
}', true);

$invoice = $provider->createInvoice($data);
                                
                            

Delete Invoice

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_delete

                                
$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';
$status = $provider->deleteInvoice($invoice_no);
                                
                            

Fully Update Invoice

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update

                                
$data = json_decode('{
  "detail": {
    "invoice_number": "#123",
    "reference": "deal-ref",
    "invoice_date": "2018-11-12",
    "currency_code": "USD",
    "note": "Thank you for your business.",
    "term": "No refunds after 30 days.",
    "memo": "This is a long contract",
    "payment_term": {
      "term_type": "NET_10",
      "due_date": "2018-11-22"
    }
  },
  "invoicer": {
    "name": {
      "given_name": "David",
      "surname": "Larusso"
    },
    "address": {
      "address_line_1": "1234 First Street",
      "address_line_2": "337673 Hillside Court",
      "admin_area_2": "Anytown",
      "admin_area_1": "CA",
      "postal_code": "98765",
      "country_code": "US"
    },
    "email_address": "merchant@example.com",
    "phones": [
      {
        "country_code": "001",
        "national_number": "4085551234",
        "phone_type": "MOBILE"
      }
    ],
    "website": "www.test.com",
    "tax_id": "ABcNkWSfb5ICTt73nD3QON1fnnpgNKBy- Jb5SeuGj185MNNw6g",
    "logo_url": "https://example.com/logo.PNG",
    "additional_notes": "2-4"
  },
  "primary_recipients": [
    {
      "billing_info": {
        "name": {
          "given_name": "Stephanie",
          "surname": "Meyers"
        },
        "address": {
          "address_line_1": "1234 Main Street",
          "admin_area_2": "Anytown",
          "admin_area_1": "CA",
          "postal_code": "98765",
          "country_code": "US"
        },
        "email_address": "bill-me@example.com",
        "phones": [
          {
            "country_code": "001",
            "national_number": "4884551234",
            "phone_type": "HOME"
          }
        ],
        "additional_info_value": "add-info"
      },
      "shipping_info": {
        "name": {
          "given_name": "Stephanie",
          "surname": "Meyers"
        },
        "address": {
          "address_line_1": "1234 Main Street",
          "admin_area_2": "Anytown",
          "admin_area_1": "CA",
          "postal_code": "98765",
          "country_code": "US"
        }
      }
    }
  ],
  "items": [
    {
      "name": "Yoga Mat",
      "description": "Elastic mat to practice yoga.",
      "quantity": "1",
      "unit_amount": {
        "currency_code": "USD",
        "value": "50.00"
      },
      "tax": {
        "name": "Sales Tax",
        "percent": "7.25"
      },
      "discount": {
        "percent": "5"
      },
      "unit_of_measure": "QUANTITY"
    },
    {
      "name": "Yoga t-shirt",
      "quantity": "1",
      "unit_amount": {
        "currency_code": "USD",
        "value": "10.00"
      },
      "tax": {
        "name": "Sales Tax",
        "percent": "7.25"
      },
      "discount": {
        "amount": {
          "currency_code": "USD",
          "value": "5.00"
        }
      },
      "unit_of_measure": "QUANTITY"
    }
  ],
  "configuration": {
    "partial_payment": {
      "allow_partial_payment": true,
      "minimum_amount_due": {
        "currency_code": "USD",
        "value": "20.00"
      }
    },
    "allow_tip": true,
    "tax_calculated_after_discount": true,
    "tax_inclusive": false,
    "template_id": "TEMP-19V05281TU309413B"
  },
  "amount": {
    "breakdown": {
      "custom": {
        "label": "Packing Charges",
        "amount": {
          "currency_code": "USD",
          "value": "10.00"
        }
      },
      "shipping": {
        "amount": {
          "currency_code": "USD",
          "value": "10.00"
        },
        "tax": {
          "name": "Sales Tax",
          "percent": "7.25"
        }
      },
      "discount": {
        "invoice_discount": {
          "percent": "5"
        }
      }
    }
  }
}', true);

$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$invoice = $provider->updateInvoice($invoice_no, $data);
                                
                            

Show Invoice Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_get

                                
$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$invoice = $provider->showInvoiceDetails($invoice_no);
                                
                            

Cancel Sent Invoice

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_cancel

                                
$data = json_decode('{
  "subject": "Invoice Cancelled",
  "note": "Cancelling the invoice",
  "send_to_invoicer": true,
  "send_to_recipient": true,
  "additional_recipients": [
    "user@example.com"
  ]
}', true);

$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$status = $provider->cancelInvoice($invoice_no, $data);
                                
                            

Generate QR Code

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-qr-code

                                
$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';
$status = $provider->generateQRCodeInvoice($invoice_no);
                                
                            

By default, a QR code of 100x100 is generated. However, if you wish to generate a QR code with different width & height. You may use the following snippet:

                                
$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';
$status = $provider->generateQRCodeInvoice($invoice_no, 50, 50);
                                
                            

Record Payment for Invoice

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments

                                
$payment_method = 'BANK_TRANSFER';

$payment_date = '2018-05-21';

$amount = 10;

$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$status = $provider->registerPaymentInvoice($invoice_no, $payment_date, $payment_method, $amount);
                                
                            

Delete External Payment

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments-delete

                                
$transaction_id = 'EXTR-86F38350LX4353815';

$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$status = $provider->deleteExternalPaymentInvoice($invoice_no, $transaction_id);
                                
                            

Refund Invoice

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds

                                
$payment_method = 'BANK_TRANSFER';

$payment_date = '2018-05-26';

$amount = 5;

$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$status = $provider->refundInvoice($invoice_no, $payment_date, $payment_method, $amount);
                                
                            

Delete External Refund

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds-delete

                                
$refund_id = 'EXTR-2LG703375E477444T';

$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$status = $provider->deleteRefundInvoice($invoice_no, $transaction_id);
                                
                            

Send Reminder for Invoice

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_remind

                                
$subject = "Reminder: Payment due for the invoice #ABC-123";

$note = "Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.";

$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$status = $provider->sendInvoiceReminder($invoice_no, $subject, $note);
                                
                            

By default, a copy of the email is sent to the recipient. However, if you wish to send a copy of the email to the merchant and also some other recipients. You may use the following snippet:

                                
$emails = ['receipt1@example.com', 'receipt2@example.com'];

$status = $provider->sendInvoiceReminder($invoice_no, $subject, $note, true, true, $emails);
                                
                            

Send Invoice

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#invoices_send

                                
$subject = "Reminder: Payment due for the invoice #ABC-123";

$note = "Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.";

$invoice_no = 'INV2-Z56S-5LLA-Q52L-CPZ5';

$status = $provider->sendInvoice($invoice_no, $subject, $note);
                                
                            

By default, a copy of the email is sent to the recipient. However, if you wish to send a copy of the email to the merchant and also some other recipients. You may use the following snippet:

                                
$emails = ['receipt1@example.com', 'receipt2@example.com'];

$status = $provider->sendInvoice($invoice_no, $subject, $note, true, true, $emails);
                                
                            

Search Invoices

The following snippets lists code snippets for interacting with Search Invoices API.

Search Invoices

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#search-invoices_search-invoices

                            
$invoices = $provider->searchInvoices();
                            
                        

By default, a paginated set of 20 invoices are returned with total records & pages. However, if you wish to provide different pagination parameters with no totals being returned. You may do using the following snippet:

                            
$invoices = $provider->searchInvoices(1, 50, false);
                            
                        

Search Invoices - Filters

By default, the default currency code filter is applied if no filters are provided. Following are the filters you can utilize for search invoices:

You must call the searchInvoices method after calling the filter methods mentioned below:
  • Recipient Email

                                      
    $invoices = $provider->addInvoiceFilterByRecipientEmail('bill-me@example.com')->searchInvoices();
                                      
                                  
  • Recipient First Name

                                      
    $invoices = $provider->addInvoiceFilterByRecipientFirstName('John')->searchInvoices();
                                      
                                  
  • Recipient Last Name

                                      
    $invoices = $provider->addInvoiceFilterByRecipientLastName('Doe')->searchInvoices();
                                      
                                  
  • Recipient Business Name

                                      
    $invoices = $provider->addInvoiceFilterByRecipientBusinessName('Acme Inc.')->searchInvoices();
                                      
                                  
  • Invoice Number

                                      
    $invoices = $provider->addInvoiceFilterByInvoiceNumber('#123')->searchInvoices();
                                      
                                  
  • Invoice Status

                                      
    $invoices = $provider->addInvoiceFilterByInvoiceStatus(['PAID', 'MARKED_AS_PAID'])->searchInvoices();
                                      
                                  
  • Reference

                                      
    $invoices = $provider->addInvoiceFilterByReferenceorMemo('deal-ref')->searchInvoices();
                                      
                                  
  • Memo

                                      
    $invoices = $provider->addInvoiceFilterByReferenceorMemo('deal-ref', true)->searchInvoices();
                                      
                                  
  • Currency Code

                                      
    $invoices = $provider->addInvoiceFilterByCurrencyCode('USD')->searchInvoices();
                                      
                                  
  • Amount Range

                                      
    $invoices = $provider->addInvoiceFilterByAmountRange(30, 50)->searchInvoices();
                                      
                                  

    By default, the currency defined the configuration or through the setCurrency method is used. However, if you wish to pass in a different currency you may use the following snippet.

                                      
    $invoices = $provider->addInvoiceFilterByAmountRange(30, 50, 'EUR')->searchInvoices();
                                      
                                  
  • Date Range with Type

                                      
    // Invoice Date
    $invoices = $provider->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'invoice_date')->searchInvoices();
    
    // Due Date
    $invoices = $provider->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'due_date')->searchInvoices();
    
    // Payment Date
    $invoices = $provider->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'payment_date')->searchInvoices();
    
    // Creation Date
    $invoices = $provider->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'creation_date')->searchInvoices();
                                      
                                  
  • Archived

                                      
    $invoices = $provider->addInvoiceFilterByArchivedStatus(false)->searchInvoices();
                                      
                                  
  • Fields

                                      
    $invoices = $provider->addInvoiceFilterByFields(['items', 'payments', 'refunds'])->searchInvoices();
                                      
                                  
You can also chain the methods mentioned above in a single call.
                                  
$invoices = $provider->addInvoiceFilterByRecipientEmail('bill-me@example.com')
            ->addInvoiceFilterByRecipientFirstName('John')
            ->addInvoiceFilterByRecipientLastName('Doe')
            ->addInvoiceFilterByRecipientBusinessName('Acme Inc.')
            ->addInvoiceFilterByInvoiceNumber('#123')
            ->addInvoiceFilterByInvoiceStatus(['PAID', 'MARKED_AS_PAID'])
            ->addInvoiceFilterByReferenceorMemo('deal-ref')
            ->addInvoiceFilterByCurrencyCode('USD')
            ->addInvoiceFilterByAmountRange(30, 50)
            ->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'invoice_date')
            ->addInvoiceFilterByArchivedStatus(false)
            ->addInvoiceFilterByFields(['items', 'payments', 'refunds'])
            ->searchInvoices();
                                  
                              

Invoices Templates

The following snippets lists code snippets for interacting with Invoices Templates API.

List Templates

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#templates_list

                                
$templates = $provider->listInvoiceTemplates();
                                
                            

By default, a paginated set of 20 invoices are returned. However, if you wish to provide different pagination parameters you may do using the following snippet:

                                
// All fields
$templates = $provider->listInvoiceTemplates(1, 50);

// Default fields
$templates = $provider->listInvoiceTemplates(1, 50, false);
                                
                            

Create Template

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#templates_create

                                
$data = json_decode('{
  "default_template": true,
  "template_info": {
    "configuration": {
      "tax_calculated_after_discount": true,
      "tax_inclusive": false,
      "allow_tip": true,
      "partial_payment": {
        "allow_partial_payment": true,
        "minimum_amount_due": {
          "currency_code": "USD",
          "value": "20.00"
        }
      }
    },
    "detail": {
      "reference": "deal-ref",
      "note": "Thank you for your business.",
      "currency_code": "USD",
      "terms_and_conditions": "No refunds after 30 days.",
      "memo": "This is a long contract",
      "attachments": [
        {
          "id": "Screen Shot 2018-11-23 at 16.45.01.png",
          "reference_url": "https://api.paypal.com/invoice/payerView/attachments/RkG9ggQbd4Mwm1tYdcF6uuixfFTFq32bBdbE1VbtQLdKSoS2ZOYpfjw9gPp7eTrZmVaFaDWzixHXm-OXWHbmigHigHzURDxJs8IIKqcqP8jawnBEZcraEAPVMULxf5iTyOSpAUc2ugW0PWdwDbM6mg-guFAUyj3Z98H7htWNjQY95jb9heOlcSXUe.sbDUR9smAszzzJoA1NXT6rEEegwQ&version=1&sig=JNODB0xEayW8txMQm6ZsIwDnd4eh3hd6ijiRLi4ipHE"
        }
      ],
      "payment_term": {
        "term_type": "NET_10"
      }
    },
    "invoicer": {
      "name": {
        "given_name": "David",
        "surname": "Larusso"
      },
      "address": {
        "address_line_1": "1234 First Street",
        "address_line_2": "337673 Hillside Court",
        "admin_area_2": "Anytown",
        "admin_area_1": "CA",
        "postal_code": "98765",
        "country_code": "US"
      },
      "email_address": "merchant@example.com",
      "phones": [
        {
          "country_code": "001",
          "national_number": "4085551234",
          "phone_type": "MOBILE"
        }
      ],
      "website": "www.test.com",
      "tax_id": "ABcNkWSfb5ICTt73nD3QON1fnnpgNKBy-Jb5SeuGj185MNNw6g",
      "logo_url": "https://example.com/logo.PNG",
      "additional_notes": "2-4"
    },
    "primary_recipients": [
      {
        "billing_info": {
          "name": {
            "given_name": "Stephanie",
            "surname": "Meyers"
          },
          "address": {
            "address_line_1": "1234 Main Street",
            "admin_area_2": "Anytown",
            "admin_area_1": "CA",
            "postal_code": "98765",
            "country_code": "US"
          },
          "email_address": "bill-me@example.com",
          "phones": [
            {
              "country_code": "001",
              "national_number": "4884551234",
              "phone_type": "MOBILE"
            }
          ],
          "additional_info": "add-info"
        },
        "shipping_info": {
          "name": {
            "given_name": "Stephanie",
            "surname": "Meyers"
          },
          "address": {
            "address_line_1": "1234 Main Street",
            "admin_area_2": "Anytown",
            "admin_area_1": "CA",
            "postal_code": "98765",
            "country_code": "US"
          }
        }
      }
    ],
    "additional_recipients": [
      "inform-me@example.com"
    ],
    "items": [
      {
        "name": "Yoga Mat",
        "description": "new watch",
        "quantity": "1",
        "unit_amount": {
          "currency_code": "USD",
          "value": "50.00"
        },
        "tax": {
          "name": "Sales Tax",
          "percent": "7.25"
        },
        "discount": {
          "percent": "5"
        },
        "unit_of_measure": "QUANTITY"
      },
      {
        "name": "Yoga T Shirt",
        "quantity": "1",
        "unit_amount": {
          "currency_code": "USD",
          "value": "10.00"
        },
        "tax": {
          "name": "Sales Tax",
          "percent": "7.25"
        },
        "discount": {
          "amount": {
            "currency_code": "USD",
            "value": "5.00"
          }
        },
        "unit_of_measure": "QUANTITY"
      }
    ],
    "amount": {
      "currency_code": "USD",
      "value": "74.21",
      "breakdown": {
        "custom": {
          "label": "Packing Charges",
          "amount": {
            "currency_code": "USD",
            "value": "10.00"
          }
        },
        "shipping": {
          "amount": {
            "currency_code": "USD",
            "value": "10.00"
          },
          "tax": {
            "name": "Sales Tax",
            "percent": "7.25"
          }
        },
        "discount": {
          "invoice_discount": {
            "percent": "5"
          }
        }
      }
    }
  },
  "settings": {
    "template_item_settings": [
      {
        "field_name": "items.date",
        "display_preference": {
          "hidden": true
        }
      },
      {
        "field_name": "items.discount",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "items.tax",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "items.description",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "items.quantity",
        "display_preference": {
          "hidden": true
        }
      }
    ],
    "template_subtotal_settings": [
      {
        "field_name": "custom",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "discount",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "shipping",
        "display_preference": {
          "hidden": false
        }
      }
    ]
  },
  "unit_of_measure": "QUANTITY",
  "standard_template": false
}', true);

$template = $provider->createInvoiceTemplate($data);
                                
                            

Delete Template

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#templates_delete

                                
$template_id = 'TEMP-19V05281TU309413B';

$template = $provider->deleteInvoiceTemplate($template_id);
                                
                            

Update Template

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#templates_update

                                
$data = json_decode('{
  "default_template": true,
  "template_info": {
    "configuration": {
      "tax_calculated_after_discount": true,
      "tax_inclusive": false,
      "allow_tip": true,
      "partial_payment": {
        "allow_partial_payment": true,
        "minimum_amount_due": {
          "currency_code": "USD",
          "value": "20.00"
        }
      }
    },
    "detail": {
      "reference": "deal-reference-value",
      "note": "Thank you for your business.",
      "currency_code": "USD",
      "terms_and_conditions": "No refunds after 30 days.",
      "memo": "This is a long contract",
      "attachments": [
        {
          "id": "Screen Shot 2018-11-23 at 16.45.01.png",
          "reference_url": "https://example.com/invoice/payerView/attachments/RkG9ggQbd4Mwm1tYdcF6uuixfFTFq32bBdbE1VbtQLdKSoS2ZOYpfjw9gPp7eTrZmVaFaDWzixHXm-OXWHbmigHigHzURDxJs8IIKqcqP8jawnBEZcraEAPVMULxf5iTyOSpAUc2ugW0PWdwDbM6mg-guFAUyj3Z98H7htWNjQY95jb9heOlcSXUe.sbDUR9smAszzzJoA1NXT6rEEegwQ&version=1&sig=JNODB0xEayW8txMQm6ZsIwDnd4eh3hd6ijiRLi4ipHE"
        }
      ],
      "payment_term": {
        "term_type": "NET_10"
      }
    },
    "invoicer": {
      "name": {
        "given_name": "David",
        "surname": "Larusso"
      },
      "address": {
        "address_line_1": "1234 First Street",
        "address_line_2": "337673 Hillside Court",
        "admin_area_2": "Anytown",
        "admin_area_1": "CA",
        "postal_code": "98765",
        "country_code": "US"
      },
      "email_address": "merchant@example.com",
      "phones": [
        {
          "country_code": "001",
          "national_number": "4085551234",
          "phone_type": "MOBILE"
        }
      ],
      "website": "www.test.com",
      "tax_id": "ABcNkWSfb5ICTt73nD3QON1fnnpgNKBy-Jb5SeuGj185MNNw6g",
      "logo_url": "https://example.com/logo.PNG",
      "additional_notes": "2-4"
    },
    "primary_recipients": [
      {
        "billing_info": {
          "name": {
            "given_name": "Stephanie",
            "surname": "Meyers"
          },
          "address": {
            "address_line_1": "1234 Main Street",
            "admin_area_2": "Anytown",
            "admin_area_1": "CA",
            "postal_code": "98765",
            "country_code": "US"
          },
          "email_address": "bill-me@example.com",
          "phones": [
            {
              "country_code": "001",
              "national_number": "4884551234",
              "phone_type": "MOBILE"
            }
          ],
          "additional_info": "add-info"
        },
        "shipping_info": {
          "name": {
            "given_name": "Stephanie",
            "surname": "Meyers"
          },
          "address": {
            "address_line_1": "1234 Main Street",
            "admin_area_2": "Anytown",
            "admin_area_1": "CA",
            "postal_code": "98765",
            "country_code": "US"
          }
        }
      }
    ],
    "additional_recipients": [
      "inform-me@example.com"
    ],
    "items": [
      {
        "name": "Yoga Mat",
        "description": "new watch",
        "quantity": "1",
        "unit_amount": {
          "currency_code": "USD",
          "value": "50.00"
        },
        "tax": {
          "name": "Sales Tax",
          "percent": "7.25"
        },
        "discount": {
          "percent": "5"
        },
        "unit_of_measure": "QUANTITY"
      },
      {
        "name": "Yoga T Shirt",
        "quantity": "1",
        "unit_amount": {
          "currency_code": "USD",
          "value": "10.00"
        },
        "tax": {
          "name": "Sales Tax",
          "percent": "7.25"
        },
        "discount": {
          "amount": {
            "currency_code": "USD",
            "value": "5.00"
          }
        },
        "unit_of_measure": "QUANTITY"
      }
    ],
    "amount": {
      "currency_code": "USD",
      "value": "74.21",
      "breakdown": {
        "custom": {
          "label": "Packing Charges",
          "amount": {
            "currency_code": "USD",
            "value": "10.00"
          }
        },
        "shipping": {
          "amount": {
            "currency_code": "USD",
            "value": "10.00"
          },
          "tax": {
            "name": "Sales Tax",
            "percent": "7.25"
          }
        },
        "discount": {
          "invoice_discount": {
            "percent": "5"
          }
        }
      }
    }
  },
  "settings": {
    "template_item_settings": [
      {
        "field_name": "items.date",
        "display_preference": {
          "hidden": true
        }
      },
      {
        "field_name": "items.discount",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "items.tax",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "items.description",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "items.quantity",
        "display_preference": {
          "hidden": true
        }
      }
    ],
    "template_subtotal_settings": [
      {
        "field_name": "custom",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "discount",
        "display_preference": {
          "hidden": false
        }
      },
      {
        "field_name": "shipping",
        "display_preference": {
          "hidden": false
        }
      }
    ]
  },
  "unit_of_measure": "QUANTITY",
  "standard_template": false
}', true);

$template_id = 'TEMP-19V05281TU309413B';

$template = $provider->updateInvoiceTemplate($template_id, $data);
                                
                            

Show Template Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/invoicing/v2/#templates_get

                                
$template_id = 'TEMP-19V05281TU309413B';

$template = $provider->showInvoiceTemplateDetails($template_id);
                                
                            

Orders

The following snippets lists code snippets for interacting with Orders API.

Create Order

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/orders/v2/#orders_create

                                
$data = json_decode('{
    "intent": "CAPTURE",
    "purchase_units": [
      {
        "amount": {
          "currency_code": "USD",
          "value": "100.00"
        }
      }
    ]
}', true);

$order = $provider->createOrder($data);
                                
                            

Update Order

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/orders/v2/#orders_patch

                                
$filters = json_decode('[
    {
      "op": "replace",
      "path": "/purchase_units/@reference_id==\'PUHF\'/shipping/address",
      "value": {
        "address_line_1": "123 Townsend St",
        "address_line_2": "Floor 6",
        "admin_area_2": "San Francisco",
        "admin_area_1": "CA",
        "postal_code": "94107",
        "country_code": "US"
      }
    }
]', true);

$order_id = '5O190127TN364715T';

$order = $provider->updateOrder($order_id, $filters);
                                
                            

Show Order Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/orders/v2/#orders_get

                                
$order_id = '5O190127TN364715T';

$order = $provider->showOrderDetails($order_id);
                                
                            

Authorize Payment for Order

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/orders/v2/#orders_authorize

                                
$order_id = '5O190127TN364715T';

$order = $provider->authorizePaymentOrder($order_id);
                                
                            

Capture Payment for Order

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/orders/v2/#orders_capture

                                
$order_id = '5O190127TN364715T';

$order = $provider->capturePaymentOrder($order_id);
                                
                            

Identity

The following snippets lists code snippets for interacting with Identity API.

Show Profile Info

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/identity/v1/#userinfo_get

                                
$profile = $provider->showProfileInfo();
                                
                            

Create Merchant Application

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/identity/v1/#applications_post

                                
$application = $provider->createMerchantApplication(
    'AGGREGATOR',
    [
        'https://example.com/callback',
        'https://example.com/callback2',
    ],
    [
        'facilitator@example.com',
        'merchant@example.com',
    ],
    'WDJJHEBZ4X2LY',
    'some-open-id'
);
                                
                            

Set Account Properties

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/identity/v1/#account-settings_post

                                
$data = json_decode('{
    "categories": [
      {
        "name": "PAYMENT",
        "groups": [
          {
            "name": "AUTH_SETTLE",
            "preferences": [
              {
                "name": "ENABLE_ENHANCED_AUTH_SETTLE",
                "value": "true"
              }
            ]
          }
        ]
      }
    ]
  }', true);

$settings = $provider->setAccountProperties($data);
                                
                            

Disable Account Properties

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/identity/v1/#account-settings_deactivate

                                
$settings = $provider->disableAccountProperties();
                                
                            

Partner Referral

The following snippets lists code snippets for interacting with Partner Referral API.

Create Partner Referral

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/partner-referrals/v2/#partner-referrals_create

                                
$data = json_decode('{
  "individual_owners": [
    {
      "names": [
        {
          "prefix": "Mr.",
          "given_name": "John",
          "surname": "Doe",
          "middle_name": "Middle",
          "suffix": "Jr.",
          "full_name": "John Middle Doe Jr.",
          "type": "LEGAL"
        }
      ],
      "citizenship": "US",
      "addresses": [
        {
          "address_line_1": "One Washington Square",
          "address_line_2": "Apt 123",
          "admin_area_2": "San Jose",
          "admin_area_1": "CA",
          "postal_code": "95112",
          "country_code": "US",
          "type": "HOME"
        }
      ],
      "phones": [
        {
          "country_code": "1",
          "national_number": "6692468839",
          "extension_number": "1234",
          "type": "MOBILE"
        }
      ],
      "birth_details": {
        "date_of_birth": "1955-12-29"
      },
      "type": "PRIMARY"
    }
  ],
  "business_entity": {
    "business_type": {
      "type": "INDIVIDUAL",
      "subtype": "ASSO_TYPE_INCORPORATED"
    },
    "business_industry": {
      "category": "1004",
      "mcc_code": "2025",
      "subcategory": "8931"
    },
    "business_incorporation": {
      "incorporation_country_code": "US",
      "incorporation_date": "1986-12-29"
    },
    "names": [
      {
        "business_name": "Test Enterprise",
        "type": "LEGAL_NAME"
      }
    ],
    "emails": [
      {
        "type": "CUSTOMER_SERVICE",
        "email": "customerservice@example.com"
      }
    ],
    "website": "https://mystore.testenterprises.com",
    "addresses": [
      {
        "address_line_1": "One Washington Square",
        "address_line_2": "Apt 123",
        "admin_area_2": "San Jose",
        "admin_area_1": "CA",
        "postal_code": "95112",
        "country_code": "US",
        "type": "WORK"
      }
    ],
    "phones": [
      {
        "country_code": "1",
        "national_number": "6692478833",
        "extension_number": "1234",
        "type": "CUSTOMER_SERVICE"
      }
    ],
    "beneficial_owners": {
      "individual_beneficial_owners": [
        {
          "names": [
            {
              "prefix": "Mr.",
              "given_name": "John",
              "surname": "Doe",
              "middle_name": "Middle",
              "suffix": "Jr.",
              "full_name": "John Middle Doe Jr.",
              "type": "LEGAL"
            }
          ],
          "citizenship": "US",
          "addresses": [
            {
              "address_line_1": "One Washington Square",
              "address_line_2": "Apt 123",
              "admin_area_2": "San Jose",
              "admin_area_1": "CA",
              "postal_code": "95112",
              "country_code": "US",
              "type": "HOME"
            }
          ],
          "phones": [
            {
              "country_code": "1",
              "national_number": "6692468839",
              "extension_number": "1234",
              "type": "MOBILE"
            }
          ],
          "birth_details": {
            "date_of_birth": "1955-12-29"
          },
          "percentage_of_ownership": "50"
        }
      ],
      "business_beneficial_owners": [
        {
          "business_type": {
            "type": "INDIVIDUAL",
            "subtype": "ASSO_TYPE_INCORPORATED"
          },
          "business_industry": {
            "category": "1004",
            "mcc_code": "2025",
            "subcategory": "8931"
          },
          "business_incorporation": {
            "incorporation_country_code": "US",
            "incorporation_date": "1986-12-29"
          },
          "names": [
            {
              "business_name": "Test Enterprise",
              "type": "LEGAL_NAME"
            }
          ],
          "emails": [
            {
              "type": "CUSTOMER_SERVICE",
              "email": "customerservice@example.com"
            }
          ],
          "website": "https://mystore.testenterprises.com",
          "addresses": [
            {
              "address_line_1": "One Washington Square",
              "address_line_2": "Apt 123",
              "admin_area_2": "San Jose",
              "admin_area_1": "CA",
              "postal_code": "95112",
              "country_code": "US",
              "type": "WORK"
            }
          ],
          "phones": [
            {
              "country_code": "1",
              "national_number": "6692478833",
              "extension_number": "1234",
              "type": "CUSTOMER_SERVICE"
            }
          ],
          "percentage_of_ownership": "50"
        }
      ]
    },
    "office_bearers": [
      {
        "names": [
          {
            "prefix": "Mr.",
            "given_name": "John",
            "surname": "Doe",
            "middle_name": "Middle",
            "suffix": "Jr.",
            "full_name": "John Middle Doe Jr.",
            "type": "LEGAL"
          }
        ],
        "citizenship": "US",
        "addresses": [
          {
            "address_line_1": "One Washington Square",
            "address_line_2": "Apt 123",
            "admin_area_2": "San Jose",
            "admin_area_1": "CA",
            "postal_code": "95112",
            "country_code": "US",
            "type": "HOME"
          }
        ],
        "phones": [
          {
            "country_code": "1",
            "national_number": "6692468839",
            "extension_number": "1234",
            "type": "MOBILE"
          }
        ],
        "birth_details": {
          "date_of_birth": "1955-12-29"
        },
        "role": "DIRECTOR"
      }
    ],
    "annual_sales_volume_range": {
      "minimum_amount": {
        "currency_code": "USD",
        "value": "10000"
      },
      "maximum_amount": {
        "currency_code": "USD",
        "value": "50000"
      }
    },
    "average_monthly_volume_range": {
      "minimum_amount": {
        "currency_code": "USD",
        "value": "1000"
      },
      "maximum_amount": {
        "currency_code": "USD",
        "value": "50000"
      }
    },
    "purpose_code": "P0104"
  },
  "email": "accountemail@example.com",
  "preferred_language_code": "en-US",
  "tracking_id": "testenterprices123122",
  "partner_config_override": {
    "partner_logo_url": "https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_111x69.jpg",
    "return_url": "https://testenterprises.com/merchantonboarded",
    "return_url_description": "the url to return the merchant after the paypal onboarding process.",
    "action_renewal_url": "https://testenterprises.com/renew-exprired-url",
    "show_add_credit_card": true
  },
  "operations": [
    {
      "operation": "BANK_ADDITION"
    }
  ],
  "financial_instruments": {
    "banks": [
      {
        "nick_name": "Bank of America",
        "account_number": "123405668293",
        "account_type": "CHECKING",
        "currency_code": "USD",
        "identifiers": [
          {
            "type": "ROUTING_NUMBER_1",
            "value": "123456789"
          }
        ]
      }
    ]
  },
  "legal_consents": [
    {
      "type": "SHARE_DATA_CONSENT",
      "granted": true
    }
  ],
  "products": [
    "EXPRESS_CHECKOUT"
  ]
}', true);

$partner = $provider->createPartnerReferral($data);
                                
                            

Show Referral Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/partner-referrals/v2/#partner-referrals_read

                                
$partner_referral_id = 'ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0=';

$partner = $provider->showReferralData($partner_referral_id);
                                
                            

Payment Experience

The following snippets lists code snippets for interacting with Payment Experience Web Profile API.

List Web Experience Profiles

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_get-list

                              
$profiles = $provider->listWebExperienceProfiles();
                              
                          

Create Web Experience Profile

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_create

                              
$payload = Utils::jsonDecode('[
  {
    "id": "XP-GCUV-X35G-HNEY-5MJY",
    "name": "exampleProfile",
    "flow_config": {
      "landing_page_type": "billing",
      "bank_txn_pending_url": "https://example.com/flow_config/"
    },
    "input_fields": {
      "no_shipping": 1,
      "address_override": 1
    },
    "presentation": {
      "logo_image": "https://example.com/logo_image/"
    }
  },
  {
    "id": "XP-A88A-LYLW-8Y3X-E5ER",
    "name": "exampleProfile",
    "flow_config": {
      "landing_page_type": "billing",
      "bank_txn_pending_url": "https://example.com/flow_config/"
    },
    "input_fields": {
      "no_shipping": 1,
      "address_override": 1
    },
    "presentation": {
      "logo_image": "https://example.com/logo_image/"
    }
  },
  {
    "id": "XP-RFV4-PVD8-AGHJ-8E5J",
    "name": "exampleProfile",
    "flow_config": {
      "bank_txn_pending_url": "https://example.com/flow_config/"
    },
    "input_fields": {
      "no_shipping": 1,
      "address_override": 1
    },
    "presentation": {
      "logo_image": "https://example.com/logo_image/"
    }
  }
]', true);

$profile = $provider->setRequestHeader('PayPal-Request-Id', 'some-request-id')->createWebExperienceProfile($payload);
                              
                          

Delete Web Experience Profile

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_delete

                              
$profile_id = 'XP-A88A-LYLW-8Y3X-E5ER';

$profile = $provider->deleteWebExperienceProfile($profile_id);
                              
                          

Partially Update Web Experience Profile

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_partial-update

                              
$profile_id = 'XP-A88A-LYLW-8Y3X-E5ER';
$payload = json_decode('[
  {
    "op": "add",
    "path": "/presentation/brand_name",
    "value": "new_brand_name"
  },
  {
    "op": "remove",
    "path": "/flow_config/landing_page_type"
  }
]', true);

$profile = $provider->patchWebExperienceProfile($profile_id, $payload);
                              
                          

Update Web Experience Profile

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_update

                              
$profile_id = 'XP-A88A-LYLW-8Y3X-E5ER';
$payload = json_decode('{
  "name": "exampleProfile",
  "presentation": {
    "logo_image": "https://example.com/logo_image/"
  },
  "input_fields": {
    "no_shipping": 1,
    "address_override": 1
  },
  "flow_config": {
    "landing_page_type": "billing",
    "bank_txn_pending_url": "https://example.com/flow_config/"
  }
}', true);

$profile = $provider->updateWebExperienceProfile($profile_id, $payload);
                              
                          

Show Web Experience Profile Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_get

                              
$profile_id = 'XP-A88A-LYLW-8Y3X-E5ER';

$profile = $provider->showWebExperienceProfileDetails($profile_id);
                              
                          

Payments

The following snippets lists code snippets for interacting with the Payments API with the following:

  • Authorizations
  • Captures
  • Refunds

Show Authorized Payment Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments/v2/#authorizations_get

                                
$payment_id = '0VF52814937998046';
$response = $provider->showAuthorizedPaymentDetails($payment_id);
                                
                            

Capture Authorized Payment

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture

                                
$response = $provider->captureAuthorizedPayment(
    '0VF52814937998046',
    'INVOICE-123',
    10.99,
    'Payment is due'
);
                                
                            

Reauthorize Authorized Payment

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments/v2/#authorizations_reauthorize

                                
$response = $provider->reAuthorizeAuthorizedPayment('0VF52814937998046', 10.99);
                                
                            

Void Authorized Payment

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments/v2/#authorizations_void

                                
$response = $provider->voidAuthorizedPayment('0VF52814937998046');
                                
                            

Show Captured Payment Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments/v2/#captures_get

                                
$response = $provider->showCapturedPaymentDetails('2GG279541U471931P');
                                
                            

Refund Captured Payment

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments/v2/#captures_refund

                                
$response = $provider->refundCapturedPayment(
    '2GG279541U471931P',
    'INVOICE-123',
    10.99,
    'Defective product'
);
                                
                            

Show Refund Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments/v2/#refunds_get

                                
$response = $provider->showRefundDetails('1JU08902781691411');
                                
                            

Payouts

The following snippets lists code snippets for interacting with the Payouts API.

Create Batch Payout

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts_post

                                
$data = json_decode('{
  "sender_batch_header": {
    "sender_batch_id": "Payouts_2018_100007",
    "email_subject": "You have a payout!",
    "email_message": "You have received a payout! Thanks for using our service!"
  },
  "items": [
    {
      "recipient_type": "EMAIL",
      "amount": {
        "value": "9.87",
        "currency": "USD"
      },
      "note": "Thanks for your patronage!",
      "sender_item_id": "201403140001",
      "receiver": "receiver@example.com",
      "alternate_notification_method": {
        "phone": {
          "country_code": "91",
          "national_number": "9999988888"
        }
      },
      "notification_language": "fr-FR"
    },
    {
      "recipient_type": "PHONE",
      "amount": {
        "value": "112.34",
        "currency": "USD"
      },
      "note": "Thanks for your support!",
      "sender_item_id": "201403140002",
      "receiver": "91-734-234-1234"
    },
    {
      "recipient_type": "PAYPAL_ID",
      "amount": {
        "value": "5.32",
        "currency": "USD"
      },
      "note": "Thanks for your patronage!",
      "sender_item_id": "201403140003",
      "receiver": "G83JXTJ5EHCQ2"
    }
  ]
}', true);

$response = $provider->createBatchPayout($data);
                                
                            

Show Payout Batch Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts_get

                                
$response = $provider->showBatchPayoutDetails('FYXMPQTX4JC9N');
                                
                            

Show Payout Item Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_get

                                
$response = $provider->showPayoutItemDetails('8AELMXH8UB2P8');
                                
                            

Cancel Unclaimed Payout Item

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_get

                                
$response = $provider->showPayoutItemDetails('8AELMXH8UB2P8');
                                
                            

Referenced Payouts

The following snippets lists code snippets for interacting with the Referenced Payouts API.

Create Referenced Batch Payout

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts_create_batch

                                
$data = json_decode('{
  "referenced_payouts": [
    {
      "reference_id": "2KP03934U4415543C",
      "reference_type": "TRANSACTION_ID"
    },
    {
      "reference_id": "8TA4226978212399L",
      "reference_type": "TRANSACTION_ID"
    }
  ]
}', true);

$response = $provider->createReferencedBatchPayout($expectedParams, 'some-request-id', 'some-attribution-id');
                                
                            

List Items In Referenced Batch Payout

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts_get_batch_details

                                
$response = $provider->listItemsReferencedInBatchPayout('KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E=');
                                
                            

Create Referenced Payout Item

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts-items_create

                                
$data = json_decode('{
  "reference_id": "CAPTURETXNID",
  "reference_type": "TRANSACTION_ID"
}', true);

$response = $provider->createReferencedBatchPayoutItem($data, 'some-request-id', 'some-attribution-id');
                                
                            

Show Referenced Payout Item Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts-items_get

                                
$response = $provider->showReferencedPayoutItemDetails('CDZEC5MJ8R5HY', 'some-attribution-id');
                                
                            

Transactions Search

The following snippets lists code snippets for interacting with the Transactions Search API.

List Transactions

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/transaction-search/v1/#transactions_get

                                
$filters = [
    'start_date'    => Carbon::now()->toIso8601String(),
    'end_date'      => Carbon::now()->addDays(30)->toIso8601String(),
];

$response = $provider->listTransactions($filters);
                                
                            

List Balances

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/transaction-search/v1/#balances_get

                                
$response = $provider->listBalances('2022-10-09', 'EUR');
                                
                            

Subscriptions

The following snippets lists code snippets for interacting with Subscriptions API.

Create Subscription

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create

                                
$data = json_decode('{
  "plan_id": "P-5ML4271244454362WXNWU5NQ",
  "start_time": "2018-11-01T00:00:00Z",
  "quantity": "20",
  "shipping_amount": {
    "currency_code": "USD",
    "value": "10.00"
  },
  "subscriber": {
    "name": {
      "given_name": "John",
      "surname": "Doe"
    },
    "email_address": "customer@example.com",
    "shipping_address": {
      "name": {
        "full_name": "John Doe"
      },
      "address": {
        "address_line_1": "2211 N First Street",
        "address_line_2": "Building 17",
        "admin_area_2": "San Jose",
        "admin_area_1": "CA",
        "postal_code": "95131",
        "country_code": "US"
      }
    }
  },
  "application_context": {
    "brand_name": "walmart",
    "locale": "en-US",
    "shipping_preference": "SET_PROVIDED_ADDRESS",
    "user_action": "SUBSCRIBE_NOW",
    "payment_method": {
      "payer_selected": "PAYPAL",
      "payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
    },
    "return_url": "https://example.com/returnUrl",
    "cancel_url": "https://example.com/cancelUrl"
  }
}', true);

$subscription = $provider->createSubscription($data);
                                
                            

Update Subscription

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_patch

                                
$data = json_decode('[
  {
    "op": "replace",
    "path": "/billing_info/outstanding_balance",
    "value": {
      "currency_code": "USD",
      "value": "50.00"
    }
  }
]', true);

$response = $provider->updateSubscription('I-BW452GLLEP1G', $data);
                                
                            

Show Subscription Details

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get

                                
$subscription = $provider->showSubscriptionDetails('I-BW452GLLEP1G');
                                
                            

Activate Subscription

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_activate

                                
$response = $provider->activateSubscription('I-BW452GLLEP1G', 'Reactivating the subscription');
                                
                            

Cancel Subscription

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel

                                
$response = $provider->cancelSubscription('I-BW452GLLEP1G', 'Not satisfied with the service');
                                
                            

Suspend Subscription

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_suspend

                                
$response = $provider->suspendSubscription('I-BW452GLLEP1G', 'Item out of stock');
                                
                            

Capture authorized payment on subscription

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_capture

                                
$response = $provider->captureSubscriptionPayment('I-BW452GLLEP1G', 'Charging as the balance reached the limit', 100);
                                
                            

Revise plan or quantity of subscription

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_revise

                                
$data = \GuzzleHttp\json_decode('{
  "plan_id": "P-5ML4271244454362WXNWU5NQ",
  "shipping_amount": {
    "currency_code": "USD",
    "value": "10.00"
  },
  "shipping_address": {
    "name": {
      "full_name": "John Doe"
    },
    "address": {
      "address_line_1": "2211 N First Street",
      "address_line_2": "Building 17",
      "admin_area_2": "San Jose",
      "admin_area_1": "CA",
      "postal_code": "95131",
      "country_code": "US"
    }
  },
  "application_context": {
    "brand_name": "walmart",
    "locale": "en-US",
    "shipping_preference": "SET_PROVIDED_ADDRESS",
    "payment_method": {
      "payer_selected": "PAYPAL",
      "payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
    },
    "return_url": "https://example.com/returnUrl",
    "cancel_url": "https://example.com/cancelUrl"
  }
}', true);

$response = $provider->reviseSubscription('I-BW452GLLEP1G', $data);
                                
                            

Capture authorized payment on subscription

This code snippet utilizes the following API:
https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions

                                
$response = $provider->listSubscriptionTransactions('I-BW452GLLEP1G', '2018-01-21T07:50:20.940Z', '2018-08-22T07:50:20.940Z');