PHP code example of obydul / larapal

1. Go to this page and download the library: Download obydul/larapal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

obydul / larapal example snippets


Obydul\LaraPal\LarapalServiceProvider::class

// Import the class namespaces first, before using it directly
use Obydul\LaraPal\Services\ExpressCheckout;

// Create object instance
$paypal = new ExpressCheckout();

// Redirect user to PayPal to obtain charging permissions
$paypal->doExpressCheckout(123.45, 'LaraPal Test Checkout', 'invoice_id', 'USD'); // single payment
$paypal->doExpressMultipleCheckout($items, 'invoice_id', 'USD', false, $customFields); // multiple items

// Perform payment, token and PayerID are being returned with GET response from PayPal
$paypal->doSinglePayment($_GET['token'], $_GET['PayerID']; // single payment
$paypal->doMultiplePayment($_GET['token'], $_GET['PayerID']; // multiple payment

// Perform refund based on transaction ID
$paypal->doRefund($transactionId, 'invoice_id', false, 0, 'USD', ''); // full refund
$paypal->doRefund($transactionId, 'invoice_id', true, 5.15, 'USD', ''); // partial refund

// Get transaction details 
$details = $paypal->getTransactionDetails($transactionId);

// Structure - invoice ID must be unique
doExpressCheckout(AMOUNT, 'DESCRIPTION', 'INVOICE', 'CURRENCY', SHIPPING, CUSTOMFIELDS);
doExpressMultipleCheckout(ITEMS, 'INVOICE', 'CURRENCY', SHIPPING, CUSTOMFIELDS);

// Normal call
doExpressCheckout(123.45, 'LaraPal Test Checkout', 'invoice_id', 'USD');

// Pass custom fields to your order
$customFields = array(
    'identifier' => "Example.com/ID",
    'customerEmail' => "[email protected]",
);

// Now do the express checkout. If you don't like to pass custom fields, then remove $customFields.
$paypal->doExpressCheckout(123.45, 'LaraPal Test Checkout', 'invoice_id', 'USD', false, $customFields);

// multiple items payment
$items = array(
    array(
        "name" => "Product 1",
        "price" => "12.25",
        "quantity" => "1",
        "product_id" => 111
    ),
    array(
        "name" => "Product 2",
        "price" => "25.50",
        "quantity" => "1",
        "product_id" => 112
    )
);

$paypal->doExpressMultipleCheckout($items, $invoice_id, 'USD', false, $customFields);


// Structure
doExpressCheckout(TRANSACTION_ID, 'INVOICE_ID', 'IS_PARTIAL', PARTIAL_AMOUNT, CURRENCY, NOTE);

// Full refund
doRefund($transactionId, 'invoice_id', false, 0, 'USD', '')

// Partial refund
doRefund($transactionId, 'invoice_id', true, 12.25, 'USD', '') // you can pass note also

// Routes
Route::get('payment-status', 'PayPalController@paymentStatus')->name('payment-status');
Route::get('single-payment', 'PayPalController@singlePayment');
Route::get('multiple-payment', 'PayPalController@multipleItemsPayment');
Route::get('do-the-payment', 'PayPalController@doThePayment');
Route::get('refund-payment', 'PayPalController@doRefund');
Route::get('cancel-payment', 'PayPalController@cancelPayment');

// Controller
php artisan make:controller PayPalController

http://example.com/single-payment
http://example.com/multiple-payment
http://example.com/refund-payment
bash
php artisan vendor:publish --provider="Obydul\LaraPal\LarapalServiceProvider"