PayPal’s NVP and SOAP APIs, including DoDirectPayment, SetExpressCheckout and DoExpressCheckoutPayment, are legacy APIs. New integrations should use the PayPal REST API: create an order with POST /v2/checkout/orders, let the buyer approve it with the JavaScript SDK buttons or card fields, then capture it with POST /v2/checkout/orders/{id}/capture. Refunds, authorizations, subscriptions and payouts each have their own REST endpoints, listed below.
Originally published in May 2010 as a list of PayPal NVP sample code. Rewritten in December 2026 as a migration guide.
Old NVP calls and their REST replacements
| NVP method | REST API replacement |
|---|---|
| SetExpressCheckout + DoExpressCheckoutPayment | POST /v2/checkout/orders, then POST /v2/checkout/orders/{id}/capture |
| DoDirectPayment (card on your site) | Orders v2 with PayPal’s hosted card fields |
| DoAuthorization / Reauthorization | Orders v2 with intent: AUTHORIZE, POST /v2/payments/authorizations/{id}/reauthorize |
| DoCapture | POST /v2/payments/authorizations/{id}/capture |
| DoVoid | POST /v2/payments/authorizations/{id}/void |
| RefundTransaction | POST /v2/payments/captures/{id}/refund |
| GetTransactionDetails | GET /v2/checkout/orders/{id} or GET /v2/payments/captures/{id} |
| TransactionSearch | GET /v1/reporting/transactions |
| GetBalance | GET /v1/reporting/balances |
| CreateRecurringPaymentsProfile | Subscriptions API, POST /v1/billing/subscriptions |
| MassPay | Payouts API, POST /v1/payments/payouts |
The REST API uses JSON and OAuth 2.0 instead of API username, password and signature fields in every request.
A minimal create-and-capture flow in PHP
Create a REST app in the PayPal Developer Dashboard to get a client ID and secret. Use the sandbox base URL while testing.
<?php
$base = 'https://api-m.sandbox.paypal.com'; // live: https://api-m.paypal.com
$clientId = getenv('PAYPAL_CLIENT_ID');
$secret = getenv('PAYPAL_SECRET');
// 1. Get an access token
$ch = curl_init("$base/v1/oauth2/token");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => "$clientId:$secret",
CURLOPT_POSTFIELDS => 'grant_type=client_credentials',
]);
$token = json_decode(curl_exec($ch), true)['access_token'];
// 2. Create an order
$order = [
'intent' => 'CAPTURE',
'purchase_units' => [[
'reference_id' => 'order-1001',
'amount' => ['currency_code' => 'USD', 'value' => '49.00'],
]],
];
$ch = curl_init("$base/v2/checkout/orders");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
"Authorization: Bearer $token",
'PayPal-Request-Id: ' . bin2hex(random_bytes(16)), // makes retries safe
],
CURLOPT_POSTFIELDS => json_encode($order),
]);
$created = json_decode(curl_exec($ch), true);
echo json_encode(['id' => $created['id']]); // return this to the JS SDKOn the page, the JavaScript SDK renders the buttons and calls your server:
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID¤cy=USD"></script>
<div id="paypal-buttons"></div>
<script>
paypal.Buttons({
createOrder: () => fetch('/paypal/create-order.php', { method: 'POST' })
.then((r) => r.json()).then((d) => d.id),
onApprove: (data) => fetch('/paypal/capture-order.php?id=' + data.orderID, { method: 'POST' })
.then((r) => r.json()).then(() => { window.location = '/thank-you'; }),
}).render('#paypal-buttons');
</script>The capture script calls POST /v2/checkout/orders/{id}/capture with the same bearer token and checks that the response status is COMPLETED before marking the order as paid.
Don’t trust the browser
Always set the amount on the server and confirm the captured amount and currency against your own order record. Also set up a webhook for PAYMENT.CAPTURE.COMPLETED and PAYMENT.CAPTURE.REFUNDED, so your records stay correct when a buyer closes the tab before the redirect.
If you take cards directly
DoDirectPayment sent raw card numbers through your server, which put you in the heaviest PCI compliance scope. With hosted card fields, the card details go straight to PayPal inside iframes, and your server only handles the order ID.
Common questions
Do old NVP integrations still work?
Some legacy integrations keep running for existing merchants, but PayPal doesn’t add features to them and new accounts may not be able to enable them. Plan a move to REST before something breaks.
Is there an official PHP SDK?
PayPal publishes server SDKs for several languages, but the REST API is simple enough that many PHP projects call it directly with cURL or Guzzle, as above. Check PayPal’s developer site for the current SDK status.
How do I test without real money?
Use the sandbox base URL and sandbox buyer and merchant accounts from the Developer Dashboard. Switch the base URL and credentials when you go live.