PHP code example of joseluisald / paypal

1. Go to this page and download the library: Download joseluisald/paypal 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/ */

    

joseluisald / paypal example snippets

 php

define('API', [
    'Type' => 'Sandbox',
    'ClientId' => '---------------',
    'ClientSecret' => '----------'
]);

 php
e joseluisald\Payment\Payment;

$payment = new Payment(API['Type'], API['ClientId'], API['ClientSecret']);

 php

$clientToken = $payment->getToken();

 php

$reference_id = uniqid() . '_' . strtotime("now") . '_' . uniqid();
$data =
'{
    "intent": "CAPTURE",
    "purchase_units": [
        {
            "reference_id": "'.$reference_id.'",
            "amount": {
                "currency_code": "USD",
                "value": "100.00"
            }
        }
    ],
    "payment_source": {
        "card": {
              "vault_id": "q5734p4c"
        }
    }
}';

$createOrder = $payment->createOrder($data);

$idPayment = $createOrder->id;
$status = $createOrder->status;