diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index dbb771be..0831ea4f 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -9,49 +9,49 @@ jobs:
matrix:
php-versions: ['5.6', '7.0', '7.1']
steps:
- - name: Checkout
- uses: actions/checkout@v2
- - name: Setup PHP with Composer and extensions
- with:
- php-version: ${{ matrix.php-versions }}
- uses: shivammathur/setup-php@v2
- - name: Get Composer cache directory
- id: composercache
- run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- - name: Cache Composer dependencies
- uses: actions/cache@v2
- with:
- php-version: ${{ matrix.php-versions }}
- path: ${{ steps.composercache.outputs.dir }}
- key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
- restore-keys: ${{ runner.os }}-composer-
- - name: Install Composer dependencies
- env:
- PHP_VERSION: ${{ matrix.php-versions }}
- run: composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" ]; then echo "--ignore-platform-reqs"; fi;)
- - name: Run tests with code coverage
- env:
- PHP_VERSION: ${{ matrix.php-versions }}
- run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- - name: Install PHP Coveralls library
- env:
- PHP_VERSION: ${{ matrix.php-versions }}
- run:
- composer global require --dev php-coveralls/php-coveralls
- - name: Upload coverage results to Coveralls
- env:
- PHP_VERSION: ${{ matrix.php-versions }}
- COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- COVERALLS_PARALLEL: true
- COVERALLS_FLAG_NAME: php-${{ matrix.php-versions }}
- run:
- php-coveralls -v
+ - name: Checkout
+ uses: actions/checkout@v2
+ - name: Setup PHP with Composer and extensions
+ with:
+ php-version: ${{ matrix.php-versions }}
+ uses: shivammathur/setup-php@v2
+ - name: Get Composer cache directory
+ id: composercache
+ run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+ - name: Cache Composer dependencies
+ uses: actions/cache@v2
+ with:
+ php-version: ${{ matrix.php-versions }}
+ path: ${{ steps.composercache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+ restore-keys: ${{ runner.os }}-composer-
+ - name: Install Composer dependencies
+ env:
+ PHP_VERSION: ${{ matrix.php-versions }}
+ run: composer install --no-progress --prefer-dist --optimize-autoloader
+ - name: Run tests with code coverage
+ env:
+ PHP_VERSION: ${{ matrix.php-versions }}
+ run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
+ - name: Install PHP Coveralls library
+ env:
+ PHP_VERSION: ${{ matrix.php-versions }}
+ run:
+ composer global require --dev php-coveralls/php-coveralls
+ - name: Upload coverage results to Coveralls
+ env:
+ PHP_VERSION: ${{ matrix.php-versions }}
+ COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ COVERALLS_PARALLEL: true
+ COVERALLS_FLAG_NAME: php-${{ matrix.php-versions }}
+ run:
+ php-coveralls -v
coveralls-finish:
needs: [paypal]
runs-on: ubuntu-latest
steps:
- - name: Coveralls Finished
- uses: coverallsapp/github-action@master
- with:
- github-token: ${{ secrets.github_token }}
- parallel-finished: true
+ - name: Coveralls Finished
+ uses: coverallsapp/github-action@master
+ with:
+ github-token: ${{ secrets.github_token }}
+ parallel-finished: true
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index f3a12024..80f9c4fe 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -25,7 +25,7 @@ build:
- php-scrutinizer-run
environment:
php:
- version: '7.1.33'
+ version: '7.3.21'
tests:
override:
-
diff --git a/README.md b/README.md
index 4809ebde..ef43b3e4 100644
--- a/README.md
+++ b/README.md
@@ -4,9 +4,9 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/srmklive/paypal.svg?style=flat-square)](https://packagist.org/packages/srmklive/paypal)
[![Total Downloads](https://img.shields.io/packagist/dt/srmklive/paypal.svg?style=flat-square)](https://packagist.org/packages/srmklive/paypal)
[![StyleCI](https://github.styleci.io/repos/43671533/shield?branch=v2.0)](https://github.styleci.io/repos/43671533?branch=v2.0)
-![Tests](https://github.com/srmklive/laravel-paypal/workflows/TestsV2/badge.svg)
-[![Coverage Status](https://coveralls.io/repos/github/srmklive/laravel-paypal/badge.svg?branch=v2.0)](https://coveralls.io/github/srmklive/laravel-paypal?branch=v2.0)
-[![Code Quality](https://scrutinizer-ci.com/g/srmklive/laravel-paypal/badges/quality-score.png?b=v2.0)](https://scrutinizer-ci.com/g/srmklive/laravel-paypal/?branch=v2.0)
+![Tests](https://github.com/srmklive/laravel-paypal/workflows/TestsV3/badge.svg)
+[![Coverage Status](https://coveralls.io/repos/github/srmklive/laravel-paypal/badge.svg?branch=v3.0)](https://coveralls.io/github/srmklive/laravel-paypal?branch=v3.0)
+[![Code Quality](https://scrutinizer-ci.com/g/srmklive/laravel-paypal/badges/quality-score.png?b=v3.0)](https://scrutinizer-ci.com/g/srmklive/laravel-paypal/?branch=v3.0)
- [Documentation](#introduction)
- [Usage](#usage)
@@ -18,7 +18,7 @@
The documentation for the package can be viewed by clicking the following link:
-https://srmklive.github.io/laravel-paypal/docs.html
+[https://srmklive.github.io/laravel-paypal/docs.html](https://srmklive.github.io/laravel-paypal/docs.html)
## Usage
@@ -32,10 +32,36 @@ use Srmklive\PayPal\Services\PayPal as PayPalClient;
$provider = new PayPalClient;
// Through facade. No need to import namespaces
-$provider = PayPal::setProvider();
+$provider = \PayPal::setProvider();
```
+## Configuration File
+
+The configuration file **paypal.php** is located in the **config** folder. Following are its contents when published:
+
+```php
+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' => env('PAYPAL_LIVE_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.
+];
+```
+
## Override PayPal API Configuration
You can override PayPal API configuration by calling `setApiCredentials` method:
@@ -58,40 +84,60 @@ $provider->getAccessToken();
## Set 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:
+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:
```php
$provider->setCurrency('EUR');
```
-## Initiating an order for Checkout
-Use the createOrder method to initiate an order
+## Create Recurring Daily Subscription
+
+```php
+$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
+ ->addSubscriptionTrialPricing('DAY', 7)
+ ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50)
+ ->setupSubscription('John Doe', 'john@example.com', '2021-12-10') ;
+```
+
+## Create Recurring Weekly Subscription
+
+```php
+$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
+ ->addSubscriptionTrialPricing('DAY', 7)
+ ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30)
+ ->setupSubscription('John Doe', 'john@example.com', '2021-12-10') ;
+```
+
+## Create Recurring Monthly Subscription
+
+```php
+$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
+ ->addSubscriptionTrialPricing('DAY', 7)
+ ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100)
+ ->setupSubscription('John Doe', 'john@example.com', '2021-12-10') ;
+```
+
+## Create Recurring Annual Subscription
+
```php
-$provider->createOrder([
- "intent"=> "CAPTURE",
- "purchase_units"=> [
- 0 => [
- "amount"=> [
- "currency_code"=> "USD",
- "value"=> "100.00"
- ]
- ]
- ]
-]);
+$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
+ ->addSubscriptionTrialPricing('DAY', 7)
+ ->addAnnualPlan('Demo Plan', 'Demo Plan', 600)
+ ->setupSubscription('John Doe', 'john@example.com', '2021-12-10') ;
```
-The response from this will include an order ID which you will need to retail, and a links collection
-so you can redirect the user to Paypal to complete the order with their payment details
+## Create Subscription by Existing Product & Billing Plan
-When the user returns to the notifcation url you can capture the order payment with
```php
-$provider->capturePaymentOrder($order_id); //order id from the createOrder step
+$response = $this->client->addProductById('PROD-XYAB12ABSB7868434')
+ ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
+ ->setupSubscription('John Doe', 'john@example.com', $start_date);
```
## Support
-This plugin only supports Laravel 5.1 to 5.8.
+This version supports Laravel 6 or greater.
* In case of any issues, kindly create one on the [Issues](https://github.com/srmklive/laravel-paypal/issues) section.
* If you would like to contribute:
* Fork this repository.
diff --git a/config/config.php b/config/config.php
index 509d7bba..11c45abe 100644
--- a/config/config.php
+++ b/config/config.php
@@ -14,7 +14,7 @@
'live' => [
'client_id' => env('PAYPAL_LIVE_CLIENT_ID', ''),
'client_secret' => env('PAYPAL_LIVE_CLIENT_SECRET', ''),
- 'app_id' => '',
+ 'app_id' => env('PAYPAL_LIVE_APP_ID', ''),
],
'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order'
diff --git a/phpunit.xml.dist.php72 b/phpunit.xml.dist.php72
new file mode 100644
index 00000000..bb37520e
--- /dev/null
+++ b/phpunit.xml.dist.php72
@@ -0,0 +1,33 @@
+
+
+
+
+ tests
+
+
+
+
+ src/
+
+ src/PayPalFacadeAccessor.php
+ src/Facades/
+ src/Providers/
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Services/PayPal.php b/src/Services/PayPal.php
index acda8a02..0a1ecdeb 100644
--- a/src/Services/PayPal.php
+++ b/src/Services/PayPal.php
@@ -12,16 +12,14 @@ class PayPal
/**
* PayPal constructor.
*
- * @param string|array $config
+ * @param array $config
*
* @throws Exception
*/
- public function __construct($config = '')
+ public function __construct(array $config = [])
{
// Setting PayPal API Credentials
- if (is_array($config)) {
- $this->setConfig($config);
- }
+ $this->setConfig($config);
$this->httpBodyParam = 'form_params';
@@ -36,19 +34,17 @@ public function __construct($config = '')
* Set ExpressCheckout API endpoints & options.
*
* @param array $credentials
- *
- * @return void
*/
- protected function setOptions($credentials)
+ protected function setOptions(array $credentials)
{
// Setting API Endpoints
- $this->config['api_url'] = 'https://api.paypal.com';
+ $this->config['api_url'] = 'https://api-m.paypal.com';
$this->config['gateway_url'] = 'https://www.paypal.com';
$this->config['ipn_url'] = 'https://ipnpb.paypal.com/cgi-bin/webscr';
if ($this->mode === 'sandbox') {
- $this->config['api_url'] = 'https://api.sandbox.paypal.com';
+ $this->config['api_url'] = 'https://api-m.sandbox.paypal.com';
$this->config['gateway_url'] = 'https://www.sandbox.paypal.com';
$this->config['ipn_url'] = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
diff --git a/src/Traits/PayPalAPI.php b/src/Traits/PayPalAPI.php
index bd135659..23cc3f6b 100644
--- a/src/Traits/PayPalAPI.php
+++ b/src/Traits/PayPalAPI.php
@@ -8,13 +8,18 @@ trait PayPalAPI
use PayPalAPI\CatalogProducts;
use PayPalAPI\Disputes;
use PayPalAPI\DisputesActions;
+ use PayPalAPI\Identity;
use PayPalAPI\Invoices;
use PayPalAPI\InvoicesSearch;
use PayPalAPI\InvoicesTemplates;
use PayPalAPI\Orders;
+ use PayPalAPI\PartnerReferrals;
+ use PayPalAPI\PaymentExperienceWebProfiles;
use PayPalAPI\PaymentAuthorizations;
use PayPalAPI\PaymentCaptures;
use PayPalAPI\PaymentRefunds;
+ use PayPalAPI\Payouts;
+ use PayPalAPI\ReferencedPayouts;
use PayPalAPI\BillingPlans;
use PayPalAPI\Subscriptions;
use PayPalAPI\Reporting;
@@ -35,7 +40,6 @@ trait PayPalAPI
public function getAccessToken()
{
$this->apiEndPoint = 'v1/oauth2/token';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['auth'] = [$this->config['client_id'], $this->config['client_secret']];
$this->options[$this->httpBodyParam] = [
@@ -44,6 +48,9 @@ public function getAccessToken()
$response = $this->doPayPalRequest();
+ unset($this->options['auth']);
+ unset($this->options[$this->httpBodyParam]);
+
if (isset($response['access_token'])) {
$this->setAccessToken($response);
@@ -60,7 +67,7 @@ public function getAccessToken()
*
* @return void
*/
- public function setAccessToken($response)
+ public function setAccessToken(array $response)
{
$this->access_token = $response['access_token'];
@@ -74,10 +81,8 @@ public function setAccessToken($response)
*
* @return void
*/
- private function setPayPalAppId($response)
+ private function setPayPalAppId(array $response)
{
- if (empty($this->config['app_id'])) {
- $this->config['app_id'] = $response['app_id'];
- }
+ $this->config['app_id'] = empty($response['app_id']) ? $this->config['app_id'] : $response['app_id'];
}
}
diff --git a/src/Traits/PayPalAPI/BillingPlans.php b/src/Traits/PayPalAPI/BillingPlans.php
index 062ae0a9..08e93f44 100644
--- a/src/Traits/PayPalAPI/BillingPlans.php
+++ b/src/Traits/PayPalAPI/BillingPlans.php
@@ -7,7 +7,8 @@ trait BillingPlans
/**
* Create a new billing plan.
*
- * @param array $data
+ * @param array $data
+ * @param string $request_id
*
* @throws \Throwable
*
@@ -15,11 +16,11 @@ trait BillingPlans
*
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create
*/
- public function createPlan(array $data)
+ public function createPlan(array $data, $request_id)
{
$this->apiEndPoint = 'v1/billing/plans';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
+ $this->options['headers']['PayPal-Request-Id'] = $request_id;
$this->options['json'] = $data;
$this->verb = 'post';
@@ -42,8 +43,9 @@ public function createPlan(array $data)
*/
public function listPlans($page = 1, $size = 20, $totals = true)
{
+ $totals = ($totals) ? 'true' : 'false';
+
$this->apiEndPoint = "v1/billing/plans?page={$page}&page_size={$size}&total_required={$totals}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -65,7 +67,6 @@ public function listPlans($page = 1, $size = 20, $totals = true)
public function updatePlan($plan_id, array $data)
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -88,7 +89,6 @@ public function updatePlan($plan_id, array $data)
public function showPlanDetails($plan_id)
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -109,7 +109,6 @@ public function showPlanDetails($plan_id)
public function activatePlan($plan_id)
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'post';
@@ -130,7 +129,6 @@ public function activatePlan($plan_id)
public function deactivatePlan($plan_id)
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'post';
@@ -152,7 +150,6 @@ public function deactivatePlan($plan_id)
public function updatePlanPricing($plan_id, array $pricing)
{
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/update-pricing-schemes";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'pricing_schemes' => $pricing,
diff --git a/src/Traits/PayPalAPI/CatalogProducts.php b/src/Traits/PayPalAPI/CatalogProducts.php
index c543447b..3a3e3513 100644
--- a/src/Traits/PayPalAPI/CatalogProducts.php
+++ b/src/Traits/PayPalAPI/CatalogProducts.php
@@ -19,7 +19,6 @@ trait CatalogProducts
public function createProduct(array $data, $request_id)
{
$this->apiEndPoint = 'v1/catalogs/products';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['headers']['PayPal-Request-Id'] = $request_id;
$this->options['json'] = $data;
@@ -47,7 +46,6 @@ public function listProducts($page = 1, $size = 20, $totals = true)
$totals = ($totals === true) ? 'true' : 'false';
$this->apiEndPoint = "v1/catalogs/products?page={$page}&page_size={$size}&total_required={$totals}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -69,7 +67,6 @@ public function listProducts($page = 1, $size = 20, $totals = true)
public function updateProduct($product_id, array $data)
{
$this->apiEndPoint = "v1/catalogs/products/{$product_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -92,7 +89,6 @@ public function updateProduct($product_id, array $data)
public function showProductDetails($product_id)
{
$this->apiEndPoint = "v1/catalogs/products/{$product_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
diff --git a/src/Traits/PayPalAPI/Disputes.php b/src/Traits/PayPalAPI/Disputes.php
index ecf10da3..eeda5ad3 100644
--- a/src/Traits/PayPalAPI/Disputes.php
+++ b/src/Traits/PayPalAPI/Disputes.php
@@ -16,7 +16,6 @@ trait Disputes
public function listDisputes()
{
$this->apiEndPoint = 'v1/customer/disputes';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -38,7 +37,6 @@ public function listDisputes()
public function updateDispute(array $data, $dispute_id)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -61,7 +59,6 @@ public function updateDispute(array $data, $dispute_id)
public function showDisputeDetails($dispute_id)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
diff --git a/src/Traits/PayPalAPI/DisputesActions.php b/src/Traits/PayPalAPI/DisputesActions.php
index 41a74a5d..76947055 100644
--- a/src/Traits/PayPalAPI/DisputesActions.php
+++ b/src/Traits/PayPalAPI/DisputesActions.php
@@ -20,7 +20,6 @@ trait DisputesActions
public function acceptDisputeClaim($dispute_id, $dispute_note, array $data = [])
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-claim";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$data['note'] = $dispute_note;
$data['accept_claim_type'] = 'REFUND';
@@ -47,7 +46,6 @@ public function acceptDisputeClaim($dispute_id, $dispute_note, array $data = [])
public function acceptDisputeOfferResolution($dispute_id, $dispute_note)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-offer";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'note' => $dispute_note,
@@ -74,7 +72,6 @@ public function acceptDisputeOfferResolution($dispute_id, $dispute_note)
public function acknowledgeItemReturned($dispute_id, $dispute_note, $acknowledgement_type)
{
$this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/acknowledge-return-item";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'note' => $dispute_note,
diff --git a/src/Traits/PayPalAPI/Identity.php b/src/Traits/PayPalAPI/Identity.php
new file mode 100644
index 00000000..551b44ba
--- /dev/null
+++ b/src/Traits/PayPalAPI/Identity.php
@@ -0,0 +1,109 @@
+apiEndPoint = 'v1/identity/oauth2/userinfo?schema=paypalv1.1';
+
+ $this->verb = 'get';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Create a merchant application.
+ *
+ * @param string $client_name
+ * @param array $redirect_uris
+ * @param array $contacts
+ * @param string $payer_id
+ * @param string $migrated_app
+ * @param string $application_type
+ * @param string $logo_url
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/identity/v1/#applications_post
+ */
+ public function createMerchantApplication($client_name, array $redirect_uris, array $contacts, $payer_id, $migrated_app, $application_type = 'web', $logo_url = '')
+ {
+ $this->apiEndPoint = 'v1/identity/applications';
+
+ $this->options['json'] = [
+ 'application_type' => $application_type,
+ 'redirect_uris' => $redirect_uris,
+ 'client_name' => $client_name,
+ 'contacts' => $contacts,
+ 'payer_id' => $payer_id,
+ 'migrated_app' => $migrated_app,
+ ];
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Create a merchant application.
+ *
+ * @param array $features
+ * @param string $account_property
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_post
+ */
+ public function setAccountProperties(array $features, $account_property = 'BRAINTREE_MERCHANT')
+ {
+ $this->apiEndPoint = 'v1/identity/account-settings';
+
+ $this->options['json'] = [
+ 'account_property' => $account_property,
+ 'features' => $features,
+ ];
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Create a merchant application.
+ *
+ * @param string $account_property
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_deactivate
+ */
+ public function disableAccountProperties($account_property = 'BRAINTREE_MERCHANT')
+ {
+ $this->apiEndPoint = 'v1/identity/account-settings/deactivate';
+
+ $this->options['json'] = [
+ 'account_property' => $account_property,
+ ];
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+}
diff --git a/src/Traits/PayPalAPI/InvoiceSearch/Filters.php b/src/Traits/PayPalAPI/InvoiceSearch/Filters.php
new file mode 100644
index 00000000..d358a5c0
--- /dev/null
+++ b/src/Traits/PayPalAPI/InvoiceSearch/Filters.php
@@ -0,0 +1,245 @@
+invoice_search_filters['recipient_email'] = $email;
+
+ return $this;
+ }
+
+ /**
+ * @param string $name
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByRecipientFirstName($name)
+ {
+ $this->invoice_search_filters['recipient_first_name'] = $name;
+
+ return $this;
+ }
+
+ /**
+ * @param string $name
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByRecipientLastName($name)
+ {
+ $this->invoice_search_filters['recipient_last_name'] = $name;
+
+ return $this;
+ }
+
+ /**
+ * @param string $name
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByRecipientBusinessName($name)
+ {
+ $this->invoice_search_filters['recipient_business_name'] = $name;
+
+ return $this;
+ }
+
+ /**
+ * @param string $invoice_number
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByInvoiceNumber($invoice_number)
+ {
+ $this->invoice_search_filters['invoice_number'] = $invoice_number;
+
+ return $this;
+ }
+
+ /**
+ * @param array $status
+ *
+ * @throws \Exception
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ *
+ * @see https://developer.paypal.com/docs/api/invoicing/v2/#definition-invoice_status
+ */
+ public function addInvoiceFilterByInvoiceStatus(array $status)
+ {
+ $invalid_status = false;
+
+ foreach ($status as $item) {
+ if (!in_array($item, $this->invoices_status_types)) {
+ $invalid_status = true;
+ }
+ }
+
+ if ($invalid_status === true) {
+ throw new \Exception('status should be always one of these: '.implode(',', $this->invoices_date_types));
+ }
+
+ $this->invoice_search_filters['status'] = $status;
+
+ return $this;
+ }
+
+ /**
+ * @param string $reference
+ * @param bool $memo
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByReferenceorMemo($reference, $memo = false)
+ {
+ $field = ($memo === false) ? 'reference' : 'memo';
+
+ $this->invoice_search_filters[$field] = $reference;
+
+ return $this;
+ }
+
+ /**
+ * @param string $currency_code
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByCurrencyCode($currency_code = '')
+ {
+ $currency = !isset($currency_code) ? $this->getCurrency() : $currency_code;
+
+ $this->invoice_search_filters['currency_code'] = $currency;
+
+ return $this;
+ }
+
+ /**
+ * @param float $start_amount
+ * @param float $end_amount
+ * @param string $amount_currency
+ *
+ * @throws \Exception
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByAmountRange($start_amount, $end_amount, $amount_currency = '')
+ {
+ if ($start_amount > $end_amount) {
+ throw new \Exception('Starting amount should always be less than end amount!');
+ }
+
+ $currency = !isset($amount_currency) ? $this->getCurrency() : $amount_currency;
+
+ $this->invoice_search_filters['total_amount_range'] = [
+ 'lower_amount' => [
+ 'currency_code' => $currency,
+ 'value' => $start_amount,
+ ],
+ 'upper_amount' => [
+ 'currency_code' => $currency,
+ 'value' => $end_amount,
+ ],
+ ];
+
+ return $this;
+ }
+
+ /**
+ * @param string $start_date
+ * @param string $end_date
+ * @param string $date_type
+ *
+ * @throws \Exception
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByDateRange($start_date, $end_date, $date_type)
+ {
+ $start_date_obj = Carbon::parse($start_date);
+ $end_date_obj = Carbon::parse($end_date);
+
+ if ($start_date_obj->gt($end_date_obj)) {
+ throw new \Exception('Starting date should always be less than the end date!');
+ }
+
+ if (!in_array($date_type, $this->invoices_date_types)) {
+ throw new \Exception('date type should be always one of these: '.implode(',', $this->invoices_date_types));
+ }
+
+ $this->invoice_search_filters["{$date_type}_range"] = [
+ 'start' => $start_date,
+ 'end' => $end_date,
+ ];
+
+ return $this;
+ }
+
+ /**
+ * @param bool $archived
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addInvoiceFilterByArchivedStatus($archived = null)
+ {
+ $this->invoice_search_filters['archived'] = $archived;
+
+ return $this;
+ }
+
+ /**
+ * @param array $fields
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ *
+ * @see https://developer.paypal.com/docs/api/invoicing/v2/#definition-field
+ */
+ public function addInvoiceFilterByFields(array $fields)
+ {
+ $this->invoice_search_filters['status'] = $fields;
+
+ return $this;
+ }
+}
diff --git a/src/Traits/PayPalAPI/Invoices.php b/src/Traits/PayPalAPI/Invoices.php
index 2091450b..11c5b071 100644
--- a/src/Traits/PayPalAPI/Invoices.php
+++ b/src/Traits/PayPalAPI/Invoices.php
@@ -16,7 +16,6 @@ trait Invoices
public function generateInvoiceNumber()
{
$this->apiEndPoint = 'v2/invoicing/generate-next-invoice-number';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'post';
@@ -37,7 +36,6 @@ public function generateInvoiceNumber()
public function createInvoice(array $data)
{
$this->apiEndPoint = 'v2/invoicing/invoices';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -69,7 +67,6 @@ public function listInvoices($page = 1, $size = 20, $totals = true, array $field
$fields = ($fields_list->count() > 0) ? "&fields={$fields_list->implode(',')}" : '';
$this->apiEndPoint = "v2/invoicing/invoices?page={$page}&page_size={$size}&total_required={$totals}{$fields}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -90,7 +87,6 @@ public function listInvoices($page = 1, $size = 20, $totals = true, array $field
public function deleteInvoice($invoice_id)
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'delete';
@@ -112,7 +108,6 @@ public function deleteInvoice($invoice_id)
public function updateInvoice($invoice_id, array $data)
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -135,7 +130,6 @@ public function updateInvoice($invoice_id, array $data)
public function showInvoiceDetails($invoice_id)
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -157,7 +151,6 @@ public function showInvoiceDetails($invoice_id)
public function cancelInvoice($invoice_id, array $notes)
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/cancel";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $notes;
@@ -179,10 +172,9 @@ public function cancelInvoice($invoice_id, array $notes)
*
* @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-qr-code
*/
- public function generateQRCodeInvoice($invoice_id, $width = 200, $height = 20)
+ public function generateQRCodeInvoice($invoice_id, $width = 100, $height = 100)
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/generate-qr-code";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'width' => $width,
@@ -212,7 +204,6 @@ public function generateQRCodeInvoice($invoice_id, $width = 200, $height = 20)
public function registerPaymentInvoice($invoice_id, $payment_date, $payment_method, $amount, $payment_note = '', $payment_id = '')
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/payments";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$data = [
'payment_id' => $payment_id,
@@ -247,7 +238,6 @@ public function registerPaymentInvoice($invoice_id, $payment_date, $payment_meth
public function deleteExternalPaymentInvoice($invoice_id, $transaction_id)
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/payments/{$transaction_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'delete';
@@ -271,7 +261,6 @@ public function deleteExternalPaymentInvoice($invoice_id, $transaction_id)
public function refundInvoice($invoice_id, $payment_date, $payment_method, $amount)
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/refunds";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$data = [
'refund_date' => $payment_date,
@@ -304,7 +293,6 @@ public function refundInvoice($invoice_id, $payment_date, $payment_method, $amou
public function deleteRefundInvoice($invoice_id, $transaction_id)
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/refunds/{$transaction_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'delete';
@@ -330,7 +318,6 @@ public function deleteRefundInvoice($invoice_id, $transaction_id)
public function sendInvoice($invoice_id, $subject = '', $note = '', $send_recipient = true, $send_merchant = false, array $recipients = [])
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/send";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$data = [
'subject' => !empty($subject) ? $subject : '',
@@ -366,7 +353,6 @@ public function sendInvoice($invoice_id, $subject = '', $note = '', $send_recipi
public function sendInvoiceReminder($invoice_id, $subject = '', $note = '', $send_recipient = true, $send_merchant = false, array $recipients = [])
{
$this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/remind";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$data = [
'subject' => !empty($subject) ? $subject : '',
diff --git a/src/Traits/PayPalAPI/InvoicesSearch.php b/src/Traits/PayPalAPI/InvoicesSearch.php
index 8229b19f..6b65a92a 100644
--- a/src/Traits/PayPalAPI/InvoicesSearch.php
+++ b/src/Traits/PayPalAPI/InvoicesSearch.php
@@ -2,16 +2,18 @@
namespace Srmklive\PayPal\Traits\PayPalAPI;
+use Srmklive\PayPal\Traits\PayPalAPI\InvoiceSearch\Filters;
+
trait InvoicesSearch
{
+ use Filters;
+
/**
* Search and return existing invoices.
*
- * @param array $filters
- * @param int $page
- * @param int $size
- * @param bool $totals
- * @param array $fields
+ * @param int $page
+ * @param int $size
+ * @param bool $totals
*
* @throws \Throwable
*
@@ -19,18 +21,19 @@ trait InvoicesSearch
*
* @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list
*/
- public function searchInvoices($filters, $page = 1, $size = 20, $totals = true, array $fields = [])
+ public function searchInvoices($page = 1, $size = 20, $totals = true)
{
$totals = ($totals === true) ? 'true' : 'false';
- $fields_list = collect($fields);
-
- $fields = ($fields_list->count() > 0) ? "&fields={$fields_list->implode(',')}" : '';
+ if (collect($this->invoice_search_filters)->count() < 1) {
+ $this->invoice_search_filters = [
+ 'currency_code' => $this->getCurrency(),
+ ];
+ }
- $this->apiEndPoint = "v2/invoicing/search-invoices?page={$page}&page_size={$size}&total_required={$totals}{$fields}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
+ $this->apiEndPoint = "v2/invoicing/search-invoices?page={$page}&page_size={$size}&total_required={$totals}";
- $this->options['json'] = $filters;
+ $this->options['json'] = $this->invoice_search_filters;
$this->verb = 'post';
diff --git a/src/Traits/PayPalAPI/InvoicesTemplates.php b/src/Traits/PayPalAPI/InvoicesTemplates.php
index b9bf252f..ab16bb5a 100644
--- a/src/Traits/PayPalAPI/InvoicesTemplates.php
+++ b/src/Traits/PayPalAPI/InvoicesTemplates.php
@@ -18,7 +18,6 @@ trait InvoicesTemplates
public function createInvoiceTemplate(array $data)
{
$this->apiEndPoint = 'v2/invoicing/templates';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -43,7 +42,6 @@ public function createInvoiceTemplate(array $data)
public function listInvoiceTemplates($page = 1, $size = 20, $fields = 'all')
{
$this->apiEndPoint = "v2/invoicing/templates?page={$page}&page_size={$size}&fields={$fields}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -64,7 +62,6 @@ public function listInvoiceTemplates($page = 1, $size = 20, $fields = 'all')
public function deleteInvoiceTemplate($template_id)
{
$this->apiEndPoint = "v2/invoicing/templates/{$template_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'delete';
@@ -86,7 +83,6 @@ public function deleteInvoiceTemplate($template_id)
public function updateInvoiceTemplate($template_id, array $data)
{
$this->apiEndPoint = "v2/invoicing/templates/{$template_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -109,7 +105,6 @@ public function updateInvoiceTemplate($template_id, array $data)
public function showInvoiceTemplateDetails($template_id)
{
$this->apiEndPoint = "v2/invoicing/templates/{$template_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
diff --git a/src/Traits/PayPalAPI/Orders.php b/src/Traits/PayPalAPI/Orders.php
index 789b1308..e1d5feeb 100644
--- a/src/Traits/PayPalAPI/Orders.php
+++ b/src/Traits/PayPalAPI/Orders.php
@@ -18,7 +18,6 @@ trait Orders
public function createOrder(array $data)
{
$this->apiEndPoint = 'v2/checkout/orders';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = (object) $data;
@@ -30,7 +29,6 @@ public function createOrder(array $data)
public function updateOrder($order_id, array $data)
{
$this->apiEndPoint = "v2/checkout/orders/{$order_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = (object) $data;
@@ -53,7 +51,6 @@ public function updateOrder($order_id, array $data)
public function showOrderDetails($order_id)
{
$this->apiEndPoint = "v2/checkout/orders/{$order_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -75,7 +72,6 @@ public function showOrderDetails($order_id)
public function authorizePaymentOrder($order_id, array $data = [])
{
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/authorize";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = (object) $data;
@@ -99,7 +95,6 @@ public function authorizePaymentOrder($order_id, array $data = [])
public function capturePaymentOrder($order_id, array $data = [])
{
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/capture";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = (object) $data;
diff --git a/src/Traits/PayPalAPI/PartnerReferrals.php b/src/Traits/PayPalAPI/PartnerReferrals.php
new file mode 100644
index 00000000..7543b8a6
--- /dev/null
+++ b/src/Traits/PayPalAPI/PartnerReferrals.php
@@ -0,0 +1,48 @@
+apiEndPoint = 'v2/customer/partner-referrals';
+
+ $this->options['json'] = $partner_data;
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Get Partner Referral Details.
+ *
+ * @param string $partner_referral_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/partner-referrals/v2/#partner-referrals_read
+ */
+ public function showReferralData($partner_referral_id)
+ {
+ $this->apiEndPoint = "v2/customer/partner-referrals/{$partner_referral_id}";
+
+ $this->verb = 'get';
+
+ return $this->doPayPalRequest();
+ }
+}
diff --git a/src/Traits/PayPalAPI/PaymentAuthorizations.php b/src/Traits/PayPalAPI/PaymentAuthorizations.php
index fd4136d5..d82ea5d5 100644
--- a/src/Traits/PayPalAPI/PaymentAuthorizations.php
+++ b/src/Traits/PayPalAPI/PaymentAuthorizations.php
@@ -18,7 +18,6 @@ trait PaymentAuthorizations
public function showAuthorizedPaymentDetails($authorization_id)
{
$this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -42,7 +41,6 @@ public function showAuthorizedPaymentDetails($authorization_id)
public function captureAuthorizedPayment($authorization_id, $invoice_id, $amount, $note)
{
$this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/capture";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'amount' => [
@@ -74,7 +72,6 @@ public function captureAuthorizedPayment($authorization_id, $invoice_id, $amount
public function reAuthorizeAuthorizedPayment($authorization_id, $amount)
{
$this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/reauthorize";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'amount' => [
@@ -102,7 +99,6 @@ public function reAuthorizeAuthorizedPayment($authorization_id, $amount)
public function voidAuthorizedPayment($authorization_id)
{
$this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/void";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'post';
diff --git a/src/Traits/PayPalAPI/PaymentCaptures.php b/src/Traits/PayPalAPI/PaymentCaptures.php
index 4960df1c..3775be4d 100644
--- a/src/Traits/PayPalAPI/PaymentCaptures.php
+++ b/src/Traits/PayPalAPI/PaymentCaptures.php
@@ -18,7 +18,6 @@ trait PaymentCaptures
public function showCapturedPaymentDetails($capture_id)
{
$this->apiEndPoint = "v2/payments/captures/{$capture_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -42,7 +41,6 @@ public function showCapturedPaymentDetails($capture_id)
public function refundCapturedPayment($capture_id, $invoice_id, $amount, $note)
{
$this->apiEndPoint = "v2/payments/captures/{$capture_id}/refund";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'amount' => [
diff --git a/src/Traits/PayPalAPI/PaymentExperienceWebProfiles.php b/src/Traits/PayPalAPI/PaymentExperienceWebProfiles.php
new file mode 100644
index 00000000..067e2d4f
--- /dev/null
+++ b/src/Traits/PayPalAPI/PaymentExperienceWebProfiles.php
@@ -0,0 +1,134 @@
+apiEndPoint = 'v1/payment-experience/web-profiles';
+
+ $this->verb = 'get';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Create a Web Experience Profile.
+ *
+ * @param array $data
+ * @param string $request_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_get-list
+ */
+ public function createWebExperienceProfile(array $data, $request_id)
+ {
+ $this->apiEndPoint = 'v1/payment-experience/web-profiles';
+
+ $this->options['headers']['PayPal-Request-Id'] = $request_id;
+ $this->options['json'] = $data;
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Delete a Web Experience Profile.
+ *
+ * @param string $profile_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_get-list
+ */
+ public function deleteWebExperienceProfile($profile_id)
+ {
+ $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}";
+
+ $this->verb = 'delete';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Partially update a Web Experience Profile.
+ *
+ * @param string $profile_id
+ * @param array $data
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_get-list
+ */
+ public function patchWebExperienceProfile($profile_id, array $data)
+ {
+ $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}";
+
+ $this->options['json'] = $data;
+
+ $this->verb = 'patch';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Partially update a Web Experience Profile.
+ *
+ * @param string $profile_id
+ * @param array $data
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_get-list
+ */
+ public function updateWebExperienceProfile($profile_id, array $data)
+ {
+ $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}";
+
+ $this->options['json'] = $data;
+
+ $this->verb = 'put';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Delete a Web Experience Profile.
+ *
+ * @param string $profile_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profiles_get-list
+ */
+ public function showWebExperienceProfileDetails($profile_id)
+ {
+ $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}";
+
+ $this->verb = 'get';
+
+ return $this->doPayPalRequest();
+ }
+}
diff --git a/src/Traits/PayPalAPI/PaymentRefunds.php b/src/Traits/PayPalAPI/PaymentRefunds.php
index 367e527e..a4363186 100644
--- a/src/Traits/PayPalAPI/PaymentRefunds.php
+++ b/src/Traits/PayPalAPI/PaymentRefunds.php
@@ -18,7 +18,6 @@ trait PaymentRefunds
public function showRefundDetails($refund_id)
{
$this->apiEndPoint = "v2/payments/refunds/{$refund_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
diff --git a/src/Traits/PayPalAPI/Payouts.php b/src/Traits/PayPalAPI/Payouts.php
new file mode 100644
index 00000000..10d33b52
--- /dev/null
+++ b/src/Traits/PayPalAPI/Payouts.php
@@ -0,0 +1,88 @@
+apiEndPoint = 'v1/payments/payouts';
+
+ $this->options['json'] = $data;
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Show Batch Payout details by ID.
+ *
+ * @param string $payout_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts_get
+ */
+ public function showBatchPayoutDetails($payout_id)
+ {
+ $this->apiEndPoint = "v1/payments/payouts/{$payout_id}";
+
+ $this->verb = 'get';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Show Payout Item details by ID.
+ *
+ * @param string $payout_item_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_get
+ */
+ public function showPayoutItemDetails($payout_item_id)
+ {
+ $this->apiEndPoint = "v1/payments/payouts-item/{$payout_item_id}";
+
+ $this->verb = 'get';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Show Payout Item details by ID.
+ *
+ * @param string $payout_item_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_cancel
+ */
+ public function cancelUnclaimedPayoutItem($payout_item_id)
+ {
+ $this->apiEndPoint = "v1/payments/payouts-item/{$payout_item_id}/cancel";
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+}
diff --git a/src/Traits/PayPalAPI/ReferencedPayouts.php b/src/Traits/PayPalAPI/ReferencedPayouts.php
new file mode 100644
index 00000000..7e18112c
--- /dev/null
+++ b/src/Traits/PayPalAPI/ReferencedPayouts.php
@@ -0,0 +1,100 @@
+apiEndPoint = 'v1/payments/referenced-payouts';
+
+ $this->options['headers']['PayPal-Request-Id'] = $request_id;
+ $this->options['headers']['PayPal-Partner-Attribution-Id'] = $partner_attribution_id;
+ $this->options['json'] = $data;
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Show Batch Payout details by ID.
+ *
+ * @param string $batch_payout_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts_get_batch_details
+ */
+ public function listItemsReferencedInBatchPayout($batch_payout_id)
+ {
+ $this->apiEndPoint = "v1/payments/referenced-payouts/{$batch_payout_id}";
+
+ $this->verb = 'get';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Create a referenced Batch Payout Item.
+ *
+ * @param array $data
+ * @param string $request_id
+ * @param string $partner_attribution_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts-items_create
+ */
+ public function createReferencedBatchPayoutItem(array $data, $request_id, $partner_attribution_id)
+ {
+ $this->apiEndPoint = 'v1/payments/referenced-payouts-items';
+
+ $this->options['headers']['PayPal-Request-Id'] = $request_id;
+ $this->options['headers']['PayPal-Partner-Attribution-Id'] = $partner_attribution_id;
+ $this->options['json'] = $data;
+
+ $this->verb = 'post';
+
+ return $this->doPayPalRequest();
+ }
+
+ /**
+ * Show Payout Item details by ID.
+ *
+ * @param string $payout_item_id
+ * @param string $partner_attribution_id
+ *
+ * @throws \Throwable
+ *
+ * @return array|\Psr\Http\Message\StreamInterface|string
+ *
+ * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts-items_get
+ */
+ public function showReferencedPayoutItemDetails($payout_item_id, $partner_attribution_id)
+ {
+ $this->apiEndPoint = "v1/payments/referenced-payouts-items/{$payout_item_id}";
+
+ $this->options['headers']['PayPal-Partner-Attribution-Id'] = $partner_attribution_id;
+ $this->verb = 'get';
+
+ return $this->doPayPalRequest();
+ }
+}
diff --git a/src/Traits/PayPalAPI/Reporting.php b/src/Traits/PayPalAPI/Reporting.php
index d721ec1d..0ff0023a 100644
--- a/src/Traits/PayPalAPI/Reporting.php
+++ b/src/Traits/PayPalAPI/Reporting.php
@@ -28,7 +28,6 @@ public function listTransactions(array $filters, $fields = 'all', $page = 1, $pa
})->implode('');
$this->apiEndPoint = "v1/reporting/transactions?{$filters_list}fields={$fields}&page={$page}&page_size={$page_size}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -39,6 +38,7 @@ public function listTransactions(array $filters, $fields = 'all', $page = 1, $pa
* List available balance.
*
* @param string $date
+ * @param string $balance_currency
*
* @throws \Throwable
*
@@ -46,12 +46,12 @@ public function listTransactions(array $filters, $fields = 'all', $page = 1, $pa
*
* @see https://developer.paypal.com/docs/api/transaction-search/v1/#balances_get
*/
- public function listBalances($date = '')
+ public function listBalances($date = '', $balance_currency = '')
{
$date = empty($date) ? Carbon::now()->toIso8601String() : Carbon::parse($date)->toIso8601String();
+ $currency = empty($currency) ? $this->getCurrency() : $balance_currency;
- $this->apiEndPoint = "v1/reporting/balances?currency_code={$this->currency}&as_of_date={$date}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
+ $this->apiEndPoint = "v1/reporting/balances?currency_code={$currency}&as_of_date={$date}";
$this->verb = 'get';
diff --git a/src/Traits/PayPalAPI/Subscriptions.php b/src/Traits/PayPalAPI/Subscriptions.php
index c814dc11..0cd2996a 100644
--- a/src/Traits/PayPalAPI/Subscriptions.php
+++ b/src/Traits/PayPalAPI/Subscriptions.php
@@ -6,6 +6,8 @@
trait Subscriptions
{
+ use Subscriptions\Helpers;
+
/**
* Create a new subscription.
*
@@ -20,7 +22,6 @@ trait Subscriptions
public function createSubscription(array $data)
{
$this->apiEndPoint = 'v1/billing/subscriptions';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -44,7 +45,6 @@ public function createSubscription(array $data)
public function updateSubscription($subscription_id, array $data)
{
$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -67,7 +67,6 @@ public function updateSubscription($subscription_id, array $data)
public function showSubscriptionDetails($subscription_id)
{
$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -89,7 +88,6 @@ public function showSubscriptionDetails($subscription_id)
public function activateSubscription($subscription_id, $reason)
{
$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/activate";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = ['reason' => $reason];
@@ -113,7 +111,6 @@ public function activateSubscription($subscription_id, $reason)
public function cancelSubscription($subscription_id, $reason)
{
$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/cancel";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = ['reason' => $reason];
@@ -137,7 +134,6 @@ public function cancelSubscription($subscription_id, $reason)
public function suspendSubscription($subscription_id, $reason)
{
$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/suspend";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = ['reason' => $reason];
@@ -162,7 +158,6 @@ public function suspendSubscription($subscription_id, $reason)
public function captureSubscriptionPayment($subscription_id, $note, $amount)
{
$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/capture";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'note' => $note,
@@ -193,7 +188,6 @@ public function captureSubscriptionPayment($subscription_id, $note, $amount)
public function reviseSubscription($subscription_id, array $items)
{
$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/revise";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $items;
@@ -229,7 +223,6 @@ public function listSubscriptionTransactions($subscription_id, $start_date = '',
$end_date = $end_date->toIso8601ZuluString();
$this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/transactions?start_time={$start_date}&end_time={$end_date}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
diff --git a/src/Traits/PayPalAPI/Subscriptions/Helpers.php b/src/Traits/PayPalAPI/Subscriptions/Helpers.php
new file mode 100644
index 00000000..f9f3397c
--- /dev/null
+++ b/src/Traits/PayPalAPI/Subscriptions/Helpers.php
@@ -0,0 +1,304 @@
+toIso8601String() : Carbon::now()->toIso8601String();
+
+ $subscription = $this->createSubscription([
+ 'plan_id' => $this->billing_plan['id'],
+ 'start_time' => $start_date,
+ 'quantity' => 1,
+ 'subscriber' => [
+ 'name' => [
+ 'given_name' => $customer_name,
+ ],
+ 'email_address' => $customer_email,
+ ],
+ ]);
+
+ unset($this->product);
+ unset($this->billing_plan);
+ unset($this->trial_pricing);
+
+ return $subscription;
+ }
+
+ /**
+ * Add a subscription trial pricing tier.
+ *
+ * @param string $interval_type
+ * @param string $interval_count
+ * @param float|int $price
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addPlanTrialPricing($interval_type, $interval_count, $price = 0)
+ {
+ $this->trial_pricing = $this->addPlanBillingCycle($interval_type, $interval_count, $price, true);
+
+ return $this;
+ }
+
+ /**
+ * Create a recurring daily billing plan.
+ *
+ * @param string $name
+ * @param string $description
+ * @param float|int $price
+ *
+ * @throws Throwable
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addDailyPlan($name, $description, $price)
+ {
+ if (isset($this->billing_plan)) {
+ return $this;
+ }
+
+ $plan_pricing = $this->addPlanBillingCycle('DAY', 1, $price);
+ $billing_cycles = collect([$this->trial_pricing, $plan_pricing])->filter()->toArray();
+
+ $this->addBillingPlan($name, $description, $billing_cycles);
+
+ return $this;
+ }
+
+ /**
+ * Create a recurring weekly billing plan.
+ *
+ * @param string $name
+ * @param string $description
+ * @param float|int $price
+ *
+ * @throws Throwable
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addWeeklyPlan($name, $description, $price)
+ {
+ if (isset($this->billing_plan)) {
+ return $this;
+ }
+
+ $plan_pricing = $this->addPlanBillingCycle('WEEK', 1, $price);
+ $billing_cycles = collect([$this->trial_pricing, $plan_pricing])->filter()->toArray();
+
+ $this->addBillingPlan($name, $description, $billing_cycles);
+
+ return $this;
+ }
+
+ /**
+ * Create a recurring monthly billing plan.
+ *
+ * @param string $name
+ * @param string $description
+ * @param float|int $price
+ *
+ * @throws Throwable
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addMonthlyPlan($name, $description, $price)
+ {
+ if (isset($this->billing_plan)) {
+ return $this;
+ }
+
+ $plan_pricing = $this->addPlanBillingCycle('MONTH', 1, $price);
+ $billing_cycles = collect([$this->trial_pricing, $plan_pricing])->filter()->toArray();
+
+ $this->addBillingPlan($name, $description, $billing_cycles);
+
+ return $this;
+ }
+
+ /**
+ * Create a recurring annual billing plan.
+ *
+ * @param string $name
+ * @param string $description
+ * @param float|int $price
+ *
+ * @throws Throwable
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addAnnualPlan($name, $description, $price)
+ {
+ if (isset($this->billing_plan)) {
+ return $this;
+ }
+
+ $plan_pricing = $this->addPlanBillingCycle('YEAR', 1, $price);
+ $billing_cycles = collect([$this->trial_pricing, $plan_pricing])->filter()->toArray();
+
+ $this->addBillingPlan($name, $description, $billing_cycles);
+
+ return $this;
+ }
+
+ /**
+ * Add Plan's Billing cycle.
+ *
+ * @param string $interval_unit
+ * @param int $interval_count
+ * @param float $price
+ * @param bool $trial
+ *
+ * @return array
+ */
+ protected function addPlanBillingCycle($interval_unit, $interval_count, $price, $trial = false)
+ {
+ $pricing_scheme = [
+ 'fixed_price' => [
+ 'value' => $price,
+ 'currency_code' => $this->getCurrency(),
+ ],
+ ];
+
+ return [
+ 'frequency' => [
+ 'interval_unit' => $interval_unit,
+ 'interval_count' => $interval_count,
+ ],
+ 'tenure_type' => ($trial === true) ? 'TRIAL' : 'REGULAR',
+ 'sequence' => ($trial === true) ? 1 : 2,
+ 'total_cycles' => ($trial === true) ? 1 : 0,
+ 'pricing_scheme' => $pricing_scheme,
+ ];
+ }
+
+ /**
+ * Create a product for a subscription's billing plan.
+ *
+ * @param string $name
+ * @param string $description
+ * @param string $type
+ * @param string $category
+ *
+ * @throws Throwable
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addProduct($name, $description, $type, $category)
+ {
+ if (isset($this->product)) {
+ return $this;
+ }
+
+ $request_id = Str::random();
+
+ $this->product = $this->createProduct([
+ 'name' => $name,
+ 'description' => $description,
+ 'type' => $type,
+ 'category' => $category,
+ ], $request_id);
+
+ return $this;
+ }
+
+ /**
+ * Add subscription's billing plan's product by ID.
+ *
+ * @param string $product_id
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addProductById($product_id)
+ {
+ $this->product = [
+ 'id' => $product_id,
+ ];
+
+ return $this;
+ }
+
+ /**
+ * Add subscription's billing plan by ID.
+ *
+ * @param string $plan_id
+ *
+ * @return \Srmklive\PayPal\Services\PayPal
+ */
+ public function addBillingPlanById($plan_id)
+ {
+ $this->billing_plan = [
+ 'id' => $plan_id,
+ ];
+
+ return $this;
+ }
+
+ /**
+ * Create a product for a subscription's billing plan.
+ *
+ * @param string $name
+ * @param string $description
+ * @param array $billing_cycles
+ *
+ * @throws Throwable
+ *
+ * @return void
+ */
+ protected function addBillingPlan($name, $description, array $billing_cycles)
+ {
+ $request_id = Str::random();
+
+ $plan_params = [
+ 'product_id' => $this->product['id'],
+ 'name' => $name,
+ 'description' => $description,
+ 'status' => 'ACTIVE',
+ 'billing_cycles' => $billing_cycles,
+ 'payment_preferences' => [
+ 'auto_bill_outstanding' => true,
+ 'setup_fee_failure_action' => 'CONTINUE',
+ 'payment_failure_threshold' => $this->payment_failure_threshold,
+ ],
+ ];
+
+ $this->billing_plan = $this->createPlan($plan_params, $request_id);
+ }
+}
diff --git a/src/Traits/PayPalAPI/Trackers.php b/src/Traits/PayPalAPI/Trackers.php
index 1c318db2..a379ec11 100644
--- a/src/Traits/PayPalAPI/Trackers.php
+++ b/src/Traits/PayPalAPI/Trackers.php
@@ -18,7 +18,6 @@ trait Trackers
public function showTrackingDetails($tracking_id)
{
$this->apiEndPoint = "v1/shipping/trackers/{$tracking_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -37,10 +36,9 @@ public function showTrackingDetails($tracking_id)
*
* @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_put
*/
- public function updateTrackingDetails($tracking_id, $data)
+ public function updateTrackingDetails($tracking_id, array $data)
{
$this->apiEndPoint = "v1/shipping/trackers/{$tracking_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -60,10 +58,9 @@ public function updateTrackingDetails($tracking_id, $data)
*
* @see https://developer.paypal.com/docs/api/tracking/v1/#trackers-batch_post
*/
- public function addBatchTracking($data)
+ public function addBatchTracking(array $data)
{
$this->apiEndPoint = 'v1/shipping/trackers-batch';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
diff --git a/src/Traits/PayPalAPI/WebHooks.php b/src/Traits/PayPalAPI/WebHooks.php
index 21f9cffa..cba7a4e1 100644
--- a/src/Traits/PayPalAPI/WebHooks.php
+++ b/src/Traits/PayPalAPI/WebHooks.php
@@ -19,7 +19,6 @@ trait WebHooks
public function createWebHook($url, array $events)
{
$this->apiEndPoint = 'v1/notifications/webhooks';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$data = ['url' => $url];
$data['event_types'] = collect($events)->map(function ($item) {
@@ -45,7 +44,6 @@ public function createWebHook($url, array $events)
public function listWebHooks()
{
$this->apiEndPoint = 'v1/notifications/webhooks';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -66,7 +64,6 @@ public function listWebHooks()
public function deleteWebHook($web_hook_id)
{
$this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'delete';
@@ -88,7 +85,6 @@ public function deleteWebHook($web_hook_id)
public function updateWebHook($web_hook_id, array $data)
{
$this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
@@ -111,7 +107,6 @@ public function updateWebHook($web_hook_id, array $data)
public function showWebHookDetails($web_hook_id)
{
$this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -132,7 +127,6 @@ public function showWebHookDetails($web_hook_id)
public function listWebHookEvents($web_hook_id)
{
$this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}/event-types";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
diff --git a/src/Traits/PayPalAPI/WebHooksEvents.php b/src/Traits/PayPalAPI/WebHooksEvents.php
index 84d03b51..47deb48a 100644
--- a/src/Traits/PayPalAPI/WebHooksEvents.php
+++ b/src/Traits/PayPalAPI/WebHooksEvents.php
@@ -16,7 +16,6 @@ trait WebHooksEvents
public function listEventTypes()
{
$this->apiEndPoint = 'v1/notifications/webhooks-event-types';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -35,7 +34,6 @@ public function listEventTypes()
public function listEvents()
{
$this->apiEndPoint = 'v1/notifications/webhooks-events';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -56,7 +54,6 @@ public function listEvents()
public function showEventDetails($event_id)
{
$this->apiEndPoint = "v1/notifications/webhooks-events/{$event_id}";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->verb = 'get';
@@ -78,7 +75,6 @@ public function showEventDetails($event_id)
public function resendEventNotification($event_id, array $items)
{
$this->apiEndPoint = "v1/notifications/webhooks-events/{$event_id}/resend";
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = [
'webhook_ids' => $items,
diff --git a/src/Traits/PayPalAPI/WebHooksVerification.php b/src/Traits/PayPalAPI/WebHooksVerification.php
index a1f1cfba..4a936f2c 100644
--- a/src/Traits/PayPalAPI/WebHooksVerification.php
+++ b/src/Traits/PayPalAPI/WebHooksVerification.php
@@ -18,7 +18,6 @@ trait WebHooksVerification
public function verifyWebHook(array $data)
{
$this->apiEndPoint = 'v1/notifications/verify-webhook-signature';
- $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
$this->options['json'] = $data;
diff --git a/src/Traits/PayPalHttpClient.php b/src/Traits/PayPalHttpClient.php
index 99b557c1..d13bbbbc 100644
--- a/src/Traits/PayPalHttpClient.php
+++ b/src/Traits/PayPalHttpClient.php
@@ -93,13 +93,24 @@ protected function setCurlConstants()
'CURLOPT_SSLCERT' => 10025,
];
- foreach ($constants as $key => $value) {
- if (!defined($key)) {
- define($key, $constants[$key]);
- }
+ foreach ($constants as $key => $item) {
+ $this->defineCurlConstant($key, $item);
}
}
+ /**
+ * Declare a curl constant.
+ *
+ * @param string $key
+ * @param string $value
+ *
+ * @return bool
+ */
+ protected function defineCurlConstant($key, $value)
+ {
+ return defined($key) ? true : define($key, $value);
+ }
+
/**
* Function to initialize/override Http Client.
*
@@ -107,7 +118,7 @@ protected function setCurlConstants()
*
* @return void
*/
- public function setClient($client = null)
+ public function setClient(HttpClient $client = null)
{
if ($client instanceof HttpClient) {
$this->client = $client;
@@ -192,6 +203,8 @@ private function makeHttpRequest()
private function doPayPalRequest($decode = true)
{
try {
+ $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
+
// Perform PayPal HTTP API request.
$response = $this->makeHttpRequest();
diff --git a/src/Traits/PayPalRequest.php b/src/Traits/PayPalRequest.php
index fc1959c2..26878f62 100644
--- a/src/Traits/PayPalRequest.php
+++ b/src/Traits/PayPalRequest.php
@@ -49,14 +49,12 @@ trait PayPalRequest
*
* @param array $credentials
*
- * @throws \RuntimeException
- *
- * @return void
+ * @throws \RuntimeException|\Exception
*/
- public function setApiCredentials($credentials)
+ public function setApiCredentials(array $credentials)
{
if (empty($credentials)) {
- throw new RuntimeException('Empty configuration provided. Please provide valid configuration for Express Checkout API.');
+ $this->throwConfigurationException();
}
// Setting Default PayPal Mode If not set
@@ -79,7 +77,7 @@ public function setApiCredentials($credentials)
*
* @throws \RuntimeException
*
- * @return $this
+ * @return \Srmklive\PayPal\Services\PayPal
*/
public function setCurrency($currency = 'USD')
{
@@ -97,8 +95,6 @@ public function setCurrency($currency = 'USD')
/**
* Return the set currency.
- *
- * @return string
*/
public function getCurrency()
{
@@ -143,11 +139,11 @@ public function getRequestHeader($key)
*
* @param array $config
*
- * @throws Exception
+ * @throws \Exception
*/
- private function setConfig(array $config = [])
+ private function setConfig(array $config)
{
- $api_config = function_exists('config') ? config('paypal') : $config;
+ $api_config = function_exists('config') && !empty(config('paypal')) ? config('paypal') : $config;
// Set Api Credentials
$this->setApiCredentials($api_config);
@@ -157,15 +153,15 @@ private function setConfig(array $config = [])
* Set API environment to be used by PayPal.
*
* @param array $credentials
- *
- * @return void
*/
- private function setApiEnvironment($credentials)
+ private function setApiEnvironment(array $credentials)
{
$this->mode = 'live';
if (!empty($credentials['mode'])) {
$this->setValidApiEnvironment($credentials['mode']);
+ } else {
+ $this->throwConfigurationException();
}
}
@@ -173,8 +169,6 @@ private function setApiEnvironment($credentials)
* Validate & set the environment to be used by PayPal.
*
* @param string $mode
- *
- * @return void
*/
private function setValidApiEnvironment($mode)
{
@@ -186,13 +180,21 @@ private function setValidApiEnvironment($mode)
*
* @param array $credentials
*
- * @throws Exception
- *
- * @return void
+ * @throws \Exception
*/
- private function setApiProviderConfiguration($credentials)
+ private function setApiProviderConfiguration(array $credentials)
{
// Setting PayPal API Credentials
+ if (empty($credentials[$this->mode])) {
+ $this->throwConfigurationException();
+ }
+
+ foreach (['client_id', 'client_secret', 'app_id'] as $item) {
+ if (empty($credentials[$this->mode][$item])) {
+ throw new RuntimeException("{$item} missing from the provided configuration. Please add your application {$item}.");
+ }
+ }
+
collect($credentials[$this->mode])->map(function ($value, $key) {
$this->config[$key] = $value;
});
@@ -205,4 +207,12 @@ private function setApiProviderConfiguration($credentials)
$this->setOptions($credentials);
}
+
+ /**
+ * @throws RuntimeException
+ */
+ private function throwConfigurationException()
+ {
+ throw new RuntimeException('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
+ }
}
diff --git a/tests/Feature/AdapterConfigTest.php b/tests/Feature/AdapterConfigTest.php
index 30660aeb..f848ffcf 100644
--- a/tests/Feature/AdapterConfigTest.php
+++ b/tests/Feature/AdapterConfigTest.php
@@ -24,10 +24,49 @@ protected function setUp()
public function it_throws_exception_if_invalid_credentials_are_provided()
{
$this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
$this->client = new PayPalClient([]);
}
+ /** @test */
+ public function it_throws_exception_if_invalid_mode_is_provided()
+ {
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
+
+ $credentials = $this->getApiCredentials();
+ $credentials['mode'] = '';
+
+ $this->client = new PayPalClient($credentials);
+ }
+
+ /** @test */
+ public function it_throws_exception_if_empty_credentials_are_provided()
+ {
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
+
+ $credentials = $this->getApiCredentials();
+ $credentials['sandbox'] = [];
+
+ $this->client = new PayPalClient($credentials);
+ }
+
+ /** @test */
+ public function it_throws_exception_if_credentials_items_are_not_provided()
+ {
+ $item = 'client_id';
+
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage("{$item} missing from the provided configuration. Please add your application {$item}.");
+
+ $credentials = $this->getApiCredentials();
+ $credentials['sandbox'][$item] = '';
+
+ $client = new PayPalClient($credentials);
+ }
+
/** @test */
public function it_can_take_valid_credentials_and_return_the_client_instance()
{
diff --git a/tests/Feature/AdapterCreateSubscriptionHelpersTest.php b/tests/Feature/AdapterCreateSubscriptionHelpersTest.php
new file mode 100644
index 00000000..7831266b
--- /dev/null
+++ b/tests/Feature/AdapterCreateSubscriptionHelpersTest.php
@@ -0,0 +1,373 @@
+client = new PayPalClient($this->getApiCredentials());
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockAccessTokenResponse()
+ )
+ );
+ $response = $this->client->getAccessToken();
+
+ self::$access_token = $response['access_token'];
+
+ parent::setUp();
+ }
+
+ /** @test */
+ public function it_can_create_a_monthly_subscription()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateCatalogProductsResponse()
+ )
+ );
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreatePlansResponse()
+ )
+ );
+
+ $this->client = $this->client->addPlanTrialPricing('DAY', 7)
+ ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_can_create_a_daily_subscription()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateCatalogProductsResponse()
+ )
+ );
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreatePlansResponse()
+ )
+ );
+
+ $this->client = $this->client->addPlanTrialPricing('DAY', 7)
+ ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_can_create_a_weekly_subscription()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateCatalogProductsResponse()
+ )
+ );
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreatePlansResponse()
+ )
+ );
+
+ $this->client = $this->client->addPlanTrialPricing('DAY', 7)
+ ->addWeeklyPlan('Demo Plan', 'Demo Plan', 50);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_can_create_an_annual_subscription()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateCatalogProductsResponse()
+ )
+ );
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreatePlansResponse()
+ )
+ );
+
+ $this->client = $this->client->addPlanTrialPricing('DAY', 7)
+ ->addAnnualPlan('Demo Plan', 'Demo Plan', 100);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_can_create_a_subscription_without_trial()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateCatalogProductsResponse()
+ )
+ );
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE');
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreatePlansResponse()
+ )
+ );
+
+ $this->client = $this->client->addMonthlyPlan('Demo Plan', 'Demo Plan', 100);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_can_create_a_subscription_by_existing_product_and_billing_plan()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->addProductById('PROD-XYAB12ABSB7868434')
+ ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
+ ->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_daily_subscription()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
+ ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
+ ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
+ ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_weekly_subscription()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
+ ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
+ ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
+ ->addWeeklyPlan('Demo Plan', 'Demo Plan', 100);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_monthly_subscription()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
+ ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
+ ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
+ ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+
+ /** @test */
+ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_an_annual_subscription()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $start_date = Carbon::now()->addDay()->toDateString();
+
+ $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434')
+ ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
+ ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
+ ->addAnnualPlan('Demo Plan', 'Demo Plan', 100);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateSubscriptionResponse()
+ )
+ );
+
+ $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', $response);
+ $this->assertArrayHasKey('plan_id', $response);
+ }
+}
diff --git a/tests/Feature/AdapterFeatureTest.php b/tests/Feature/AdapterFeatureTest.php
index 989f5ff7..3668bfa5 100644
--- a/tests/Feature/AdapterFeatureTest.php
+++ b/tests/Feature/AdapterFeatureTest.php
@@ -73,7 +73,7 @@ public function it_can_create_a_billing_plan()
$expectedParams = $this->createPlanParams();
- $response = $this->client->createPlan($expectedParams);
+ $response = $this->client->createPlan($expectedParams, 'some-request-id');
$this->assertNotEmpty($response);
$this->assertArrayHasKey('id', $response);
@@ -805,12 +805,394 @@ public function it_can_search_invoices()
)
);
- $filters = $this->invoiceSearchParams();
+ $response = $this->client->searchInvoices();
+
+ $this->assertArrayHasKey('total_pages', $response);
+ $this->assertArrayHasKey('total_items', $response);
+ }
+
+ /** @test */
+ public function it_can_search_invoices_with_custom_filters()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockSearchInvoicesResponse()
+ )
+ );
- $response = $this->client->searchInvoices($filters);
+ $response = $this->client
+ ->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();
$this->assertArrayHasKey('total_pages', $response);
$this->assertArrayHasKey('total_items', $response);
+ $this->assertArrayHasKey('items', $response);
+ }
+
+ /** @test */
+ public function it_throws_exception_on_search_invoices_with_invalid_status()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockSearchInvoicesResponse()
+ )
+ );
+
+ $this->expectException(\Exception::class);
+
+ $response = $this->client
+ ->addInvoiceFilterByInvoiceStatus(['DECLINED'])
+ ->searchInvoices();
+ }
+
+ /** @test */
+ public function it_throws_exception_on_search_invoices_with_invalid_amount_ranges()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockSearchInvoicesResponse()
+ )
+ );
+
+ $filters = $this->invoiceSearchParams();
+
+ $this->expectException(\Exception::class);
+
+ $response = $this->client
+ ->addInvoiceFilterByAmountRange(50, 30)
+ ->searchInvoices();
+ }
+
+ /** @test */
+ public function it_throws_exception_on_search_invoices_with_invalid_date_ranges()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockSearchInvoicesResponse()
+ )
+ );
+
+ $filters = $this->invoiceSearchParams();
+
+ $this->expectException(\Exception::class);
+
+ $response = $this->client
+ ->addInvoiceFilterByDateRange('2018-07-01', '2018-06-21', 'invoice_date')
+ ->searchInvoices();
+ }
+
+ /** @test */
+ public function it_throws_exception_on_search_invoices_with_invalid_date_range_type()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockSearchInvoicesResponse()
+ )
+ );
+
+ $filters = $this->invoiceSearchParams();
+
+ $this->expectException(\Exception::class);
+
+ $response = $this->client
+ ->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'declined_date')
+ ->searchInvoices();
+ }
+
+ /** @test */
+ public function it_can_get_user_profile_details()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockShowProfileInfoResponse()
+ )
+ );
+
+ $response = $this->client->showProfileInfo();
+
+ $this->assertArrayHasKey('user_id', $response);
+ $this->assertArrayHasKey('payer_id', $response);
+ $this->assertArrayHasKey('emails', $response);
+ }
+
+ /** @test */
+ public function it_can_create_merchant_applications()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreateMerchantApplicationResponse()
+ )
+ );
+
+ $response = $this->client->createMerchantApplication(
+ 'AGGREGATOR',
+ [
+ 'https://example.com/callback',
+ 'https://example.com/callback2',
+ ],
+ [
+ 'facilitator@example.com',
+ 'merchant@example.com',
+ ],
+ 'WDJJHEBZ4X2LY',
+ 'some-open-id'
+ );
+
+ $this->assertArrayHasKey('client_name', $response);
+ $this->assertArrayHasKey('contacts', $response);
+ $this->assertArrayHasKey('redirect_uris', $response);
+ }
+
+ /** @test */
+ public function it_can_set_account_properties()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client('')
+ );
+
+ $response = $this->client->setAccountProperties($this->mockSetAccountPropertiesParams());
+
+ $this->assertEmpty($response);
+ }
+
+ /** @test */
+ public function it_can_disable_account_properties()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockUpdateOrdersResponse()
+ )
+ );
+
+ $response = $this->client->disableAccountProperties();
+
+ $this->assertEmpty($response);
+ }
+
+ /** @test */
+ public function it_can_create_partner_referral()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockCreatePartnerReferralsResponse()
+ )
+ );
+
+ $expectedParams = $this->mockCreatePartnerReferralParams();
+
+ $response = $this->client->createPartnerReferral($expectedParams);
+
+ $this->assertArrayHasKey('links', $response);
+ }
+
+ /** @test */
+ public function it_can_get_referral_details()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockShowReferralDataResponse()
+ )
+ );
+
+ $partner_referral_id = 'ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0=';
+
+ $response = $this->client->showReferralData($partner_referral_id);
+
+ $this->assertArrayHasKey('partner_referral_id', $response);
+ $this->assertArrayHasKey('referral_data', $response);
+ }
+
+ /** @test */
+ public function it_can_list_web_experience_profiles()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockListWebProfilesResponse()
+ )
+ );
+
+ $response = $this->client->listWebExperienceProfiles();
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('id', collect($response)->first());
+ }
+
+ /** @test */
+ public function it_can_create_web_experience_profile()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockWebProfileResponse()
+ )
+ );
+
+ $expectedParams = $this->mockCreateWebProfileParams();
+
+ $response = $this->client->createWebExperienceProfile($expectedParams, 'some-request-id');
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('name', $response);
+ }
+
+ /** @test */
+ public function it_can_delete_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER';
+
+ $response = $this->client->deleteWebExperienceProfile($expectedParams);
+
+ $this->assertEmpty($response);
+ }
+
+ /** @test */
+ public function it_can_partially_update_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $expectedParams = $this->partiallyUpdateWebProfileParams();
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->patchWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams);
+
+ $this->assertEmpty($response);
+ }
+
+ /** @test */
+ public function it_can_fully_update_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $expectedParams = $this->updateWebProfileParams();
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->updateWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams);
+
+ $this->assertEmpty($response);
+ }
+
+ /** @test */
+ public function it_can_get_web_experience_profile_details()
+ {
+ $expectedResponse = $this->mockWebProfileResponse();
+
+ $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER';
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->showWebExperienceProfileDetails($expectedParams);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('name', $response);
}
/** @test */
@@ -1079,6 +1461,188 @@ public function it_can_show_details_for_a_refund()
$this->assertArrayHasKey('id', $response);
}
+ /** @test */
+ public function it_can_create_batch_payout()
+ {
+ $expectedResponse = $this->mockCreateBatchPayoutResponse();
+
+ $expectedParams = $this->mockCreateBatchPayoutParams();
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->createBatchPayout($expectedParams);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('batch_header', $response);
+ }
+
+ /** @test */
+ public function it_can_show_batch_payout_details()
+ {
+ $expectedResponse = $this->showBatchPayoutResponse();
+
+ $expectedParams = 'FYXMPQTX4JC9N';
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->showBatchPayoutDetails($expectedParams);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('batch_header', $response);
+ $this->assertArrayHasKey('items', $response);
+ }
+
+ /** @test */
+ public function it_can_show_batch_payout_item_details()
+ {
+ $expectedResponse = $this->showBatchPayoutItemResponse();
+
+ $expectedParams = '8AELMXH8UB2P8';
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->showPayoutItemDetails($expectedParams);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('payout_item_id', $response);
+ $this->assertArrayHasKey('payout_batch_id', $response);
+ $this->assertArrayHasKey('payout_item', $response);
+ }
+
+ /** @test */
+ public function it_can_cancel_unclaimed_batch_payout_item()
+ {
+ $expectedResponse = $this->mockCancelUnclaimedBatchItemResponse();
+
+ $expectedParams = '8AELMXH8UB2P8';
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->cancelUnclaimedPayoutItem($expectedParams);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('payout_item_id', $response);
+ $this->assertArrayHasKey('payout_batch_id', $response);
+ $this->assertArrayHasKey('payout_item', $response);
+ }
+
+ /** @test */
+ public function it_can_create_referenced_batch_payout()
+ {
+ $expectedResponse = $this->mockCreateReferencedBatchPayoutResponse();
+
+ $expectedParams = $this->mockCreateReferencedBatchPayoutParams();
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->createReferencedBatchPayout($expectedParams, 'some-request-id', 'some-attribution-id');
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('links', $response);
+ }
+
+ /** @test */
+ public function it_can_list_items_referenced_in_batch_payout()
+ {
+ $expectedResponse = $this->mockShowReferencedBatchPayoutResponse();
+
+ $expectedParams = 'KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E=';
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->listItemsReferencedInBatchPayout($expectedParams);
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('links', $response);
+ }
+
+ /** @test */
+ public function it_can_create_referenced_batch_payout_item()
+ {
+ $expectedResponse = $this->mockCreateReferencedBatchPayoutItemResponse();
+
+ $expectedParams = $this->mockCreateReferencedBatchPayoutItemParams();
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->createReferencedBatchPayoutItem($expectedParams, 'some-request-id', 'some-attribution-id');
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('links', $response);
+ }
+
+ /** @test */
+ public function it_can_show_referenced_payout_item_details()
+ {
+ $expectedResponse = $this->mockShowReferencedBatchPayoutItemResponse();
+
+ $expectedParams = 'CDZEC5MJ8R5HY';
+
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client($expectedResponse)
+ );
+
+ $response = $this->client->showReferencedPayoutItemDetails($expectedParams, 'some-attribution-id');
+
+ $this->assertNotEmpty($response);
+ $this->assertArrayHasKey('item_id', $response);
+ $this->assertArrayHasKey('reference_id', $response);
+ }
+
/** @test */
public function it_can_list_transactions()
{
@@ -1125,6 +1689,27 @@ public function it_can_list_account_balances()
$this->assertNotEmpty($response);
}
+ /** @test */
+ public function it_can_list_account_balances_for_a_different_currency()
+ {
+ $this->client->setAccessToken([
+ 'access_token' => self::$access_token,
+ 'token_type' => 'Bearer',
+ ]);
+
+ $this->client->setClient(
+ $this->mock_http_client(
+ $this->mockListBalancesResponse()
+ )
+ );
+
+ $date = Carbon::now()->subDays(30)->toIso8601String();
+
+ $response = $this->client->listBalances($date, 'EUR');
+
+ $this->assertNotEmpty($response);
+ }
+
/** @test */
public function it_can_create_a_subscription()
{
diff --git a/tests/MockClientClasses.php b/tests/MockClientClasses.php
index 3a4d5168..469e141b 100644
--- a/tests/MockClientClasses.php
+++ b/tests/MockClientClasses.php
@@ -11,6 +11,11 @@
trait MockClientClasses
{
+ /**
+ * @param array $response
+ *
+ * @return HttpClient
+ */
private function mock_http_client($response)
{
$mock = new HttpMockHandler([
@@ -88,7 +93,7 @@ private function getMockCredentials()
'sandbox' => [
'client_id' => 'some-client-id',
'client_secret' => 'some-access-token',
- 'app_id' => '',
+ 'app_id' => 'some-app-id',
],
'payment_action' => 'Sale',
'currency' => 'USD',
@@ -105,7 +110,7 @@ private function getApiCredentials()
'sandbox' => [
'client_id' => 'AbJgVQM6g57qPrXimGkBz1UaBOXn1dKLSdUj7BgiB3JhzJRCapzCnkPq6ycOOmgXHtnDZcjwLMJ2IdAI',
'client_secret' => 'EPd_XBNkfhU3-MlSw6gpa6EJj9x8QBdsC3o77jZZWjcFy_hrjR4kzBP8QN3MPPH4g52U_acG4-ogWUxI',
- 'app_id' => '',
+ 'app_id' => 'APP-80W284485P519543T',
],
'payment_action' => 'Sale',
'currency' => 'USD',
diff --git a/tests/MockRequestPayloads.php b/tests/MockRequestPayloads.php
index 60feee0b..9cbb86aa 100644
--- a/tests/MockRequestPayloads.php
+++ b/tests/MockRequestPayloads.php
@@ -8,12 +8,17 @@ trait MockRequestPayloads
use Mocks\Requests\CatalogProducts;
use Mocks\Requests\Disputes;
use Mocks\Requests\DisputesActions;
+ use Mocks\Requests\Identity;
use Mocks\Requests\Invoices;
use Mocks\Requests\InvoicesSearch;
use Mocks\Requests\InvoicesTemplates;
use Mocks\Requests\Orders;
+ use Mocks\Requests\PartnerReferrals;
+ use Mocks\Requests\PaymentExperienceWebProfiles;
use Mocks\Requests\PaymentAuthorizations;
use Mocks\Requests\PaymentCaptures;
+ use Mocks\Requests\Payouts;
+ use Mocks\Requests\ReferencedPayouts;
use Mocks\Requests\Subscriptions;
use Mocks\Requests\Trackers;
use Mocks\Requests\WebHooks;
diff --git a/tests/MockResponsePayloads.php b/tests/MockResponsePayloads.php
index 0e73d447..2354ce4e 100644
--- a/tests/MockResponsePayloads.php
+++ b/tests/MockResponsePayloads.php
@@ -8,13 +8,18 @@ trait MockResponsePayloads
use Mocks\Responses\CatalogProducts;
use Mocks\Responses\Disputes;
use Mocks\Responses\DisputesActions;
+ use Mocks\Responses\Identity;
use Mocks\Responses\Invoices;
use Mocks\Responses\InvoicesSearch;
use Mocks\Responses\InvoicesTemplates;
use Mocks\Responses\Orders;
+ use Mocks\Responses\PartnerReferrals;
+ use Mocks\Responses\PaymentExperienceWebProfiles;
use Mocks\Responses\PaymentAuthorizations;
use Mocks\Responses\PaymentCaptures;
use Mocks\Responses\PaymentRefunds;
+ use Mocks\Responses\Payouts;
+ use Mocks\Responses\ReferencedPayouts;
use Mocks\Responses\Reporting;
use Mocks\Responses\Subscriptions;
use Mocks\Responses\Trackers;
diff --git a/tests/Mocks/Requests/DisputesActions.php b/tests/Mocks/Requests/DisputesActions.php
index cd20ec3c..ac50f308 100644
--- a/tests/Mocks/Requests/DisputesActions.php
+++ b/tests/Mocks/Requests/DisputesActions.php
@@ -18,7 +18,7 @@ protected function acceptDisputeClaimParams()
/**
* @return array
*/
- protected function acceptDisputeResoltuionParams()
+ protected function acceptDisputeResolutionParams()
{
return \GuzzleHttp\json_decode('{
"note": "I am ok with the refund offered."
diff --git a/tests/Mocks/Requests/Identity.php b/tests/Mocks/Requests/Identity.php
new file mode 100644
index 00000000..2ae96d17
--- /dev/null
+++ b/tests/Mocks/Requests/Identity.php
@@ -0,0 +1,49 @@
+setApiCredentials($this->getMockCredentials());
$mockClient->getAccessToken();
- $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, 'some-request-id'));
}
/** @test */
diff --git a/tests/Unit/Adapter/IdentityTest.php b/tests/Unit/Adapter/IdentityTest.php
new file mode 100644
index 00000000..443d66ba
--- /dev/null
+++ b/tests/Unit/Adapter/IdentityTest.php
@@ -0,0 +1,89 @@
+mockShowProfileInfoResponse();
+
+ $expectedMethod = 'showProfileInfo';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}());
+ }
+
+ /** @test */
+ public function it_can_create_merchant_applications()
+ {
+ $expectedResponse = $this->mockCreateMerchantApplicationResponse();
+
+ $expectedMethod = 'createMerchantApplication';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}(
+ 'AGGREGATOR',
+ [
+ 'https://example.com/callback',
+ 'https://example.com/callback2',
+ ],
+ [
+ 'facilitator@example.com',
+ 'merchant@example.com',
+ ],
+ 'WDJJHEBZ4X2LY',
+ 'some-open-id'
+ ));
+ }
+
+ /** @test */
+ public function it_can_set_account_properties()
+ {
+ $expectedResponse = '';
+
+ $expectedParams = $this->mockSetAccountPropertiesParams();
+
+ $expectedMethod = 'setAccountProperties';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+
+ /** @test */
+ public function it_can_disable_account_properties()
+ {
+ $expectedResponse = '';
+
+ $expectedMethod = 'disableAccountProperties';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}());
+ }
+}
diff --git a/tests/Unit/Adapter/InvoicesSearchTest.php b/tests/Unit/Adapter/InvoicesSearchTest.php
index 94881304..473b203e 100644
--- a/tests/Unit/Adapter/InvoicesSearchTest.php
+++ b/tests/Unit/Adapter/InvoicesSearchTest.php
@@ -18,7 +18,20 @@ public function it_can_search_invoices()
{
$expectedResponse = $this->mockSearchInvoicesResponse();
- $expectedParams = $this->invoiceSearchParams();
+ $expectedMethod = 'searchInvoices';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}(1, 1, true));
+ }
+
+ /** @test */
+ public function it_can_search_invoices_with_custom_filters()
+ {
+ $expectedResponse = $this->mockSearchInvoicesResponse();
$expectedMethod = 'searchInvoices';
@@ -27,6 +40,9 @@ public function it_can_search_invoices()
$mockClient->setApiCredentials($this->getMockCredentials());
$mockClient->getAccessToken();
- $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, 1, 1, true));
+ $this->assertEquals($expectedResponse, $mockClient->addInvoiceFilterByRecipientEmail('bill-me@example.com')
+ ->addInvoiceFilterByCurrencyCode('USD')
+ ->addInvoiceFilterByAmountRange(30, 50)
+ ->{$expectedMethod}(1, 1, true));
}
}
diff --git a/tests/Unit/Adapter/PartnerReferralsTest.php b/tests/Unit/Adapter/PartnerReferralsTest.php
new file mode 100644
index 00000000..9d67fa27
--- /dev/null
+++ b/tests/Unit/Adapter/PartnerReferralsTest.php
@@ -0,0 +1,49 @@
+mockCreatePartnerReferralsResponse();
+
+ $expectedParams = $this->mockCreatePartnerReferralParams();
+
+ $expectedMethod = 'createPartnerReferral';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+
+ /** @test */
+ public function it_can_get_referral_details()
+ {
+ $expectedResponse = $this->mockShowReferralDataResponse();
+
+ $expectedParams = 'ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0=';
+
+ $expectedMethod = 'showReferralData';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+}
diff --git a/tests/Unit/Adapter/PaymentExperienceWebProfilesTest.php b/tests/Unit/Adapter/PaymentExperienceWebProfilesTest.php
new file mode 100644
index 00000000..7f907e96
--- /dev/null
+++ b/tests/Unit/Adapter/PaymentExperienceWebProfilesTest.php
@@ -0,0 +1,115 @@
+mockListWebProfilesResponse();
+
+ $expectedMethod = 'listWebExperienceProfiles';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}());
+ }
+
+ /** @test */
+ public function it_can_create_web_experience_profile()
+ {
+ $expectedResponse = $this->mockWebProfileResponse();
+
+ $expectedParams = $this->mockCreateWebProfileParams();
+
+ $expectedMethod = 'createWebExperienceProfile';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, 'some-request-id'));
+ }
+
+ /** @test */
+ public function it_can_delete_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER';
+
+ $expectedMethod = 'deleteWebExperienceProfile';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+
+ /** @test */
+ public function it_can_partially_update_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $expectedParams = $this->partiallyUpdateWebProfileParams();
+
+ $expectedMethod = 'patchWebExperienceProfile';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams));
+ }
+
+ /** @test */
+ public function it_can_fully_update_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $expectedParams = $this->updateWebProfileParams();
+
+ $expectedMethod = 'updateWebExperienceProfile';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams));
+ }
+
+ /** @test */
+ public function it_can_get_web_experience_profile_details()
+ {
+ $expectedResponse = $this->mockWebProfileResponse();
+
+ $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER';
+
+ $expectedMethod = 'showWebExperienceProfileDetails';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+}
diff --git a/tests/Unit/Adapter/PayoutsTest.php b/tests/Unit/Adapter/PayoutsTest.php
new file mode 100644
index 00000000..da4a79ca
--- /dev/null
+++ b/tests/Unit/Adapter/PayoutsTest.php
@@ -0,0 +1,83 @@
+mockCreateBatchPayoutResponse();
+
+ $expectedParams = $this->mockCreateBatchPayoutParams();
+
+ $expectedMethod = 'createBatchPayout';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+
+ /** @test */
+ public function it_can_show_batch_payout_details()
+ {
+ $expectedResponse = $this->showBatchPayoutResponse();
+
+ $expectedParams = 'FYXMPQTX4JC9N';
+
+ $expectedMethod = 'showBatchPayoutDetails';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+
+ /** @test */
+ public function it_can_show_batch_payout_item_details()
+ {
+ $expectedResponse = $this->showBatchPayoutItemResponse();
+
+ $expectedParams = '8AELMXH8UB2P8';
+
+ $expectedMethod = 'showPayoutItemDetails';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+
+ /** @test */
+ public function it_can_cancel_unclaimed_batch_payout_item()
+ {
+ $expectedResponse = $this->mockCancelUnclaimedBatchItemResponse();
+
+ $expectedParams = '8AELMXH8UB2P8';
+
+ $expectedMethod = 'cancelUnclaimedPayoutItem';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+}
diff --git a/tests/Unit/Adapter/ReferencedPayoutsTest.php b/tests/Unit/Adapter/ReferencedPayoutsTest.php
new file mode 100644
index 00000000..fce21f05
--- /dev/null
+++ b/tests/Unit/Adapter/ReferencedPayoutsTest.php
@@ -0,0 +1,83 @@
+mockCreateReferencedBatchPayoutResponse();
+
+ $expectedParams = $this->mockCreateReferencedBatchPayoutParams();
+
+ $expectedMethod = 'createReferencedBatchPayout';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, 'some-request-id', 'some-attribution-id'));
+ }
+
+ /** @test */
+ public function it_can_list_items_referenced_in_batch_payout()
+ {
+ $expectedResponse = $this->mockShowReferencedBatchPayoutResponse();
+
+ $expectedParams = 'KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E=';
+
+ $expectedMethod = 'listItemsReferencedInBatchPayout';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
+ }
+
+ /** @test */
+ public function it_can_create_referenced_batch_payout_item()
+ {
+ $expectedResponse = $this->mockCreateReferencedBatchPayoutItemResponse();
+
+ $expectedParams = $this->mockCreateReferencedBatchPayoutItemParams();
+
+ $expectedMethod = 'createReferencedBatchPayoutItem';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, 'some-request-id', 'some-attribution-id'));
+ }
+
+ /** @test */
+ public function it_can_show_referenced_payout_item_details()
+ {
+ $expectedResponse = $this->mockShowReferencedBatchPayoutItemResponse();
+
+ $expectedParams = 'CDZEC5MJ8R5HY';
+
+ $expectedMethod = 'showReferencedPayoutItemDetails';
+
+ $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);
+
+ $mockClient->setApiCredentials($this->getMockCredentials());
+ $mockClient->getAccessToken();
+
+ $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, 'some-attribution-id'));
+ }
+}
diff --git a/tests/Unit/AdapterTest.php b/tests/Unit/AdapterTest.php
index 588b7e62..358f40e5 100644
--- a/tests/Unit/AdapterTest.php
+++ b/tests/Unit/AdapterTest.php
@@ -15,11 +15,57 @@ class AdapterTest extends TestCase
/** @test */
public function it_can_be_instantiated()
{
- $client = new PayPalClient();
+ $client = new PayPalClient($this->getMockCredentials());
$this->assertInstanceOf(PayPalClient::class, $client);
}
+ /** @test */
+ public function it_throws_exception_if_invalid_credentials_are_provided()
+ {
+ $this->expectException(\RuntimeException::class);
+
+ $client = new PayPalClient();
+ }
+
+ /** @test */
+ public function it_throws_exception_if_invalid_mode_is_provided()
+ {
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
+
+ $credentials = $this->getMockCredentials();
+ $credentials['mode'] = '';
+
+ $client = new PayPalClient($credentials);
+ }
+
+ /** @test */
+ public function it_throws_exception_if_empty_credentials_are_provided()
+ {
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
+
+ $credentials = $this->getMockCredentials();
+ $credentials['sandbox'] = [];
+
+ $client = new PayPalClient($credentials);
+ }
+
+ /** @test */
+ public function it_throws_exception_if_credentials_items_are_not_provided()
+ {
+ $item = 'client_id';
+
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage("{$item} missing from the provided configuration. Please add your application {$item}.");
+
+ $credentials = $this->getMockCredentials();
+ $credentials['sandbox'][$item] = '';
+
+ $client = new PayPalClient($credentials);
+ }
+
/** @test */
public function it_can_get_access_token()
{
diff --git a/tests/Unit/Client/BillingPlansTest.php b/tests/Unit/Client/BillingPlansTest.php
index 51ff6ef8..102db94c 100644
--- a/tests/Unit/Client/BillingPlansTest.php
+++ b/tests/Unit/Client/BillingPlansTest.php
@@ -18,7 +18,7 @@ public function it_can_create_a_billing_plan()
{
$expectedResponse = $this->mockCreatePlansResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/plans';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -38,7 +38,7 @@ public function it_can_list_billing_plans()
{
$expectedResponse = $this->mockListPlansResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/plans?product_id=PROD-XXCD1234QWER65782&page_size=2&page=1&total_required=true';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=PROD-XXCD1234QWER65782&page_size=2&page=1&total_required=true';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -57,7 +57,7 @@ public function it_can_update_a_billing_plan()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -77,7 +77,7 @@ public function it_can_show_details_for_a_billing_plan()
{
$expectedResponse = $this->mockGetPlansResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/plans/P-5ML4271244454362WXNWU5NQ';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-5ML4271244454362WXNWU5NQ';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -96,7 +96,7 @@ public function it_can_activate_a_billing_plan()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/activate';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/activate';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -115,7 +115,7 @@ public function it_can_deactivate_a_billing_plan()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/deactivate';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/deactivate';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -134,7 +134,7 @@ public function it_can_update_pricing_for_a_billing_plan()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/plans/P-2UF78835G6983425GLSM44MA/update-pricing-schemes';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-2UF78835G6983425GLSM44MA/update-pricing-schemes';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/CatalogProductsTest.php b/tests/Unit/Client/CatalogProductsTest.php
index b13a5f70..8556750f 100644
--- a/tests/Unit/Client/CatalogProductsTest.php
+++ b/tests/Unit/Client/CatalogProductsTest.php
@@ -18,7 +18,7 @@ public function it_can_create_a_product()
{
$expectedResponse = $this->mockCreateCatalogProductsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/catalogs/products';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/catalogs/products';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -38,7 +38,7 @@ public function it_can_list_products()
{
$expectedResponse = $this->mockListCatalogProductsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/catalogs/products?page=1&page_size=2&total_required=true';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/catalogs/products?page=1&page_size=2&total_required=true';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -57,7 +57,7 @@ public function it_can_update_a_product()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/catalogs/products/72255d4849af8ed6e0df1173';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/catalogs/products/72255d4849af8ed6e0df1173';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -77,7 +77,7 @@ public function it_can_get_details_for_a_product()
{
$expectedResponse = $this->mockGetCatalogProductsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/catalogs/products/72255d4849af8ed6e0df1173';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/catalogs/products/72255d4849af8ed6e0df1173';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/DisputeActionsTest.php b/tests/Unit/Client/DisputeActionsTest.php
index 158fb376..f0645cbb 100644
--- a/tests/Unit/Client/DisputeActionsTest.php
+++ b/tests/Unit/Client/DisputeActionsTest.php
@@ -18,7 +18,7 @@ public function it_can_accept_dispute_claim()
{
$expectedResponse = $this->mockAcceptDisputesClaimResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-27803/accept-claim';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-D-27803/accept-claim';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -38,14 +38,14 @@ public function it_can_accept_dispute_offer_resolution()
{
$expectedResponse = $this->mockAcceptDisputesOfferResolutionResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454/accept-offer';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454/accept-offer';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
'Accept-Language' => 'en_US',
'Authorization' => 'Bearer some-token',
],
- 'json' => $this->acceptDisputeResoltuionParams(),
+ 'json' => $this->acceptDisputeResolutionParams(),
];
$mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
@@ -58,7 +58,7 @@ public function it_can_acknowledge_item_is_returned_for_raised_dispute()
{
$expectedResponse = $this->mockAcknowledgeItemReturnedResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454/acknowledge-return-item';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454/acknowledge-return-item';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/DisputesTest.php b/tests/Unit/Client/DisputesTest.php
index a5f4d0f9..ab36f1e4 100644
--- a/tests/Unit/Client/DisputesTest.php
+++ b/tests/Unit/Client/DisputesTest.php
@@ -18,7 +18,7 @@ public function it_can_list_disputes()
{
$expectedResponse = $this->mockListDisputesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -37,7 +37,7 @@ public function it_can_partially_update_a_dispute()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-27803';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-D-27803';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -57,7 +57,7 @@ public function it_can_get_details_for_a_dispute()
{
$expectedResponse = $this->mockGetDisputesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/customer/disputes/PP-D-4012';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-D-4012';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/IdentityTest.php b/tests/Unit/Client/IdentityTest.php
new file mode 100644
index 00000000..689151c3
--- /dev/null
+++ b/tests/Unit/Client/IdentityTest.php
@@ -0,0 +1,101 @@
+mockShowProfileInfoResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_create_merchant_applications()
+ {
+ $expectedResponse = $this->mockCreateMerchantApplicationResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/identity/applications';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ 'json' => $this->mockCreateMerchantApplicationParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_set_account_properties()
+ {
+ $expectedResponse = '';
+
+ $params = $this->mockSetAccountPropertiesParams();
+ $params['account_property'] = 'BRAINTREE_MERCHANT';
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/identity/account-settings';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ 'json' => $params,
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody()));
+ }
+
+ /** @test */
+ public function it_can_disable_account_properties()
+ {
+ $expectedResponse = '';
+
+ $params = [
+ 'account_property' => 'BRAINTREE_MERCHANT',
+ ];
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/identity/account-settings/deactivate';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ 'json' => $params,
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody()));
+ }
+}
diff --git a/tests/Unit/Client/InvoicesSearchTest.php b/tests/Unit/Client/InvoicesSearchTest.php
index eeb33e7f..09c57973 100644
--- a/tests/Unit/Client/InvoicesSearchTest.php
+++ b/tests/Unit/Client/InvoicesSearchTest.php
@@ -18,7 +18,7 @@ public function it_can_search_invoices()
{
$expectedResponse = $this->mockSearchInvoicesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/search-invoices?page=1&page_size=1&total_required=true';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/search-invoices?page=1&page_size=1&total_required=true';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/InvoicesTemplatesTest.php b/tests/Unit/Client/InvoicesTemplatesTest.php
index fd1c237e..9489c07c 100644
--- a/tests/Unit/Client/InvoicesTemplatesTest.php
+++ b/tests/Unit/Client/InvoicesTemplatesTest.php
@@ -18,7 +18,7 @@ public function it_can_create_invoice_template()
{
$expectedResponse = $this->mockCreateInvoiceTemplateResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/templates';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -38,7 +38,7 @@ public function it_can_list_invoice_templates()
{
$expectedResponse = $this->mockListInvoiceTemplateResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/templates';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -57,7 +57,7 @@ public function it_can_delete_an_invoice_template()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -76,7 +76,7 @@ public function it_can_update_an_invoice_template()
{
$expectedResponse = $this->mockUpdateInvoiceTemplateResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -96,7 +96,7 @@ public function it_can_get_details_for_an_invoice_template()
{
$expectedResponse = $this->mockGetInvoiceTemplateResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/InvoicesTest.php b/tests/Unit/Client/InvoicesTest.php
index 9ac445b1..dd1fa817 100644
--- a/tests/Unit/Client/InvoicesTest.php
+++ b/tests/Unit/Client/InvoicesTest.php
@@ -18,7 +18,7 @@ public function it_can_generate_unique_invoice_number()
{
$expectedResponse = $this->mockGenerateInvoiceNumberResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/generate-next-invoice-number';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/generate-next-invoice-number';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -37,7 +37,7 @@ public function it_can_create_a_draft_invoice()
{
$expectedResponse = $this->mockCreateInvoicesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -57,7 +57,7 @@ public function it_can_list_current_invoices()
{
$expectedResponse = $this->mockListInvoicesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices?total_required=true';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -76,7 +76,7 @@ public function it_can_delete_an_invoice()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -95,7 +95,7 @@ public function it_can_update_an_invoice()
{
$expectedResponse = $this->mockUpdateInvoicesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -115,7 +115,7 @@ public function it_can_show_details_for_an_invoice()
{
$expectedResponse = $this->mockGetInvoicesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -134,7 +134,7 @@ public function it_can_cancel_an_invoice()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/cancel';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/cancel';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -154,7 +154,7 @@ public function it_can_generate_qr_code_for_invoice()
{
$expectedResponse = $this->mockGenerateInvoiceNumberResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/generate-qr-code';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/generate-qr-code';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -174,7 +174,7 @@ public function it_can_register_payment_for_invoice()
{
$expectedResponse = $this->mockInvoiceRegisterPaymentResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/payments';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/payments';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -194,7 +194,7 @@ public function it_can_delete_payment_for_invoice()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/payments/EXTR-86F38350LX4353815';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/payments/EXTR-86F38350LX4353815';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -213,7 +213,7 @@ public function it_can_refund_payment_for_invoice()
{
$expectedResponse = $this->mockInvoiceRefundPaymentResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/refunds';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/refunds';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -233,7 +233,7 @@ public function it_can_delete_refund_for_invoice()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-333R-YUQL-YNNN-D7WF/refunds/EXTR-2LG703375E477444T';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-333R-YUQL-YNNN-D7WF/refunds/EXTR-2LG703375E477444T';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -252,7 +252,7 @@ public function it_can_send_an_invoice()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-EHNV-LJ5S-A7DZ-V6NJ/send';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-EHNV-LJ5S-A7DZ-V6NJ/send';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -272,7 +272,7 @@ public function it_can_send_reminder_for_an_invoice()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/remind';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/remind';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/OrdersTest.php b/tests/Unit/Client/OrdersTest.php
index 6014e75c..79294710 100644
--- a/tests/Unit/Client/OrdersTest.php
+++ b/tests/Unit/Client/OrdersTest.php
@@ -18,7 +18,7 @@ public function it_can_create_an_order()
{
$expectedResponse = $this->mockCreateOrdersResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/checkout/orders';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/checkout/orders';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/PartnerReferralsTest.php b/tests/Unit/Client/PartnerReferralsTest.php
new file mode 100644
index 00000000..5876962f
--- /dev/null
+++ b/tests/Unit/Client/PartnerReferralsTest.php
@@ -0,0 +1,54 @@
+mockCreatePartnerReferralsResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/customer/partner-referrals';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ 'json' => $this->mockCreatePartnerReferralParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_get_referral_details()
+ {
+ $expectedResponse = $this->mockShowReferralDataResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/customer/partner-referrals/ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0=';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+}
diff --git a/tests/Unit/Client/PaymentAuthorizationsTest.php b/tests/Unit/Client/PaymentAuthorizationsTest.php
index c33cebfa..02b438f8 100644
--- a/tests/Unit/Client/PaymentAuthorizationsTest.php
+++ b/tests/Unit/Client/PaymentAuthorizationsTest.php
@@ -18,7 +18,7 @@ public function it_can_show_details_for_an_authorized_payment()
{
$expectedResponse = $this->mockGetAuthorizedPaymentDetailsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -37,7 +37,7 @@ public function it_can_capture_an_authorized_payment()
{
$expectedResponse = $this->mockCaptureAuthorizedPaymentResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/capture';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/capture';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -57,7 +57,7 @@ public function it_can_reauthorize_an_authorized_payment()
{
$expectedResponse = $this->mockReAuthorizeAuthorizedPaymentResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/reauthorize';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/reauthorize';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -77,7 +77,7 @@ public function it_can_void_an_authorized_payment()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/void';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/void';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/PaymentCapturesTest.php b/tests/Unit/Client/PaymentCapturesTest.php
index 7844939a..d9a50719 100644
--- a/tests/Unit/Client/PaymentCapturesTest.php
+++ b/tests/Unit/Client/PaymentCapturesTest.php
@@ -18,7 +18,7 @@ public function it_can_show_details_for_a_captured_payment()
{
$expectedResponse = $this->mockGetCapturedPaymentDetailsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/payments/captures/2GG279541U471931P';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/captures/2GG279541U471931P';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -37,7 +37,7 @@ public function it_can_refund_a_captured_payment()
{
$expectedResponse = $this->mockRefundCapturedPaymentResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/payments/captures/2GG279541U471931P/refund';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/captures/2GG279541U471931P/refund';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/PaymentExperienceWebProfilesTest.php b/tests/Unit/Client/PaymentExperienceWebProfilesTest.php
new file mode 100644
index 00000000..c0ab808d
--- /dev/null
+++ b/tests/Unit/Client/PaymentExperienceWebProfilesTest.php
@@ -0,0 +1,133 @@
+mockListWebProfilesResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_create_web_experience_profile()
+ {
+ $expectedResponse = $this->mockWebProfileResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ 'PayPal-Request-Id' => 'some-request-id',
+ ],
+ 'json' => $this->mockCreateWebProfileParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_delete_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_partially_update_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ 'json' => $this->partiallyUpdateWebProfileParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_fully_update_web_experience_profile()
+ {
+ $expectedResponse = '';
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ 'json' => $this->updateWebProfileParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_get_web_experience_profile_details()
+ {
+ $expectedResponse = $this->mockWebProfileResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+}
diff --git a/tests/Unit/Client/PaymentRefundsTest.php b/tests/Unit/Client/PaymentRefundsTest.php
index 81fc05b1..39a9ae41 100644
--- a/tests/Unit/Client/PaymentRefundsTest.php
+++ b/tests/Unit/Client/PaymentRefundsTest.php
@@ -16,7 +16,7 @@ public function it_can_show_details_for_a_refund()
{
$expectedResponse = $this->mockGetRefundDetailsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v2/payments/refunds/1JU08902781691411';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/refunds/1JU08902781691411';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/PayoutsTest.php b/tests/Unit/Client/PayoutsTest.php
new file mode 100644
index 00000000..634ddffc
--- /dev/null
+++ b/tests/Unit/Client/PayoutsTest.php
@@ -0,0 +1,92 @@
+mockCreateBatchPayoutResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/payouts';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ 'json' => $this->mockCreateBatchPayoutParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_show_batch_payout_details()
+ {
+ $expectedResponse = $this->showBatchPayoutResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/payouts/FYXMPQTX4JC9N';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_show_batch_payout_item_details()
+ {
+ $expectedResponse = $this->showBatchPayoutItemResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/payouts-item/8AELMXH8UB2P8';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_cancel_unclaimed_batch_payout_item()
+ {
+ $expectedResponse = $this->mockCancelUnclaimedBatchItemResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/payouts-item/8AELMXH8UB2P8/cancel';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+}
diff --git a/tests/Unit/Client/ReferencedPayoutsTest.php b/tests/Unit/Client/ReferencedPayoutsTest.php
new file mode 100644
index 00000000..750d0f0b
--- /dev/null
+++ b/tests/Unit/Client/ReferencedPayoutsTest.php
@@ -0,0 +1,100 @@
+mockCreateReferencedBatchPayoutResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ 'PayPal-Request-Id' => 'some-request-id',
+ 'PayPal-Partner-Attribution-Id' => 'some-attribution-id',
+ ],
+ 'json' => $this->mockCreateReferencedBatchPayoutParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_list_items_referenced_in_batch_payout()
+ {
+ $expectedResponse = $this->mockShowReferencedBatchPayoutResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts/KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E=';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ ],
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_create_referenced_batch_payout_item()
+ {
+ $expectedResponse = $this->mockCreateReferencedBatchPayoutItemResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts-items';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ 'PayPal-Request-Id' => 'some-request-id',
+ 'PayPal-Partner-Attribution-Id' => 'some-attribution-id',
+ ],
+ 'json' => $this->mockCreateReferencedBatchPayoutItemParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+
+ /** @test */
+ public function it_can_show_referenced_payout_item_details()
+ {
+ $expectedResponse = $this->mockShowReferencedBatchPayoutItemResponse();
+
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts-items/CDZEC5MJ8R5HY';
+ $expectedParams = [
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Accept-Language' => 'en_US',
+ 'Authorization' => 'Bearer some-token',
+ 'PayPal-Request-Id' => 'some-request-id',
+ 'PayPal-Partner-Attribution-Id' => 'some-attribution-id',
+ ],
+ 'json' => $this->mockCreateReferencedBatchPayoutItemParams(),
+ ];
+
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+
+ $this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
+ }
+}
diff --git a/tests/Unit/Client/ReportingTest.php b/tests/Unit/Client/ReportingTest.php
index f76152f0..34468d06 100644
--- a/tests/Unit/Client/ReportingTest.php
+++ b/tests/Unit/Client/ReportingTest.php
@@ -18,7 +18,7 @@ public function it_can_list_transactions()
{
$expectedResponse = $this->mockListTransactionsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/reporting/transactions?start_date=2014-07-01T00:00:00-0700&end_date=2014-07-30T23:59:59-0700&transaction_id=5TY05013RG002845M&fields=all&page_size=100&page=1';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/reporting/transactions?start_date=2014-07-01T00:00:00-0700&end_date=2014-07-30T23:59:59-0700&transaction_id=5TY05013RG002845M&fields=all&page_size=100&page=1';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -37,7 +37,7 @@ public function it_can_list_balances()
{
$expectedResponse = $this->mockListBalancesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/reporting/balances?currency_code=USD&as_of_time=2016-10-15T06:07:00-0700';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/reporting/balances?currency_code=USD&as_of_time=2016-10-15T06:07:00-0700';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/SubscriptionsTest.php b/tests/Unit/Client/SubscriptionsTest.php
index f18dc5be..bd808f3b 100644
--- a/tests/Unit/Client/SubscriptionsTest.php
+++ b/tests/Unit/Client/SubscriptionsTest.php
@@ -18,7 +18,7 @@ public function it_can_create_a_subscription()
{
$expectedResponse = $this->mockCreateSubscriptionResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -38,7 +38,7 @@ public function it_can_update_a_subscription()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -58,7 +58,7 @@ public function it_can_show_details_for_a_subscription()
{
$expectedResponse = $this->mockGetSubscriptionDetailsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -77,7 +77,7 @@ public function it_can_activate_a_subscription()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/activate';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/activate';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -97,7 +97,7 @@ public function it_can_cancel_a_subscription()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/cancel';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/cancel';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -117,7 +117,7 @@ public function it_can_suspend_a_subscription()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/suspend';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/suspend';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -137,7 +137,7 @@ public function it_can_capture_payment_for_a_subscription()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/capture';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/capture';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -157,7 +157,7 @@ public function it_can_update_quantity_or_product_for_a_subscription()
{
$expectedResponse = $this->mockUpdateSubscriptionItemsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/revise';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/revise';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -177,7 +177,7 @@ public function it_can_list_transactions_for_a_subscription()
{
$expectedResponse = $this->mockListSubscriptionTransactionsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/transactions?start_time=2018-01-21T07:50:20.940Z&end_time=2018-08-21T07:50:20.940Z';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/transactions?start_time=2018-01-21T07:50:20.940Z&end_time=2018-08-21T07:50:20.940Z';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/TrackersTest.php b/tests/Unit/Client/TrackersTest.php
index ac096f91..f08881c4 100644
--- a/tests/Unit/Client/TrackersTest.php
+++ b/tests/Unit/Client/TrackersTest.php
@@ -18,7 +18,7 @@ public function it_can_get_tracking_details_for_tracking_id()
{
$expectedResponse = $this->mockGetTrackingDetailsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/shipping/trackers/8MC585209K746392H-443844607820';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/shipping/trackers/8MC585209K746392H-443844607820';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -27,7 +27,7 @@ public function it_can_get_tracking_details_for_tracking_id()
],
];
- $mockHttpClient = $this->mock_http_request(json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
$this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
}
@@ -37,7 +37,7 @@ public function it_can_update_tracking_details_for_tracking_id()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/shipping/trackers/8MC585209K746392H-443844607820';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/shipping/trackers/8MC585209K746392H-443844607820';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -47,7 +47,7 @@ public function it_can_update_tracking_details_for_tracking_id()
'json' => $this->mockUpdateTrackingDetailsParams(),
];
- $mockHttpClient = $this->mock_http_request(json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'put');
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'put');
$this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->put($expectedEndpoint, $expectedParams)->getBody(), true));
}
@@ -57,7 +57,7 @@ public function it_can_create_tracking_in_batches()
{
$expectedResponse = $this->mockCreateTrackinginBatchesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/shipping/trackers-batch';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/shipping/trackers-batch';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -67,7 +67,7 @@ public function it_can_create_tracking_in_batches()
'json' => $this->mockCreateTrackinginBatchesParams(),
];
- $mockHttpClient = $this->mock_http_request(json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
$this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
}
diff --git a/tests/Unit/Client/WebHooksEventsTest.php b/tests/Unit/Client/WebHooksEventsTest.php
index 4c8a41ea..06444973 100644
--- a/tests/Unit/Client/WebHooksEventsTest.php
+++ b/tests/Unit/Client/WebHooksEventsTest.php
@@ -18,7 +18,7 @@ public function it_can_list_web_hooks_event_types()
{
$expectedResponse = $this->mockListWebHookEventsTypesResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks-event-types';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-event-types';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -37,7 +37,7 @@ public function it_can_list_web_hooks_events()
{
$expectedResponse = $this->mockWebHookEventsListResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -56,7 +56,7 @@ public function it_can_show_details_for_a_web_hooks_event()
{
$expectedResponse = $this->mockGetWebHookEventResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/8PT597110X687430LKGECATA';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events/8PT597110X687430LKGECATA';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -75,7 +75,7 @@ public function it_can_resend_notification_for_a_web_hooks_event()
{
$expectedResponse = $this->mockResendWebHookEventNotificationResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events/8PT597110X687430LKGECATA/resend';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events/8PT597110X687430LKGECATA/resend';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/WebHooksTest.php b/tests/Unit/Client/WebHooksTest.php
index b5a39c9a..8f10fa02 100644
--- a/tests/Unit/Client/WebHooksTest.php
+++ b/tests/Unit/Client/WebHooksTest.php
@@ -18,7 +18,7 @@ public function it_can_create_a_web_hook()
{
$expectedResponse = $this->mockCreateWebHookResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -38,7 +38,7 @@ public function it_can_list_web_hooks()
{
$expectedResponse = $this->mockListWebHookResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -57,7 +57,7 @@ public function it_can_delete_a_web_hook()
{
$expectedResponse = '';
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks/5GP028458E2496506';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/5GP028458E2496506';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -76,7 +76,7 @@ public function it_can_update_a_web_hook()
{
$expectedResponse = $this->mockUpdateWebHookResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -96,7 +96,7 @@ public function it_can_show_details_for_a_web_hook()
{
$expectedResponse = $this->mockGetWebHookResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -115,7 +115,7 @@ public function it_can_list_web_hooks_events()
{
$expectedResponse = $this->mockListWebHookEventsResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/Client/WebHooksVerificationTest.php b/tests/Unit/Client/WebHooksVerificationTest.php
index 30c11c16..f8110f9b 100644
--- a/tests/Unit/Client/WebHooksVerificationTest.php
+++ b/tests/Unit/Client/WebHooksVerificationTest.php
@@ -18,7 +18,7 @@ public function it_can_verify_web_hook_signature()
{
$expectedResponse = $this->mockVerifyWebHookSignatureResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/notifications/webhooks-event-types';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-event-types';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php
index fed115d8..4c1cb82b 100644
--- a/tests/Unit/ClientTest.php
+++ b/tests/Unit/ClientTest.php
@@ -24,7 +24,7 @@ public function it_can_get_access_token()
{
$expectedResponse = $this->mockAccessTokenResponse();
- $expectedEndpoint = 'https://api.sandbox.paypal.com/v1/oauth2/token?grant_type=client_credentials';
+ $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/oauth2/token?grant_type=client_credentials';
$expectedParams = [
'headers' => [
'Accept' => 'application/json',
@@ -33,7 +33,7 @@ public function it_can_get_access_token()
'auth' => ['username', 'password'],
];
- $mockHttpClient = $this->mock_http_request(json_encode($expectedResponse), $expectedEndpoint, $expectedParams);
+ $mockHttpClient = $this->mock_http_request(\GuzzleHttp\json_encode($expectedResponse), $expectedEndpoint, $expectedParams);
$this->assertEquals($expectedResponse, \GuzzleHttp\json_decode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
}