flutter_paypal_payment_checkout_v2 2.0.1
flutter_paypal_payment_checkout_v2: ^2.0.1 copied to clipboard
This package simplifies integrating PayPal payments into your mobile app. Key features include seamless in-app PayPal integration
Flutter PayPal Payment #
A powerful, easy-to-use Flutter package that enables seamless PayPal checkout flows using:
- PayPal Payments / Orders API V2 (recommended)
- Legacy Payments API V1 (deprecated by PayPal, but still supported)
This package supports:
- Secure backend-driven order creation
- Client-side sandbox testing
- In-app WebView checkout experience
- Custom transaction models
- Full capture flow for PayPal V2
β¨ Features #
- π Production-ready PayPal V2 flow (backend creates + captures order)
- π§ͺ Sandbox testing mode
- βοΈ Full PayPal Orders API V2 request/response models
- π³ Line items, shipping, taxes, preferences & more
- π Custom return & cancel URL schemes (e.g.,
paypal-sdk://success) - π― Callbacks for success, error, cancellation
- π Supports PayPal API V1 for backward compatibility
π¦ Installation #
Add to pubspec.yaml:
dependencies:
flutter_paypal_payment_checkout_v2: ^2.0.1
Install:
flutter pub get
π Usage #
You can choose between:
β Using PayPal API V2 (Recommended) #
V2 supports modern PayPal features, is more secure, and is PayPalβs officially recommended API.
Secure Backend Flow #
π In production, you MUST create and capture orders on your backend. Your backend returns only the approval URL.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PaypalCheckoutViewV2(
sandboxMode: true,
/// Recommended: backend returns approval URL
approvalUrl: () async {
// Your backend should return a full checkout URL
return await myBackend.createPaypalOrder();
},
/// Called when user finishes checkout and redirects back to app
onSuccess: (result) {
print("Payment success: $result");
Navigator.pop(context);
},
onError: (error) {
print("Error: $error");
Navigator.pop(context);
},
onCancel: () {
print("Payment cancelled");
Navigator.pop(context);
},
),
),
);
Client-Side Flow (Sandbox Only) #
β οΈ Never use this in production. It exposes your PayPal clientId + secretKey.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PaypalCheckoutViewV2(
sandboxMode: true,
clientId: "SANDBOX_CLIENT_ID",
secretKey: "SANDBOX_SECRET_KEY",
overrideInsecureClientCredentials: true, // allow local tokens
getAccessToken: () async => null,
transactions: PayPalOrderRequestV2(
intent: PayPalOrderIntent.capture,
// amount, items, shipping, etc...
),
onSuccess: (PayPalCaptureOrderResponse res) {
print("Captured: ${res.status}");
},
onError: (error) => print(error),
onCancel: () => print("Cancelled"),
),
),
);
π‘ Legacy PayPal V1 Checkout (Optional) #
PayPal V1 is older and deprecated, but supported for compatibility.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PaypalCheckoutViewV1(
sandboxMode: true,
clientId: "ONLY FOR SANDBOX",
secretKey: "ONLY FOR SANDBOX",
getAccessToken: null, // MUST be handled by your backend in live mode
transactions: PaypalTransactionV1(
amount: PaypalTransactionV1Amount(
subTotal: 100.0,
tax: 0.0,
shipping: 0.0,
handlingFee: 0.0,
shippingDiscount: 0.0,
insurance: 0.0,
total: 100.0,
currency: 'USD',
),
description: "Order description",
items: [
PaypalTransactionV1Item(
name: "Apple",
quantity: 4,
price: 10.0,
tax: 0.0,
currency: "USD",
sku: "SKU_APPLE",
description: "Fresh apples",
),
],
),
onSuccess: (params) {
print("Success: $params");
},
onError: (error) => print("Error: $error"),
onCancel: () => print("Cancelled"),
),
),
);
π Security Notes (Important) #
DO NOT PUT YOUR PAYPAL SECRET KEY IN A MOBILE APP FOR PRODUCTION. #
Flutter code can be extracted even from release builds.
β Use backend mode (approvalUrl) for all real payments
β Limit local credentials to sandbox only
β Set overrideInsecureClientCredentials only for testing
β€οΈ Donate #
If you would like to support this package:
PayPal: https://paypal.me/mazenelgayar
Thank you for your support!