PHP code example of srmklive / paypal
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',
],
'currency' => 'USD',
'locale' => 'en_US',
'validate_ssl' => true,
]);
$provider->getAccessToken();
// All API methods are now available
$order = $provider->createOrder([...]);
return [
'mode' => env('PAYPAL_MODE', 'sandbox'), // 'sandbox' or 'live'
'sandbox' => [
'client_id' => env('PAYPAL_SANDBOX_CLIENT_ID', ''),
'client_secret' => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''),
'app_id' => 'APP-80W284485P519543T',
],
'live' => [
'client_id' => env('PAYPAL_LIVE_CLIENT_ID', ''),
'client_secret' => env('PAYPAL_LIVE_CLIENT_SECRET', ''),
'app_id' => env('PAYPAL_LIVE_APP_ID', ''),
],
'currency' => env('PAYPAL_CURRENCY', 'USD'),
'locale' => env('PAYPAL_LOCALE', 'en_US'),
'validate_ssl' => env('PAYPAL_VALIDATE_SSL', true),
'timeout' => env('PAYPAL_TIMEOUT', 30), // total request timeout (seconds)
'connect_timeout' => env('PAYPAL_CONNECT_TIMEOUT', 10), // connection timeout (seconds)
'max_retries' => env('PAYPAL_MAX_RETRIES', 2), // retries on 5xx / 429 / network errors (0 to disable); POST/PATCH only with withIdempotencyKey()
];
use Srmklive\PayPal\Services\PayPal as PayPalClient;
$provider = new PayPalClient;
// Or via facade
$provider = \PayPal::setProvider();
use Symfony\Component\HttpClient\Psr18Client;
$provider->setClient(new Psr18Client());
$provider->withIdempotencyKey()->capturePaymentOrder($orderId);
$provider->setApiCredentials([
'mode' => 'live',
'live' => [
'client_id' => 'PAYPAL_LIVE_CLIENT_ID',
'client_secret' => 'PAYPAL_LIVE_CLIENT_SECRET',
'app_id' => 'PAYPAL_LIVE_APP_ID',
],
'currency' => 'USD',
'locale' => 'en_US',
'validate_ssl' => true,
]);
$provider->getAccessToken();
$provider->setCurrency('EUR');
$provider->setPartnerAttributionId('YourPlatform_SP');
$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
}
// Browser-safe client token bound to your domain(s); your server access token is not replaced.
$result = $provider->generateFastlaneClientToken(['example.com']);
// $result['access_token'] — the client token, pass this to your frontend
// $result['expires_in'] — lifetime in seconds, use it to cache the token
// Create
$order = $provider->createOrder([
'intent' => 'CAPTURE',
'purchase_units' => [
['amount' => ['currency_code' => 'USD', 'value' => '49.99']],
],
'payment_source' => [
'card' => [
'single_use_token' => $singleUseToken, // from Fastlane.FastlaneCardComponent
],
],
]);
// Capture
$capture = $provider->capturePaymentOrder($order['id']);
// Extract the transaction/capture ID
$captureId = $provider->getCaptureIdFromOrder($capture);
$provider->getAccessToken();
$provider->setPaymentSourcePayUponInvoice([
'name' => ['given_name' => 'John', 'surname' => 'Doe'],
'email' => '[email protected] ',
'birth_date' => '1990-01-01',
'phone' => ['country_code' => '49', 'national_number' => '1234567890'],
'billing_address' => [
'address_line_1' => 'Hauptstraße 1',
'admin_area_2' => 'Berlin',
'postal_code' => '10115',
'country_code' => 'DE',
],
'experience_context' => [
'locale' => 'de-DE',
'return_url' => 'https://example.com/paypal-success',
'cancel_url' => 'https://example.com/paypal-cancel',
],
]);
$order = $provider->createOrderWithPaymentSource([
'intent' => 'CAPTURE',
'purchase_units' => [
['amount' => ['currency_code' => 'EUR', 'value' => '99.00']],
],
]);
$capture = $provider->capturePaymentOrder($order['id']);
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addPlanTrialPricing('DAY', 7)
->addDailyPlan('Demo Plan', 'Demo Plan', 1.50)
->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', '[email protected] ', '2025-01-01');
// Weekly
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addPlanTrialPricing('DAY', 7)
->addWeeklyPlan('Demo Plan', 'Demo Plan', 30)
->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', '[email protected] ', '2025-01-01');
// Monthly
$response = $provider->addProduct(...)->addMonthlyPlan('Demo Plan', 'Demo Plan', 100)->...->setupSubscription(...);
// Annual
$response = $provider->addProduct(...)->addAnnualPlan('Demo Plan', 'Demo Plan', 600)->...->setupSubscription(...);
$response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE')
->addCustomPlan('Demo Plan', 'Demo Plan', 150, 'MONTH', 3)
->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', '[email protected] ', '2025-01-01');
$response = $provider->addProductById('PROD-XYAB12ABSB7868434')
->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel')
->setupSubscription('John Doe', '[email protected] ', '2025-01-01');
// Setup fee
$provider->addSetupFee(9.99)->addProductById(...)->...->setupSubscription(...);
// Shipping address
$provider->addShippingAddress('John Doe', '123 Main St', 'Suite 1', 'Austin', 'TX', 78701, 'US')
->addProductById(...)->...->setupSubscription(...);
// Payment failure threshold
$provider->addPaymentFailureThreshold(5)->addProductById(...)->...->setupSubscription(...);
$response = $provider->addBillingPlanById('P-5ML4271244454362WXNWU5NQ')
->addPricingScheme('DAY', 7, 0, true)
->addPricingScheme('MONTH', 1, 100)
->processBillingPlanPricingUpdates();
use Srmklive\PayPal\Builders\BillingPlanBuilder;
$response = BillingPlanBuilder::make()
->forProduct('PROD-XXCD1234QWER65782')
->named('Premium Plan', 'Monthly premium access')
->monthly(9.99)
->create($provider);
$response = BillingPlanBuilder::make()
->forProduct('PROD-XXCD1234QWER65782')
->named('Video Streaming Plan', 'Video Streaming Service basic plan')
->trialMonthly(3.00, totalCycles: 2) // $3/mo for 2 months
->trialMonthly(6.00, totalCycles: 3) // $6/mo for 3 months
->monthly(10.00, totalCycles: 12) // $10/mo for 12 months
->withSetupFee(10.00)
->withTax(10.0)
->create($provider);
$payload = BillingPlanBuilder::make()
->forProduct('PROD-XXCD1234QWER65782')
->named('Annual Plan')
->annual(99.00)
->withCurrency('EUR')
->withFailureThreshold(5)
->build(); // returns array<string, mixed>
$provider->createPlan($payload);
// List (page, count, show_total, fields)
$plans = $provider->listPlans();
$plans = $provider->setCurrentPage(2)->setPageSize(20)->listPlans(); // page size max. 20
$plans = $provider->listPlansForProduct('PROD-XXCD1234QWER65782');
// Create
$plan = $provider->createPlan($data);
// Update
$provider->updatePlan('P-7GL4271244454362WXNWU5NQ', [
['op' => 'replace', 'path' => '/payment_preferences/payment_failure_threshold', 'value' => 7],
]);
// Show / Activate / Deactivate
$plan = $provider->showPlanDetails('P-7GL4271244454362WXNWU5NQ');
$provider->activatePlan('P-7GL4271244454362WXNWU5NQ');
$provider->deactivatePlan('P-7GL4271244454362WXNWU5NQ');
// Update pricing
$provider->updatePlanPricing('P-7GL4271244454362WXNWU5NQ', $pricingData);
$products = $provider->listProducts();
$products = $provider->listProducts(1, 30, true);
$product = $provider->createProduct($data, 'create-product-'.time());
$provider->updateProduct('72255d4849af8ed6e0df1173', [
['op' => 'replace', 'path' => '/description', 'value' => 'Updated description'],
]);
$product = $provider->showProductDetails('72255d4849af8ed6e0df1173');
// 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');
$order = $provider->showOrderDetails('5O190127TN364715T', ['payment_source']); // king to the order (Orders v2 tracking)
$provider->addTrackingForOrder($order['id'], [
'capture_id' => $captureId,
'tracking_number' => '1Z999AA10123456784',
'carrier' => 'UPS',
]);
// Update or cancel it later (tracker ID: purchase_units[].shipping.trackers[].id of the response)
$provider->updateTrackingForOrder($order['id'], $trackerId, [
['op' => 'replace', 'path' => '/notify_payer', 'value' => true],
]);
$provider->cancelTrackingForOrder($order['id'], $trackerId);
$provider->showAuthorizedPaymentDetails('0VF52814937998046');
$provider->captureAuthorizedPayment('0VF52814937998046', 'INVOICE-123', 10.99, 'Payment note');
$provider->reAuthorizeAuthorizedPayment('0VF52814937998046', 10.99);
$provider->voidAuthorizedPayment('0VF52814937998046');
$provider->showCapturedPaymentDetails('2GG279541U471931P');
$provider->refundCapturedPayment('2GG279541U471931P', 'INVOICE-123', 10.99, 'Defective product');
$provider->refundCapturedPaymentInFull('2GG279541U471931P'); // refunds the remaining captured amount
$provider->showRefundDetails('1JU08902781691411');
// Which payment methods can this buyer use? (all fields optional)
$methods = $provider->findEligiblePaymentMethods([
'customer' => [
'country_code' => 'US',
'channel' => ['browser_type' => 'SAFARI', 'device_type' => 'MOBILE', 'client_os' => 'IOS'],
],
'purchase_units' => [
['amount' => ['currency_code' => 'USD', 'value' => '100.00']],
],
'preferences' => [
'payment_source_constraint' => ['constraint_type' => 'EXCLUDE', 'payment_sources' => ['PAYPAL']],
],
]);
$provider->createBatchPayout($data);
$provider->showBatchPayoutDetails('FYXMPQTX4JC9N');
$provider->showPayoutItemDetails('8AELMXH8UB2P8');
$provider->cancelUnclaimedPayoutItem('8AELMXH8UB2P8');
// Create batch
$provider->createReferencedBatchPayout([
'referenced_payouts' => [
['reference_id' => '2KP03934U4415543C', 'reference_type' => 'TRANSACTION_ID'],
],
], 'some-request-id', 'some-attribution-id');
$provider->listItemsReferencedInBatchPayout('KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E=');
$provider->createReferencedBatchPayoutItem(
['reference_id' => 'CAPTURETXNID', 'reference_type' => 'TRANSACTION_ID'],
'some-request-id', 'some-attribution-id'
);
$provider->showReferencedPayoutItemDetails('CDZEC5MJ8R5HY', 'some-attribution-id');
// 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');
$invoiceNo = $provider->generateInvoiceNumber();
$invoices = $provider->listInvoices();
$invoices = $provider->setCurrentPage(2)->setPageSize(50)->listInvoices();
$invoice = $provider->createInvoice($data);
$provider->deleteInvoice('INV2-Z56S-5LLA-Q52L-CPZ5');
$provider->updateInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', $data);
$provider->updateInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', $data, false, false); // update without emailing recipient/merchant
$invoice = $provider->showInvoiceDetails('INV2-Z56S-5LLA-Q52L-CPZ5');
$provider->cancelInvoice('INV2-Z56S-5LLA-Q52L-CPZ5');
$qrCode = $provider->generateQRCodeInvoice('INV2-Z56S-5LLA-Q52L-CPZ5'); // base64 PNG, 500x500
$qrCode = $provider->generateQRCodeInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', 200, 200, 'details'); // 150-500 px; 'pay' or 'details'
// <img src="data:image/png;base64,<?= $qrCode
$invoices = $provider->searchInvoices();
$invoices = $provider->setCurrentPage(1)->setPageSize(50)->showTotals(false)->searchInvoices();
$invoices = $provider
->addInvoiceFilterByRecipientEmail('[email protected] ')
->addInvoiceFilterByRecipientFirstName('John')
->addInvoiceFilterByRecipientLastName('Doe')
->addInvoiceFilterByRecipientBusinessName('Acme Inc.')
->addInvoiceFilterByInvoiceNumber('#123')
->addInvoiceFilterByInvoiceStatus(['PAID', 'MARKED_AS_PAID'])
->addInvoiceFilterByReferenceorMemo('deal-ref')
->addInvoiceFilterByCurrencyCode('USD')
->addInvoiceFilterByAmountRange(30, 50) // uses configured currency
->addInvoiceFilterByAmountRange(30, 50, 'EUR') // explicit currency
->addInvoiceFilterByDateRange('2024-01-01', '2024-06-30', 'invoice_date') // invoice_date|due_date|payment_date|creation_date
->addInvoiceFilterByArchivedStatus(false)
->addInvoiceFilterByFields(['items', 'payments', 'refunds'])
->searchInvoices();
$provider->listInvoiceTemplates();
$provider->listInvoiceTemplates(1, 50);
$provider->createInvoiceTemplate($data);
$provider->deleteInvoiceTemplate('TEMP-19V05281TU309413B');
$provider->updateInvoiceTemplate('TEMP-19V05281TU309413B', $data);
$provider->showInvoiceTemplateDetails('TEMP-19V05281TU309413B');
$provider->createSubscription($data);
$provider->updateSubscription('I-BW452GLLEP1G', [
['op' => 'replace', 'path' => '/billing_info/outstanding_balance', 'value' => ['currency_code' => 'USD', 'value' => '50.00']],
]);
$provider->showSubscriptionDetails('I-BW452GLLEP1G');
$provider->showSubscriptionDetails('I-BW452GLLEP1G', ['last_failed_payment', 'plan']); // 1G', $data);
$provider->listSubscriptionTransactions('I-BW452GLLEP1G', '2024-01-01T00:00:00Z', '2024-12-31T23:59:59Z');
// Lifecycle helpers
$provider->reactivateSubscription('I-BW452GLLEP1G'); // default reason
$provider->reactivateSubscription('I-BW452GLLEP1G', 'Customer requested'); // custom reason
$isActive = $provider->isSubscriptionActive('I-BW452GLLEP1G'); // bool
$provider->listDisputes();
$provider->updateDispute('PP-D-27803', $patchData);
$provider->showDisputeDetails('PP-D-27803');
$provider->acceptDisputeClaim('PP-D-27803', 'Wrong item shipped');
$provider->acceptDisputeOfferResolution('PP-D-27803', 'Accepting discount offer');
$provider->acknowledgeItemReturned('PP-D-27803', 'Items received', 'ITEM_RECEIVED');
$provider->makeOfferToResolveDispute('PP-D-27803', 'Offering refund', 10.00, 'REFUND');
$provider->makeOfferToResolveDispute('PP-D-27803', 'Please return the item', 10.00, 'REFUND_WITH_RETURN', [
'return_shipping_address' => ['address_line_1' => '1 Main St', 'admin_area_2' => 'San Jose', 'postal_code' => '95131', 'country_code' => 'US'],
]);
$provider->makeOfferToResolveDispute('PP-D-27803', 'Sending a replacement', 0, 'REPLACEMENT_WITHOUT_REFUND'); // amount ignored
$provider->escalateDisputeToClaim('PP-D-27803', 'Escalating unresolved dispute');
$provider->updateDisputeStatus('PP-D-27803', $data);
// Provide evidence (jpg, png, pdf only)
$provider->provideDisputeEvidence('PP-D-27803', [
'/path/to/invoice.pdf',
'/path/to/screenshot.jpg',
]);
// Optionally describe the evidence (sent as a JSON "input" part)
$provider->provideDisputeEvidence('PP-D-27803', ['/path/to/proof-of-delivery.pdf'], [
[
'evidence_type' => 'PROOF_OF_FULFILLMENT',
'evidence_info' => ['tracking_info' => [['carrier_name' => 'UPS', 'tracking_number' => '1Z999AA10123456784']]],
'notes' => 'Delivered on 2026-09-30.',
],
]);
// Appeal a decision with new evidence (
$provider->addTracking($data);
$provider->listTrackingDetails($captureId);
$provider->listTrackingDetails($captureId, 'tracking-number');
$provider->updateTrackingDetails('tracking-id', $data);
$provider->showTrackingDetails('tracking-id');
// Create
$provider->createWebHook('https://example.com/paypal/webhook', ['PAYMENT.CAPTURE.COMPLETED']);
// List / Show / Update / Delete
$provider->listWebHooks();
$provider->showWebHookDetails('webhook-id');
$provider->updateWebHook('webhook-id', $patchData);
$provider->deleteWebHook('webhook-id');
// Events
$provider->listWebHookEvents('webhook-id');
$provider->listEventTypes();
$provider->listEvents();
$provider->listEvents(['event_type' => 'PAYMENT.CAPTURE.COMPLETED', 'start_time' => '2026-09-01T00:00:00Z']);
$provider->showEventDetails('event-id');
$provider->resendEventNotification('event-id', ['webhook-id']);
// Simulate an event (PayPal posts a mock event to your webhook or URL)
$provider->simulateWebHookEvent('PAYMENT.CAPTURE.COMPLETED', 'webhook-id');
$provider->simulateWebHookEvent('PAYMENT.CAPTURE.COMPLETED', url: 'https://example.com/paypal/webhook');
// Mock events can't be verified via verifyWebHook(); verify them locally with the
// webhook ID 'WEBHOOK_ID': $provider->verifyWebHookLocally($headers, 'WEBHOOK_ID', $rawBody);
// Verify incoming webhook signature (API roundtrip)
$provider->verifyWebHook([
'auth_algo' => $request->header('PAYPAL-AUTH-ALGO'),
'cert_url' => $request->header('PAYPAL-CERT-URL'),
'transmission_id' => $request->header('PAYPAL-TRANSMISSION-ID'),
'transmission_sig' => $request->header('PAYPAL-TRANSMISSION-SIG'),
'transmission_time' => $request->header('PAYPAL-TRANSMISSION-TIME'),
'webhook_id' => 'your-webhook-id',
'webhook_event' => $request->getContent(), // raw body: PayPal
use Srmklive\PayPal\Events\WebhookEvent;
$rawBody = $request->getContent();
if (! $provider->verifyWebHookLocally($request->headers->all(), 'your-webhook-id', $rawBody)) {
return response()->json(['error' => 'Invalid signature'], 401);
}
$event = WebhookEvent::fromRawBody($rawBody);
if ($event->is('PAYMENT.CAPTURE.COMPLETED')) {
// $event->resource contains the capture object
$this->handleCapture($event->resource);
}
if ($event->is('BILLING.SUBSCRIPTION.CANCELLED')) {
$this->handleCancellation($event->resource);
}
// Available properties:
// $event->id — webhook notification ID
// $event->eventType — e.g. 'PAYMENT.CAPTURE.COMPLETED'
// $event->resourceType — e.g. 'capture'
// $event->summary — human-readable summary
// $event->createTime — ISO 8601 timestamp
// $event->resource — event-specific resource array
// $event->rawPayload — full decoded payload array
$event = WebhookEvent::fromArray($request->json()->all());
// Payment tokens (permanent)
$provider->createPaymentSourceToken($data);
$provider->setCustomerId('customer_4029352050'); // ');
$provider->deletePaymentSourceToken('token-id');
// Setup tokens (single-use, used to create a payment token; they expire automatically)
$provider->createPaymentSetupToken($data);
$provider->showPaymentSetupTokenDetails('token-id');
$response = $provider->setTokenSource('5C991763VB2781612', 'SETUP_TOKEN')
->setCustomerId('customer_4029352050')
->sendPaymentMethodRequest(); // converts the setup token into a payment token
// ->sendPaymentMethodRequest(true) creates a setup token instead; use it with
// card/PayPal/Venmo sources (setPaymentSourceCard() etc.), not with a token source
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');
// Requires the user's access token from Log in with PayPal, set via setAccessToken()
$provider->showProfileInfo();
$provider->createMerchantApplication(
'AGGREGATOR',
['https://example.com/callback'],
['[email protected] '],
'WDJJHEBZ4X2LY',
'some-open-id'
);
$provider->setAccountProperties($data);
$provider->disableAccountProperties();
$provider->listUsers(); // all users
$provider->listUsers('userName eq "jdoe"'); // SCIM filter expression
$provider->listUsers('', 11, 10); // startIndex 11, count 10
$provider->showUserDetails('user-id');
$provider->deleteUser('user-id');
// Client token for JS SDK v5 hosted card fields (Advanced Card Payments)
$provider->generateClientToken(); // alias of getClientToken()
$provider->getClientToken();
// Client token for PayPal Fastlane (see the Fastlane section)
$provider->generateFastlaneClientToken(['example.com']);
$provider->createPartnerReferral($data);
$provider->showReferralData('ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0=');
$provider->listSellerTrackingInfo('tracking-id');
$provider->listSellerStatus('partner-id', 'merchant-id');
$provider->listMerchantCredentials();
$provider->listWebExperienceProfiles();
$provider->createWebExperienceProfile($data);
$provider->showWebExperienceProfileDetails('XP-A88A-LYLW-8Y3X-E5ER');
$provider->updateWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $data);
$provider->patchWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $patchData);
$provider->deleteWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER');
use Srmklive\PayPal\Testing\MockPayPalClient;
$mock = new MockPayPalClient();
$mock->addResponse(['id' => '5O190127TN364715T', 'status' => 'CREATED']);
// mockProvider() returns a ready PayPal instance — credentials and access token pre-set
$provider = $mock->mockProvider();
$order = $provider->createOrder($data);
expect($order['id'])->toBe('5O190127TN364715T');
$mock = new MockPayPalClient();
$mock->addResponse(['id' => 'ORDER-1', 'status' => 'CREATED']);
$mock->addResponse(['id' => 'ORDER-2', 'status' => 'CREATED']);
$mock->addResponse(false, 204);
$request = $mock->lastRequest(); // Psr\Http\Message\RequestInterface
$mock->requests(); // all captured requests, in order
$mock->requestCount(); // int
$request->getHeaderLine('Authorization'); // 'Bearer mock-access-token'
$request->getMethod(); // 'POST'
(string) $request->getUri(); // 'https://api-m.sandbox.paypal.com/v2/checkout/orders'
$provider->setAccessToken(['access_token' => 'mock-token', 'token_type' => 'Bearer']);
$provider->setClient($mock);
bash
php artisan vendor:publish --provider "Srmklive\PayPal\Providers\PayPalServiceProvider"
html
<script>
const sdkInstance = await window.paypal.createInstance({
clientToken: '<?= $result["access_token"]