1. Go to this page and download the library: Download srmklive/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/ */
srmklive / paypal example snippets
// 1. Create the order and redirect the buyer
$order = $provider->createOrder([
'intent' => 'CAPTURE',
'purchase_units' => [
['amount' => ['currency_code' => 'USD', 'value' => '49.99']],
],
'payment_source' => [
'paypal' => [
'experience_context' => [
'return_url' => 'https://example.com/paypal/return',
'cancel_url' => 'https://example.com/paypal/cancel',
],
],
],
]);
// Redirect the buyer to: $order['links'][href where rel === 'payer-action']
// 2. After the buyer approves, capture the payment
$capture = $provider->capturePaymentOrder($order['id']);
$captureId = $provider->getCaptureIdFromOrder($capture); // store this
// New subscriptions flow
$response = $provider->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->setReturnAndCancelUrl('https://example.com/success', 'https://example.com/cancel')
->setupSubscription('John Doe', '[email protected]');
// Redirect the buyer to: $response['links'][href where rel === 'approve']
use Srmklive\PayPal\Services\PayPal as PayPalClient;
$provider = new PayPalClient;
$provider->setApiCredentials([
'mode' => 'sandbox', // or 'live'
'sandbox' => [
'client_id' => 'YOUR_SANDBOX_CLIENT_ID',
'client_secret' => 'YOUR_SANDBOX_CLIENT_SECRET',
'app_id' => 'APP-80W284485P519543T',
],
'live' => [
'client_id' => 'YOUR_LIVE_CLIENT_ID',
'client_secret' => 'YOUR_LIVE_CLIENT_SECRET',
'app_id' => 'YOUR_LIVE_APP_ID',
],
'payment_action' => 'Sale',
'currency' => 'USD',
'notify_url' => '',
'locale' => 'en_US',
'validate_ssl' => true,
]);
$provider->getAccessToken();
// All API methods are now available
$order = $provider->createOrder([...]);
$response = $provider->showOrderDetails('bad-id');
if (isset($response['error'])) {
// $response['error'] is the decoded PayPal error object or a plain string
}
use Srmklive\PayPal\Exceptions\PayPalApiException;
$provider->withExceptions();
try {
$order = $provider->showOrderDetails('bad-id');
} catch (PayPalApiException $e) {
$e->getHttpStatus(); // HTTP status code: 400, 401, 404, 422, 500, etc. (0 for network errors)
$e->getMessage(); // JSON-encoded error string
$e->getPayPalError(); // decoded array (e.g. ['name' => 'RESOURCE_NOT_FOUND', ...])
// or a plain string for non-JSON errors
}
$provider->getAccessToken();
$result = $provider->generateClientToken();
// $result['client_token'] — pass this to your frontend
// Create
$order = $provider->createOrder([
'intent' => 'CAPTURE',
'purchase_units' => [
['amount' => ['currency_code' => 'USD', 'value' => '100.00']],
],
]);
// Update, show, authorize
$provider->updateOrder('5O190127TN364715T', $patchData);
$order = $provider->showOrderDetails('5O190127TN364715T');
$provider->authorizePaymentOrder('5O190127TN364715T');
// Capture — and extract the capture/transaction ID from the response
$capture = $provider->capturePaymentOrder($order['id']);
$captureId = $provider->getCaptureIdFromOrder($capture);
// $captureId is the value you store in your database and use for refunds,
// dispute lookups, and shipment tracking (see Trackers section).
// Create an agreement token (first step)
$provider->createBillingAgreementToken($data);
// Get details of an existing agreement token
$provider->getBillingAgreementTokenDetails('token-id');
// Create a billing agreement from a token
$provider->createBillingAgreement('token-id');
// Show / Update / Cancel a billing agreement
$provider->showBillingAgreementDetails('agreement-id');
$provider->updateBillingAgreement('agreement-id', $patchData);
$provider->cancelBillingAgreement('agreement-id');
// Payment tokens (permanent)
$provider->createPaymentSourceToken($data);
$provider->setCustomerId('customer_4029352050'); // tSourceToken('token-id');
// Setup tokens (single-use, used to create a payment token)
$provider->createPaymentSetupToken($data);
$provider->showPaymentSetupTokenDetails('token-id');
$provider->deletePaymentSetupToken('token-id');
$response = $provider->setTokenSource('5C991763VB2781612', 'SETUP_TOKEN')
->setCustomerId('customer_4029352050')
->sendPaymentMethodRequest();
// or ->sendPaymentMethodRequest(true) to create a setup token instead
use Carbon\Carbon;
// Raw filter array (full control)
$provider->listTransactions([
'start_date' => Carbon::now()->subDays(30)->toIso8601String(),
'end_date' => Carbon::now()->toIso8601String(),
]);
// Convenience helpers
$provider->getTransactionDetails('5TY05013RG002845M'); // searches last 31 days
$provider->getTransactionDetails('5TY05013RG002845M', 7); // searches last 7 days
$provider->listTransactionsForDateRange('2024-07-01', '2024-07-31');
$provider->listTransactionsByType('T0006', '2024-07-01', '2024-07-31'); // e.g. express checkout sales
$provider->listTransactionsByStatus('S', '2024-07-01', '2024-07-31'); // 'S'=success, 'V'=reversed, 'P'=pending
$provider->listBalances('2024-01-01');
$provider->listBalances('2024-01-01', 'EUR');
$provider->showProfileInfo();
$provider->createMerchantApplication(
'AGGREGATOR',
['https://example.com/callback'],
['[email protected]'],
'WDJJHEBZ4X2LY',
'some-open-id'
);
$provider->setAccountProperties($data);
$provider->disableAccountProperties();
$provider->listUsers(1, 10);
$provider->showUserDetails('user-id');
$provider->deleteUser('user-id');
// Client token — used with PayPal Fastlane and Advanced Card Payments
$provider->generateClientToken(); // preferred alias
$provider->getClientToken(); // equivalent