Skip to content

Commit

Permalink
Merge branch 'v3.0' into v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Sep 30, 2023
2 parents d79b43a + 9f0768d commit 27e8f80
Show file tree
Hide file tree
Showing 132 changed files with 4,095 additions and 1,129 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pdf filter=lfs diff=lfs merge=lfs -text
35 changes: 35 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Static Analysis
on: [push, pull_request]
jobs:
paypal:
name: PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
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" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;)
- name: Run type checking analysis
env:
PHP_VERSION: ${{ matrix.php-versions }}
run: vendor/bin/phpstan
82 changes: 43 additions & 39 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: TestsV2
name: Laravel PayPal V2
on: [push, pull_request]
jobs:
paypal:
Expand All @@ -7,45 +7,49 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['5.6', '7.0', '7.1']
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
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
- 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
with:
lfs: true
- name: Checkout LFS objects
run: git lfs checkout
- 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" || "$PHP_VERSION" == "8.1" ]; 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
coveralls-finish:
needs: [paypal]
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
.env
composer.lock
/build
*docker*
*-container*
*.phpunit*
test.php
/.venv
/docs/build
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM srmklive/docker-php-cli:7.2

LABEL maintainer="Raza Mehdi<[email protected]>"

ENV DEBIAN_FRONTEND=noninteractive

# Set apps home directory.
ENV APP_DIR /server/http

# Define current working directory.
WORKDIR ${APP_DIR}

RUN apt-get -y autoclean \
&& apt-get -y autoremove \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY supervisor.conf /etc/supervisor/conf.d/supervisord.conf

CMD ["/usr/bin/supervisord"]
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ return [
You can override PayPal API configuration by calling `setApiCredentials` method:

```php
$config = [
'mode' => 'live',
'live' => [
'client_id' => 'PAYPAL_LIVE_CLIENT_ID',
'client_secret' => 'PAYPAL_LIVE_CLIENT_SECRET',
'app_id' => 'PAYPAL_LIVE_APP_ID',
],

'payment_action' => 'Sale',
'currency' => 'USD',
'notify_url' => 'https://your-site.com/paypal/notify',
'locale' => 'en_US',
'validate_ssl' => true,
];
$provider->setApiCredentials($config);
```

Expand Down Expand Up @@ -128,9 +142,68 @@ $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SO

## Create Subscription by Existing Product & Billing Plan

<a name="usage-helpers"></a>
## Helper Methods

> Please note that in the examples below, the call to `addPlanTrialPricing` is optional and it can be omitted when you are creating subscriptions without trial period.
> `setReturnAndCancelUrl()` is optional. If you set urls you have to use real domains. e.g. localhost, project.test does not work.
### Create Recurring Daily Subscription

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

### Create Recurring Weekly Subscription

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

### Create Recurring Monthly Subscription

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

### Create Recurring Annual Subscription

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

### Create Recurring Subscription with Custom Intervals

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

### Create Subscription by Existing Product & Billing Plan

```php
$response = $this->client->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', '[email protected]', $start_date);
```

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"nesbot/carbon": "~1.0|~2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7|^6.0|^7.0",
"phpunit/phpunit": "^5.7|^6.0|^7.0|^8.0",
"symfony/var-dumper": "~3.0|~4.0|~5.0"
},
"config": {
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '2'
services:
app:
build:
context: ./
dockerfile: Dockerfile
image: srmklive/laravel-paypal
restart: always
volumes:
- ./:/server/http
9 changes: 9 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
paths:
- src
level: 0
ignoreErrors:
- "#Parameter#"
- "#Call to static method error\\(\\)\\ on an unknown class Log.#"
excludePaths:
- "src/Providers/PayPalServiceProvider.php"
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<directory suffix=".php">src/</directory>
<exclude>
<file>src/PayPalFacadeAccessor.php</file>
<file>src/Traits/PayPalVerifyIPN.php</file>
<file>src/Services/Str.php</file>
<directory suffix=".php">src/Facades/</directory>
<directory suffix=".php">src/Providers/</directory>
</exclude>
Expand Down
33 changes: 0 additions & 33 deletions phpunit.xml.dist.php72

This file was deleted.

8 changes: 4 additions & 4 deletions src/Services/PayPal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Exception;
use Srmklive\PayPal\Traits\PayPalRequest as PayPalAPIRequest;
use Srmklive\PayPal\Traits\PayPalVerifyIPN;

class PayPal
{
use PayPalAPIRequest;
use PayPalVerifyIPN;

/**
* PayPal constructor.
Expand All @@ -24,10 +26,8 @@ public function __construct(array $config = [])
$this->httpBodyParam = 'form_params';

$this->options = [];
$this->options['headers'] = [
'Accept' => 'application/json',
'Accept-Language' => $this->locale,
];

$this->setRequestHeader('Accept', 'application/json');
}

/**
Expand Down
34 changes: 34 additions & 0 deletions src/Services/Str.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Srmklive\PayPal\Services;

use GuzzleHttp\Utils;

class Str extends \Illuminate\Support\Str
{
/**
* Determine if a given value is valid JSON.
*
* @param mixed $value
*
* @return bool
*/
public static function isJson($value): bool
{
if (!is_string($value)) {
return false;
}

if (function_exists('json_validate')) {
return json_validate($value, 512);
}

try {
Utils::jsonDecode($value, true, 512, 4194304);
} catch (\JsonException $jsonException) {
return false;
}

return true;
}
}
Loading

0 comments on commit 27e8f80

Please sign in to comment.