itemvirtual/ecommerce-paypal

PayPal's payments with Laravel

1.0.1 2023-11-15 10:06 UTC

This package is auto-updated.

Last update: 2024-11-15 12:16:00 UTC


README

PayPal's payments with Laravel

Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require itemvirtual/ecommerce-paypal

Publish config (with --force option to update)

php artisan vendor:publish --provider="Itemvirtual\EcommercePaypal\EcommercePaypalServiceProvider" --tag=config

Add this environment variable to your .env

ECOMMERCE_PAYPAL_MODE=sandbox  # sandbox or live
ECOMMERCE_PAYPAL_CLIENT_ID=""
ECOMMERCE_PAYPAL_CLIENT_SECRET=""
ECOMMERCE_PAYPAL_RETURN_URL="${APP_URL}/<paypal-ok-url>"
ECOMMERCE_PAYPAL_CANCEL_URL="${APP_URL}/<paypal-cancel-url>"

Usage

Create a PayPal order
After creating the order, get the approval link for the user to make the payment

use Itemvirtual\EcommercePaypal\Services\PaypalCheckout;

$EcommercePaypal = new PaypalCheckout();
$EcommercePaypalApprovalLink = null;
        
$EcommercePaypalOrder = $EcommercePaypal->setTotal(<TotalAmountToPay>)->createOrder();

if ($EcommercePaypalOrder) {
    $EcommercePaypalApprovalLink = $EcommercePaypal->getApprovalLink($EcommercePaypalOrder);
    $EcommercePaypalOrderId = $EcommercePaypal->getOrderId($EcommercePaypalOrder);
}

After the user has made the payment in PayPal, capture order and get payment details

use Itemvirtual\EcommercePaypal\Services\PaypalCheckout;

$paypalOrderId = $request->get('token', null);

$EcommercePaypal = new PaypalCheckout();
$EcommercePaypalResponse = $EcommercePaypal->captureOrder($paypalOrderId);
$isOrderSuccessful = $EcommercePaypal->isOrderSuccessful($EcommercePaypalResponse);

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.