Skip to content

Commit

Permalink
Merge v3 into v2 (#481)
Browse files Browse the repository at this point in the history
* Add more tests.

* Update build config & refactor tests for v3.

* Add functional tests for Reporting API.

* Refactor & updated README.

* Support PHP 8.

* Add PHP 8.0 to build

* Url error, remove / (#398)

* Refactor tests for PHP 8.0

* Update package for code coverage

* Update README.md

* Update README.md

* Update README.md

* Order api implementation and README (#413)

Additional order API methods

Co-authored-by: Ron Heywood <[email protected]>

* Apply fixes from StyleCI (#415)

Co-authored-by: Raza Mehdi <[email protected]>

* Add CNY currency code (#419)

* Fix sample code for create order (#421)

* Fix: Scrutinizer-CI Issue for PayPalHttpClient.php (#431)

https://scrutinizer-ci.com/g/srmklive/laravel-paypal/issues/v2.0/files/src/Traits/PayPalHttpClient.php?orderField=path&order=asc&honorSelectedPaths=0

* Update Subscriptions capture parameter (#426)

* Typo fixed (#427)

* Add documentation link

* Refactor & fix listPlans API call.

* Update date format for listSubscriptionTransactions

* Added support for setting a request header. (#446)

* Fix CI issues

* Adjust QR code size

* Refactor invoices search by adding custom filters.

* CI fixes and add remaining filter methods for coverage.

* Add missing fields filter for search invoices.

* Add missing data types.

* Update config.

* Update function data types and error response.

* Update README.md

* Implement Identity API.

* Update API endpoints & Implement Partner Referral API.

* Update initialization flow (fixes #467).

* Add configuration checks for API.

* Fix CI.

* Refactoring.

* Apply fixes from StyleCI (#472)

* Implement Payment Experience Web Profiles API.

* Implement Payouts API.

* Implement Referenced Payouts API.

* Move API endpoint setup to request call.

* Refactor setCurlConstants method.

* Add defineCurlConstant method.

* Temporarily remove PHP 8.0 from CI.

* Remove redundant function call.

* Convert boolean to string to fix INVALID_PARAMETER_VALUE for listPlans (#475)

* Remove unnecessary header params.

* Add custom methods to create recurring monthly/annual subscriptions. (#477)

* Add custom method to create recurring weekly subscriptions. (#478)

* Add custom method to create recurring daily subscriptions. (#479)

* Fix conflicts.

* Fix return types and imports.

* Fix build.

Co-authored-by: vendaagil <[email protected]>
Co-authored-by: ronheywood <[email protected]>
Co-authored-by: Ron Heywood <[email protected]>
Co-authored-by: Raza Mehdi <[email protected]>
Co-authored-by: Zelin Ning <[email protected]>
Co-authored-by: Raja-Omer-Mustafa <[email protected]>
Co-authored-by: Sean <[email protected]>
Co-authored-by: Andrei Ristea <[email protected]>
Co-authored-by: Dasun Tharanga <[email protected]>
Co-authored-by: Jesse Tolj <[email protected]>
Co-authored-by: Tom Shaw <[email protected]>
Co-authored-by: Jesse Tolj <[email protected]>
  • Loading branch information
13 people authored Dec 5, 2021
1 parent f438a91 commit d79b43a
Show file tree
Hide file tree
Showing 86 changed files with 4,816 additions and 327 deletions.
84 changes: 42 additions & 42 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build:
- php-scrutinizer-run
environment:
php:
version: '7.1.33'
version: '7.3.21'
tests:
override:
-
Expand Down
94 changes: 70 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

<a name="usage"></a>
## Usage
Expand All @@ -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();
```

<a name="usage-paypal-api-configuration"></a>
## 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:
Expand All @@ -58,40 +84,60 @@ $provider->getAccessToken();
<a name="usage-currency"></a>
## 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', '[email protected]', '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', '[email protected]', '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', '[email protected]', '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', '[email protected]', '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', '[email protected]', $start_date);
```

<a name="support"></a>
## 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.
Expand Down
2 changes: 1 addition & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
33 changes: 33 additions & 0 deletions phpunit.xml.dist.php72
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="PayPal Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
<exclude>
<file>src/PayPalFacadeAccessor.php</file>
<directory suffix=".php">src/Facades/</directory>
<directory suffix=".php">src/Providers/</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
16 changes: 6 additions & 10 deletions src/Services/PayPal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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';
Expand Down
17 changes: 11 additions & 6 deletions src/Traits/PayPalAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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] = [
Expand All @@ -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);

Expand All @@ -60,7 +67,7 @@ public function getAccessToken()
*
* @return void
*/
public function setAccessToken($response)
public function setAccessToken(array $response)
{
$this->access_token = $response['access_token'];

Expand All @@ -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'];
}
}
Loading

0 comments on commit d79b43a

Please sign in to comment.