srmklive / paypal
Laravel plugin For Processing Payments Through Paypal Express Checkout. Can Be Used Independently With Other Applications.
Installs: 2 354 267
Dependents: 35
Suggesters: 0
Security: 0
Stars: 1 053
Watchers: 31
Forks: 317
Open Issues: 4
Requires
- php: >=7.2|^8.0
- ext-curl: *
- guzzlehttp/guzzle: ~7.0
- illuminate/support: ~6.0|~7.0|~8.0|~9.0|^10.0|^11.0
- nesbot/carbon: ~2.0|^3.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^8.0|^9.0|^10.0|^11.0
- symfony/var-dumper: ~5.0|^6.0|^7.0
- dev-master
- v4.0.x-dev
- v3.0.x-dev
- 3.0.32
- 3.0.31
- 3.0.30
- 3.0.28
- 3.0.27
- 3.0.26
- 3.0.25
- 3.0.24
- 3.0.23
- 3.0.22
- 3.0.21
- 3.0.20
- 3.0.19
- 3.0.18
- 3.0.17
- 3.0.16
- 3.0.15
- 3.0.14
- 3.0.13
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- v3.0
- v2.0.x-dev
- 2.0.30
- 2.0.20
- 2.0.10
- 2.0.2
- 2.0.1
- v2.0.0
- 2.0.0-beta-3
- v2.0.0-beta-2
- v2.0.0-beta-1
- 1.11.11
- 1.11.10
- 1.11.0
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.11
- 1.6.10
- 1.6.9
- 1.6.8
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.9
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.0
- v1.0.x-dev
- 1.0.3
- 1.0.2
- 1.0.1
- 0.2.2
- 0.2.1
- v0.2
This package is auto-updated.
Last update: 2024-11-11 07:20:18 UTC
README
Important
Laravel 11 will be the last version supported for v3.0. v4 is being actively worked on, and will be released by end of October 2024. For v4, following are the changes being introduced:
- PHP 8.1+ required.
- Laravel 10 & onwards required.
- Integration of PayPal JS SDK.
- Symfony plugin.
Documentation
The documentation for the package can be viewed by clicking the following link:
https://laravel-paypal.readthedocs.io/en/latest/
The old documentation can be found at the following link:
https://srmklive.github.io/laravel-paypal/docs.html
Usage
Following are some ways through which you can access the paypal provider:
// Import the class namespaces first, before using it directly use Srmklive\PayPal\Services\PayPal as PayPalClient; $provider = new PayPalClient; // Through facade. No need to import namespaces $provider = \PayPal::setProvider();
Configuration File
The configuration file paypal.php is located in the config folder. Following are its contents when published:
return [ 'mode' => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used. 'sandbox' => [ 'client_id' => env('PAYPAL_SANDBOX_CLIENT_ID', ''), 'client_secret' => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''), 'app_id' => 'APP-80W284485P519543T', ], 'live' => [ 'client_id' => env('PAYPAL_LIVE_CLIENT_ID', ''), 'client_secret' => env('PAYPAL_LIVE_CLIENT_SECRET', ''), 'app_id' => 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:
$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);
Get Access Token
After setting the PayPal API configuration by calling setApiCredentials
method. You need to get access token before performing any API calls
$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:
$provider->setCurrency('EUR');
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
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addPlanTrialPricing('DAY', 7) ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
Create Recurring Weekly Subscription
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addPlanTrialPricing('DAY', 7) ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
Create Recurring Monthly Subscription
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addPlanTrialPricing('DAY', 7) ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
Create Recurring Annual Subscription
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addPlanTrialPricing('DAY', 7) ->addAnnualPlan('Demo Plan', 'Demo Plan', 600) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
Create Recurring Subscription with Custom Intervals
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addCustomPlan('Demo Plan', 'Demo Plan', 150, 'MONTH', 3) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10');
Create Subscription by Existing Product & Billing Plan
$response = $this->client->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', $start_date);
Support
This version supports Laravel 6 or greater.
- In case of any issues, kindly create one on the Issues section.
- If you would like to contribute:
- Fork this repository.
- Implement your features.
- Generate pull request.