pleets / laravel-paypal
Paypal Integrations
Installs: 1 235
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.4|^8.0
- ext-json: *
- laravel/framework: ^7.0|^8.0
- payment-gateways/paypal-sdk: ^1.2
Requires (Dev)
- orchestra/testbench: ^6.7
- phpunit/phpunit: ^9.4
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-10-12 09:35:54 UTC
README
Laravel integrator for PayPal solutions. Actually this library supports the following solutions:
1. Requirements
You need to make sure your server meets the following requirements.
- PHP >= 7.4, PHP >= 8.0
- Laravel 7.x, 8.x
2. Installation
Use following command to install this library:
composer require pleets/laravel-paypal
Add the service provider to your providers[]
array in config/app.php
file like:
\Pleets\LaravelPayPal\LaravelPaypalProvider::class
Finally, publish the vendor files.
php artisan vendor:publish --tag="laravel-paypal"
3. Usage
3.1 Live and Sandbox environments
Set up first API credentials for sandbox with the following env vars.
PAYPAL_SANDBOX_CLIENT_ID= PAYPAL_SANDBOX_SECRET=
For live environment set up the following.
PAYPAL_LIVE_CLIENT_ID= PAYPAL_LIVE_SECRET=
You can choose your current environment with the following.
PAYPAL_ENVIRONMENT=sandbox
The only valid values for this are sandbox
and live
.
3.2 Checkout
Activate paypal checkout with the following env var.
PAYPAL_CHECKOUT_ACTIVATED=true
Add the PayPal SDK to your blade templates as follows
@include('laravel-paypal::checkout.sdk')
💡 You don't have to be worried about when to include this SDK. The component checks for PAYPAL_CHECKOUT_ACTIVATED
and then include the JavaScript SDK in case the value were true.
Then you can add the Smart Payment Button like this
@include('laravel-paypal::checkout.button')
⚠️ Finally, after the code of this button add the javascript code to handle it. This JS file is not intended to be used for production. It is just an example about how to handle the PayPal button.
<script src="{{ asset('js/paypal/checkout.js') }}" defer></script>
The checkout.js
file contains values related to the purchase amount and purchase behaviour.
For other values you can check the official documentation.
3.3 Subscriptions
Activate paypal subscriptions with the following en var.
PAYPAL_SUBSCRIPTION_ACTIVATED=true
You can interact with subscriptions Api through this PayPal SDK. Add the service provider
to your providers[]
array in config/app.php
file like:
Pleets\LaravelPayPal\Providers\PayPalServiceProvider::class
Add the PayPal SDK to your blade templates as follows
@include('laravel-paypal::subscriptions.sdk')
💡 You don't have to be worried about when to include this SDK. The component checks for PAYPAL_SUBSCRIPTION_ACTIVATED
and then include the JavaScript SDK in case the value were true.
Then you can add the Smart Payment Button like this
@include('laravel-paypal::subscriptions.button')
⚠️ Finally, after the code of this button add the javascript code to handle it. This JS file is not intended to be used for production. It is just an example about how to handle the PayPal button.
<script src="{{ asset('js/paypal/subscriptions.js') }}" defer></script>
The subscriptions.js
file contains values related to creating subscriptions and purchase behaviour.
For other values you can check the official documentation.
4. Mocking
If you want to mock the PayPal Service for testing purposes, you need to overwrite the paypal testing configuration.
You must create a testing.php
file inside config/paypal
folder and set up a specific handler like this.
'handler' => [ 'class' => PaymentGateway\PayPalApiMock\PayPalApiMock::class, ]
Feel free to use your own paypal mock, or you can use this PayPal Api Mock.
Finally, you should set up the following in your testing environment.
PAYPAL_HANDLER_ENABLED=true