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:truefor test mode,falsefor 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
- Initialize Stripe with publishable key.
- Create PaymentIntent via Stripe API using secret key.
- Initialize PaymentSheet with PaymentIntent client secret.
- Present PaymentSheet to complete the transaction.
- Handle response:
- β
Success β
IncodesListener().onSuccess() - β Failure/Cancel β
IncodesListener().onFailure()
- β
Success β
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
π³ 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
- Setup checkout options (key, amount, user info, theme, wallets).
- Open Razorpay Checkout.
- Handle events:
- β
Success β
IncodesListener().onSuccess() - β Failure β
IncodesListener().onFailure() - πΌ External Wallet β
IncodesListener().onSuccess()with wallet details
- β
Success β
- 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:truefor sandbox (default),falsefor 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
- Navigate to PayPal Checkout View with given credentials and transactions.
- Process Payment via PayPal UI.
- Handle events:
- β
Success β
IncodesListener().onSuccess() - β Failure β
IncodesListener().onFailure() - π« Cancel β
IncodesListener().onFailure()
- β
Success β
- 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
- Generate unique transaction reference.
- Open Paystack Checkout with amount, currency, and customer details.
- Handle events:
- β
Success β
IncodesListener().onSuccess()with payment reference. - β Failure β
IncodesListener().onFailure()with error reason.
- β
Success β
- 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.com/").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 (defaulttrue).onShowToast: (Optional) Custom toast/snackbar/dialog handler.onPaymentSuccess: (Optional) Callback when payment succeeds.onPaymentFailure: (Optional) Callback when payment fails.
π Flow of Flutterwave Payment
- Create Customer object with name, email, phone.
- Generate unique transaction reference (TX-...).
- Open Flutterwave Checkout with payment options and amount.
- Handle events:
- β
Success β
IncodesListener().onSuccess()with transaction ID. - β Failure β
IncodesListener().onFailure()with error reason.
- β
Success β
- 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 (defaulttrue).onShowToast: (Optional) Custom toast/snackbar/dialog handler.onPaymentSuccess: (Optional) Callback when payment succeeds.onPaymentFailure: (Optional) Callback when payment fails.
π Flow of Cashfree Payment
- Create Payment Session using
clientIdandclientSecret(API call to Cashfree). - If session created successfully β proceed, else return failure.
- Configure Payment Components (Card, UPI, NetBanking).
- Set Checkout Theme (colors, fonts).
- Build Checkout Payment object.
- Set Callbacks:
- β
Success β
IncodesListener().onSuccess()with order ID. - β Failure β
IncodesListener().onFailure()with error message.
- β
Success β
- 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
- Initialize IAP using
initialize(). - Fetch Product Details from the store using
initStoreInfo(). - Start Listener with
getAlreadyPurchaseItems(callback). - Buy Subscription/Consumable β triggers
buySubscription(). - Listen for Events:
- β³ Pending β
onPending() - β
Success β Verify receipt β
onSuccessPurchase() - β Error β
onBillingError() - π Restored β
getPastPurchases()
- β³ Pending β
- iOS Receipt Validation:
- First tries Production server.
- If error
21007β retry with Sandbox. - Processes receipt data & checks subscription validity.
- Deliver Product β If valid, adds purchase to stream & completes transaction.
- Clear Pending Transactions for iOS using
clearTransactions().
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Libraries
- incodes_payment
- incodes_payment_services
- main
- methods/cash_free_payment/cash_free_service
- methods/flutter_wave/flutter_wave_service
- methods/in_app_purchase/iap_callback
- methods/in_app_purchase/iap_receipt_data
- methods/in_app_purchase/in_app_purchase_helper
- methods/in_app_purchase/purchase_request
- methods/pay_stack/pay_stack_payment
- methods/paypal/paypal_service
- methods/razor_pay/razorpay_service
- methods/stripe/stripe_pay_model
- methods/stripe/stripe_service
- model/incodes_payment_response
- user/services/services
- utils/listener