incodes_payment 1.0.0+1 copy "incodes_payment: ^1.0.0+1" to clipboard
incodes_payment: ^1.0.0+1 copied to clipboard

A Flutter package for handling multiple payment gateways including Stripe, Razorpay, PayPal, and more.

InCodes Payment #

This project integrates multiple payment gateways into Flutter.
Each section explains the gateway name, methods included, and how they work.

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

πŸš€ Stripe Payment Integration #

This module provides integration with Stripe using the flutter_stripe package.

It allows you to create payment intents, open the Stripe PaymentSheet, and handle success/failure callbacks with optional custom toast/snackbar messages.


πŸ”‘ Features #

  • Initialize Stripe in test or live mode.
  • Create PaymentIntent with Stripe’s REST API.
  • Open Stripe PaymentSheet (supports Apple Pay & Google Pay).
  • Handle success and failure with callbacks.
  • Default or custom toast/snackbar handling.

βš™οΈ Methods #

1. init({required bool isTest, required String publishableKey})

Initializes the Stripe SDK.

Parameters:

  • isTest: true for test mode, false for live mode.
  • publishableKey: Your Stripe Publishable Key.

2. stripePay({...})

Opens the Stripe payment flow.

Parameters:

  • amount: Amount in the smallest currency unit (e.g. cents for USD).
  • currency: Currency code (e.g. "USD", "INR").
  • secretKey: Your Stripe Secret Key (used to create PaymentIntent).
  • merchantCountryCode: Country code (for Apple Pay/Google Pay).
  • merchantDisplayName: Merchant/business name displayed in payment sheet.
  • paymentGatewayName: Gateway name for logging/toast (default "Stripe").
  • description: (Optional) Payment description.
  • onShowToast: (Optional) Custom toast/snackbar/dialog function.
  • onPaymentSuccess: (Optional) Callback when payment succeeds.
  • onPaymentFailure: (Optional) Callback when payment fails.

πŸ”„ Flow of Stripe Payment #

  1. Initialize Stripe with publishable key.
  2. Create PaymentIntent via Stripe API using secret key.
  3. Initialize PaymentSheet with PaymentIntent client secret.
  4. Present PaymentSheet to complete the transaction.
  5. Handle response:
    • βœ… Success β†’ IncodesListener().onSuccess()
    • ❌ Failure/Cancel β†’ IncodesListener().onFailure()

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

πŸ’³ Razorpay Payment Integration #

This module integrates Razorpay using the razorpay_flutter package.

It manages checkout flow, success/failure handling, and external wallet selection with both default toast (via IncodesListener) and custom user-provided callbacks.


πŸ”‘ Features #

  • Open Razorpay Checkout with user details (email, phone).
  • Handle events:
    • βœ… Payment Success
    • ❌ Payment Failure
    • πŸ’Ό External Wallet Selection (Paytm, PhonePe, Mobikwik, etc.)
  • Custom or default toast/snackbar support.
  • Exposes callbacks for API calls after events.
  • Dispose listeners safely to avoid memory leaks.

βš™οΈ Methods #

1. openRazorpay({...})

Opens Razorpay checkout.

Parameters:

  • contactNumber: Customer phone number (prefilled).
  • emailId: Customer email address (prefilled).
  • razorpayKey: Your Razorpay Public Key.
  • amount: Payment amount in INR (converted to paisa internally).
  • appName: Business/app display name.
  • description: (Optional) Payment/order description.
  • colorCode: (Optional) Theme color (default: green #0CA72F).
  • paymentGatewayName: Name for logs/toast (default "Razorpay").
  • onShowToast: (Optional) Custom toast/snackbar/dialog handler.
  • onPaymentSuccess: (Optional) Called after successful payment.
  • onPaymentFailure: (Optional) Called after failed payment.
  • onExternalWallet: (Optional) Called when user selects an external wallet.

2. dispose()

Cleans up Razorpay listeners.
Should be called when the screen is disposed to prevent memory leaks.


πŸ”„ Flow of Razorpay Payment #

  1. Setup checkout options (key, amount, user info, theme, wallets).
  2. Open Razorpay Checkout.
  3. Handle events:
    • βœ… Success β†’ IncodesListener().onSuccess()
    • ❌ Failure β†’ IncodesListener().onFailure()
    • πŸ’Ό External Wallet β†’ IncodesListener().onSuccess() with wallet details
  4. Callbacks (onPaymentSuccess, onPaymentFailure, onExternalWallet) are triggered if provided.

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

πŸ…ΏοΈ PayPal Payment Integration #

This module integrates PayPal using the flutter_paypal_payment package.

It manages checkout with PayPal, handles success/failure/cancel events, and provides default or custom toast/snackbar handling.


πŸ”‘ Features #

  • Open PayPal Checkout with clientId, secretKey, and transaction details.
  • Supports sandbox and live mode.
  • Handle events:
    • βœ… Payment Success
    • ❌ Payment Failure
    • 🚫 Payment Cancel
  • Custom or default toast/snackbar handling.
  • Exposes callbacks for API calls after payment events.

βš™οΈ Methods #

1. openPaypal({...})

Opens the PayPal checkout screen.

Parameters:

  • context: Flutter BuildContext (required for navigation).
  • clientId: PayPal Client ID.
  • secretKey: PayPal Secret Key.
  • transactions: List of transactions to be paid.
  • sandboxMode: true for sandbox (default), false for live mode.
  • note: (Optional) Note to show in checkout.
  • paymentGatewayName: Gateway name for logs/toast (default "PayPal").
  • onShowToast: (Optional) Custom toast/snackbar/dialog handler.
  • onPaymentSuccess: (Optional) Callback when payment succeeds.
  • onPaymentFailure: (Optional) Callback when payment fails.
  • onPaymentCancel: (Optional) Callback when payment is cancelled.

πŸ”„ Flow of PayPal Payment #

  1. Navigate to PayPal Checkout View with given credentials and transactions.
  2. Process Payment via PayPal UI.
  3. Handle events:
    • βœ… Success β†’ IncodesListener().onSuccess()
    • ❌ Failure β†’ IncodesListener().onFailure()
    • 🚫 Cancel β†’ IncodesListener().onFailure()
  4. Callbacks (onPaymentSuccess, onPaymentFailure, onPaymentCancel) are triggered if provided.

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

πŸ’° Paystack Payment Integration #

This module integrates Paystack using the pay_with_paystack package.

It manages checkout with Paystack, handles success/failure, and provides default or custom toast/snackbar handling.


πŸ”‘ Features #

  • Open Paystack Checkout with customer details and amount.
  • Supports transactions in NGN (default) or other currencies.
  • Handle events:
    • βœ… Payment Success
    • ❌ Payment Failure
  • Generates a unique transaction reference automatically.
  • Custom or default toast/snackbar handling.
  • Exposes callbacks for API calls after events.

βš™οΈ Methods #

1. openPaystack({...})

Opens the Paystack checkout screen.

Parameters:

  • context: Flutter BuildContext (required for navigation).
  • secretKey: Paystack Secret Key.
  • customerEmail: Customer email ID.
  • amount: Payment amount in kobo (₦200 = 20000).
  • currency: (Optional) Currency code (default "NGN").
  • callbackUrl: (Optional) Callback URL (default: "https://google.com").
  • paymentGatewayName: Gateway name for logs/toast (default "Pay stack").
  • onShowToast: (Optional) Custom toast/snackbar/dialog handler.
  • onPaymentSuccess: (Optional) Callback when payment succeeds.
  • onPaymentFailure: (Optional) Callback when payment fails.

πŸ”„ Flow of Paystack Payment #

  1. Generate unique transaction reference.
  2. Open Paystack Checkout with amount, currency, and customer details.
  3. Handle events:
    • βœ… Success β†’ IncodesListener().onSuccess() with payment reference.
    • ❌ Failure β†’ IncodesListener().onFailure() with error reason.
  4. Callbacks (onPaymentSuccess, onPaymentFailure) are triggered if provided.

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

🌍 Flutterwave Payment Integration #

This module integrates Flutterwave using the flutterwave_standard package.

It manages checkout with Flutterwave, supports multiple payment options, and handles success/failure with default or custom toast/snackbar handling.


πŸ”‘ Features #

  • Open Flutterwave Checkout with customer details and amount.
  • Supports multiple payment methods: USSD, Card, Barter, Pay Attitude, etc.
  • Handle events:
    • βœ… Payment Success
    • ❌ Payment Failure
  • Generates a unique transaction reference automatically.
  • Works in Test Mode or Live Mode.
  • Custom or default toast/snackbar handling.
  • Exposes callbacks for API calls after events.

βš™οΈ Methods #

1. openFlutterWave({...})

Opens the Flutterwave checkout screen.

Parameters:

  • context: Flutter BuildContext (required for navigation).
  • publicKey: Flutterwave Public Key.
  • currency: Currency code (e.g., "NGN", "USD").
  • amount: Payment amount as a string.
  • customerName: Full name of the customer.
  • customerEmail: Customer email address.
  • customerPhone: (Optional) Customer phone number.
  • redirectUrl: (Optional) Callback redirect URL (default "https://www.google.cn/").
  • paymentOptions: Payment methods (default "ussd, card, barter, pay attitude").
  • title: Title displayed on the checkout screen (default "Payment SDK").
  • paymentGatewayName: Gateway name for logs/toast (default "Flutter wave").
  • isTestMode: (Optional) Boolean to enable test mode (default true).
  • onShowToast: (Optional) Custom toast/snackbar/dialog handler.
  • onPaymentSuccess: (Optional) Callback when payment succeeds.
  • onPaymentFailure: (Optional) Callback when payment fails.

πŸ”„ Flow of Flutterwave Payment #

  1. Create Customer object with name, email, phone.
  2. Generate unique transaction reference (TX-...).
  3. Open Flutterwave Checkout with payment options and amount.
  4. Handle events:
    • βœ… Success β†’ IncodesListener().onSuccess() with transaction ID.
    • ❌ Failure β†’ IncodesListener().onFailure() with error reason.
  5. Callbacks (onPaymentSuccess, onPaymentFailure) are triggered if provided.

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

πŸ’³ Cashfree Payment Integration #

This module integrates Cashfree using the flutter_cashfree_pg_sdk package.

It creates a payment session with Cashfree API, opens checkout with multiple payment modes, and handles success/failure events.


πŸ”‘ Features #

  • Open Cashfree Checkout with customer details and amount.
  • Supports multiple payment modes: Card, UPI, NetBanking.
  • Generates a unique session & order ID via Cashfree API.
  • Customizable checkout theme.
  • Handles events:
    • βœ… Payment Success
    • ❌ Payment Failure
  • Sandbox and Production environments supported.
  • Custom or default toast/snackbar handling.
  • Exposes callbacks for API calls after events.

βš™οΈ Methods #

1. openCashfree({...})

Opens the Cashfree checkout screen.

Parameters:

  • context: Flutter BuildContext (required for navigation).
  • clientId: Cashfree Client ID.
  • clientSecret: Cashfree Client Secret.
  • amount: Payment amount (double).
  • currency: Currency code (e.g., "INR").
  • customerName: Full name of the customer.
  • customerEmail: Customer email address.
  • customerPhone: Customer phone number.
  • returnUrl: (Optional) Redirect URL after payment.
  • paymentGatewayName: Gateway name for logs/toast (default "Cashfree").
  • isSandbox: Boolean to enable sandbox mode (default true).
  • onShowToast: (Optional) Custom toast/snackbar/dialog handler.
  • onPaymentSuccess: (Optional) Callback when payment succeeds.
  • onPaymentFailure: (Optional) Callback when payment fails.

πŸ”„ Flow of Cashfree Payment #

  1. Create Payment Session using clientId and clientSecret (API call to Cashfree).
  2. If session created successfully β†’ proceed, else return failure.
  3. Configure Payment Components (Card, UPI, NetBanking).
  4. Set Checkout Theme (colors, fonts).
  5. Build Checkout Payment object.
  6. Set Callbacks:
    • βœ… Success β†’ IncodesListener().onSuccess() with order ID.
    • ❌ Failure β†’ IncodesListener().onFailure() with error message.
  7. Start Payment β†’ Cashfree checkout opens for user.

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

πŸ›’ In-App Purchase (IAP) Integration #

This module integrates In-App Purchases for both Android (Google Play) and iOS (App Store) using the in_app_purchase plugin.

It manages subscriptions, restores purchases, validates receipts (especially for iOS), and handles success/error states.


πŸ”‘ Features #

  • Supports subscriptions & consumables.
  • Works on Android & iOS.
  • Handles purchase states:
    • ⏳ Pending
    • βœ… Success
    • ❌ Error / Canceled
    • πŸ”„ Restored purchases
  • Receipt validation:
    • iOS β†’ Verified with Apple’s production/sandbox servers.
    • Android β†’ Direct purchase validation (with Google).
  • Provides callbacks via IAPCallback.
  • Restores already purchased items.
  • Handles expired and invalid receipts.
  • Includes custom error handling and toast messages.

βš™οΈ Key Classes & Methods #

1. IAPCallback

Defines callback methods for purchase events:

  • onLoaded(bool initialized) β†’ Store initialized.
  • onPending(PurchaseDetails product) β†’ Purchase pending.
  • onSuccessPurchase(PurchaseDetails product) β†’ Successful purchase.
  • onBillingError(dynamic error) β†’ Error occurred.

2. InAppPurchaseHelper

Singleton class to handle all IAP operations.

Important Methods:

  • init({...}) β†’ Initialize with amount, userId, product IDs, etc.
  • initialize() β†’ Setup IAP (Android/iOS).
  • getAlreadyPurchaseItems(IAPCallback) β†’ Attach listener for existing & new purchases.
  • initStoreInfo() β†’ Loads product details from Play Store/App Store.
  • buySubscription(ProductDetails, Map purchases) β†’ Initiates subscription purchase.
  • getPastPurchases(List purchases) β†’ Restores already purchased items.
  • deliverProduct(PurchaseDetails) β†’ Marks product as delivered after verification.
  • clearTransactions() β†’ Clears pending iOS transactions.
  • finishTransaction() β†’ Completes pending transactions on iOS.
  • _verifyProductReceipts() β†’ iOS receipt validation with Apple servers.
  • _getReceiptStatusMessage(int) β†’ Maps Apple receipt error codes to messages.
  • _listenToPurchaseUpdated(List purchases) β†’ Main listener for purchase state changes.

πŸ”„ Flow of In-App Purchase #

  1. Initialize IAP using initialize().
  2. Fetch Product Details from the store using initStoreInfo().
  3. Start Listener with getAlreadyPurchaseItems(callback).
  4. Buy Subscription/Consumable β†’ triggers buySubscription().
  5. Listen for Events:
    • ⏳ Pending β†’ onPending()
    • βœ… Success β†’ Verify receipt β†’ onSuccessPurchase()
    • ❌ Error β†’ onBillingError()
    • πŸ”„ Restored β†’ getPastPurchases()
  6. iOS Receipt Validation:
    • First tries Production server.
    • If error 21007 β†’ retry with Sandbox.
    • Processes receipt data & checks subscription validity.
  7. Deliver Product β†’ If valid, adds purchase to stream & completes transaction.
  8. Clear Pending Transactions for iOS using clearTransactions().

#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

0
likes
120
points
2
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for handling multiple payment gateways including Stripe, Razorpay, PayPal, and more.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

cupertino_icons, dio, flutter, flutter_cashfree_pg_sdk, flutter_paypal_payment, flutter_stripe, fluttertoast, flutterwave_standard, http, in_app_purchase, in_app_purchase_android, in_app_purchase_storekit, pay_with_paystack, razorpay_flutter, uuid

More

Packages that depend on incodes_payment