PayPal Checkout in Flutter: Orders, Approval, Capture, and Webhooks
Build PayPal checkout in Flutter the safe way: server-created Orders v2, webview approval, capture, and verified webhooks for fulfillment.
Published on • November 10, 2026
AI Assistant

Taking money in a Flutter app is easy to get wrong: many PayPal packages quietly ask for your client secret inside the app, which ships it to every user. This post walks the safe flow end to end - REST credentials, a server-side Orders v2 call, approval in a webview or browser, capture, and verified webhooks for fulfillment.
Credentials, sandbox, and live
PayPal integrations authenticate with a client ID (public, safe in client code) and a client secret (private, server-only). From the developer dashboard you select Apps & Credentials, toggle between Sandbox and Live, and create a REST app; the two environments use separate credentials and separate hosts:
curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token" \
-u "CLIENT_ID:CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials"
The response carries an access token you reuse until it expires; live calls go to https://api-m.paypal.com instead of the sandbox host. PayPal’s sandbox ships with a personal (buyer) and a business (seller) account so you can watch test money move between them, and live credentials require a verified Premier or Business account.
Keep the secret on your server
Several pub.dev packages make it easy to leak the secret. flutter_paypal_checkout (1.0.1) takes secretKey directly in its widget constructor:
PaypalCheckout(
sandboxMode: true,
clientId: "CLIENT_ID",
secretKey: "SECRET_KEY", // never do this in a shipped app
// ...
)
Flutter code can always be decompiled, and the README of flutter_paypal_payment_checkout_v2 states the rule plainly: do not put your PayPal secret key in a mobile app in production - in production always use backend-created orders. The better pattern is the one paypal_checkout_flutter uses: your server creates the order and hands the app only an order ID.
final result = await paypal.pay(PaymentRequest(orderId: orderIdFromBackend));
result.fold(
(failure) => debugPrint('Error: ${failure.message}'),
(success) => debugPrint('Paid! Order: ${success.orderId}'),
);
The client ID is the only credential your app may embed.
Create, approve, and capture the order
Creating an order is a server call to the Orders v2 API. Set intent to CAPTURE (or AUTHORIZE if you want to capture later), and put the return/cancel URLs in payment_source.paypal.experience_context:
curl -X POST https://api-m.sandbox.paypal.com/v2/checkout/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
-d '{
"intent": "CAPTURE",
"purchase_units": [{
"amount": { "currency_code": "USD", "value": "100.00" }
}],
"payment_source": {
"paypal": {
"experience_context": {
"return_url": "https://example.com/return",
"cancel_url": "https://example.com/cancel"
}
}
}
}'
A successful create returns 200 with status PAYER_ACTION_REQUIRED and a links entry with rel: "payer-action" whose href is the approval URL (for example https://www.sandbox.paypal.com/checkoutnow?token=...). After the buyer approves, the order status becomes APPROVED and you capture it - an order cannot be captured before that:
curl -v -X POST "https://api-m.sandbox.paypal.com/v2/checkout/orders/ORDER_ID/capture" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ACCESS_TOKEN" \
-d '{}'
PayPal documents that you have about 3 hours to capture or modify a freshly created order (extendable to 72 hours by arrangement), so capture promptly after approval rather than at some later point.
Approving in a webview or browser
On Android and iOS, open the approval URL in an in-app webview - flutter_paypal_checkout and paypal_checkout both do this with flutter_inappwebview and surface onSuccess, onError, and onCancel callbacks. On Flutter web, a full-page redirect is the reliable route: send the browser to the approval URL, let PayPal bounce back to your HTTPS return URL carrying the token query parameter, then create and capture the order on the backend after the redirect. flutter_paypal_payment_checkout_v2 supports exactly this split, with custom return schemes like paypal-sdk://success on mobile and HTTPS return/cancel URLs on web.
Fulfilling with webhooks
Never trust the redirect alone for fulfillment - the browser may close mid-flight. Register a webhook with POST /v1/notifications/webhooks and subscribe to the events that matter: CHECKOUT.ORDER.APPROVED (buyer approved, ready to capture), PAYMENT.CAPTURE.COMPLETED (fulfill the order), plus PAYMENT.CAPTURE.PENDING, PAYMENT.CAPTURE.DENIED, and CHECKOUT.PAYMENT-APPROVAL.REVERSED. Verify every delivery with POST /v1/notifications/verify-webhook-signature, passing the five PAYPAL-* headers (PAYPAL-AUTH-ALGO, PAYPAL-CERT-URL, PAYPAL-TRANSMISSION-ID, PAYPAL-TRANSMISSION-SIG, PAYPAL-TRANSMISSION-TIME), your webhook_id, and the raw request body byte-for-byte - re-serializing the JSON breaks the signature. Respond 200 immediately (PayPal retries non-2xx responses up to 25 times over 3 days), process asynchronously, and deduplicate by event id so retries stay idempotent.
Alternatives to consider
PayPal is not the only option. Stripe ships a first-party Flutter SDK (flutter_stripe) with a hosted PaymentSheet that folds card, Apple Pay, and Google Pay into one flow; in_app_purchase is the required path for digital goods sold inside iOS and Android apps, where store rules mandate store billing. PayPal’s own packages cluster into three camps: webview wrappers (flutter_paypal_checkout, paypal_checkout), native-SDK bridges (paypal_checkout_flutter, no webview), and Orders V2 wrappers with typed models (flutter_paypal_payment_checkout_v2). Whatever you pick, the architecture stays the same: create and capture on the server, verify webhooks, and keep secrets out of the binary.
Takeaway: Keep the PayPal client secret server-side, create Orders v2 with intent: CAPTURE, open the payer-action URL in a webview or redirect, capture once the order is APPROVED, and treat verified, idempotent webhooks - not the app callback - as the source of truth for fulfillment.
Sources
- https://developer.paypal.com/api/get-started
- https://developer.paypal.com/api/orders/v2/orders-create
- https://developer.paypal.com/checkout/put-it-all-together
- https://developer.paypal.com/api/rest/webhooks/rest
- https://developer.paypal.com/api/webhooks/v1/verify-webhook-signature-post
- https://developer.paypal.com/payment-methods/webhooks
- https://pub.dev/packages/flutter_paypal_checkout
- https://pub.dev/packages/flutter_paypal_payment_checkout_v2
- https://pub.dev/packages/paypal_checkout_flutter