paymob_flutter 0.1.4
paymob_flutter: ^0.1.4 copied to clipboard
A Flutter SDK for Paymob payment gateway. Supports Card (WebView & Direct API), Mobile Wallet (Vodafone Cash, Orange Money, Etisalat, WE), and Kiosk (Fawry / Aman) payments.
paymob_flutter #
A Flutter SDK for Paymob payment gateway. Supports Card (WebView & Direct API), Mobile Wallet (Vodafone Cash, Orange Money, Etisalat, WE), and Kiosk (Fawry / Aman) payments.
๐ณ Card API #

๐ Card WebView #

๐ฑ Wallet Payment #

๐ง Kiosk Payment #

โจ What's New in 0.1.3 #
- โ Full dartdoc coverage โ 160/160 pub points
- โ
Fixed
isSandboxโ now correctly switches between sandbox and production URLs - โ
Replaced deprecated
withOpacity()withwithValues(alpha:)throughout - โ
tokenExpirationโ configure payment-key lifetime (default 3600 s) - โ
extraPaymentKeyDataโ merge custom fields into the payment-key request - โ
extraOrderDataโ merge custom fields into the order-registration request - โ
PaymobOrder.merchantOrderIdโ link Paymob orders to your own order IDs - โ
PaymobOrder.deliveryNeededโ control delivery flag per order - โ
OrderItemโ optionaldescription,sku,category, andextrafields - โ
BillingDataโ all address fields are now optional (default'NA'), plusextramap - โ
PaymobServiceis now fully public with dartdocs for advanced use
๐ฆ Installation #
dependencies:
paymob_flutter: ^0.1.3
๐ Quick Start #
import 'package:paymob_flutter/paymob_flutter.dart';
final result = await Paymob.pay(
context: context,
config: PaymobConfig(
apiKey: 'YOUR_API_KEY',
integrationId: 123456,
iframeId: 789,
isSandbox: true,
),
order: PaymobOrder(
amount: 100.0,
currency: 'EGP',
items: [
OrderItem(name: 'Product', amount: 100.0, quantity: 1),
],
),
billing: BillingData(
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
phone: '+201234567890',
),
);
if (result.isSuccess) {
print('Payment ID: ${result.transactionId}');
} else if (result.isPending) {
print('Pending: ${result.transactionId}');
} else if (result.isCancelled) {
print('Cancelled by user');
} else {
print('Failed: ${result.errorMessage}');
}
๐๏ธ Payment Modes #
API Mode (Recommended) #
No WebView โ full native Flutter UI.
PaymobConfig(
apiKey: 'YOUR_API_KEY',
integrationId: 123456,
iframeId: 789,
paymentMode: PaymentMode.api, // default
)
WebView Mode #
Classic Paymob hosted iframe page.
PaymobConfig(
apiKey: 'YOUR_API_KEY',
integrationId: 123456,
iframeId: 789,
paymentMode: PaymentMode.webview,
)
Note: WebView mode only supports Card payments. Wallet and Kiosk always use Direct API regardless of
paymentMode.
๐ณ Adding Wallet Support #
PaymobConfig(
apiKey: 'YOUR_API_KEY',
integrationId: 123456,
walletIntegrationId: 789012,
iframeId: 789,
)
Supported wallets: ๐ฑ Vodafone Cash ยท ๐ Orange Money ยท ๐ Etisalat Cash ยท ๐ต WE Pay
๐ง Adding Kiosk Support #
PaymobConfig(
apiKey: 'YOUR_API_KEY',
integrationId: 123456,
kioskIntegrationId: 345678,
iframeId: 789,
)
Returns a bill reference number โ user pays cash at any Fawry or Aman kiosk.
๐ All Three Methods #
PaymobConfig(
apiKey: 'YOUR_API_KEY',
integrationId: 123456,
walletIntegrationId: 789012,
kioskIntegrationId: 345678,
iframeId: 789,
isSandbox: true,
paymentMode: PaymentMode.api,
)
Bottom sheet will show: Card / Wallet / Kiosk
โ๏ธ Advanced Configuration #
Token expiration #
PaymobConfig(
apiKey: 'YOUR_API_KEY',
integrationId: 123456,
iframeId: 789,
tokenExpiration: 7200, // 2 hours instead of the default 1 hour
)
Extra request fields #
Inject any custom or undocumented Paymob field without modifying the SDK:
PaymobConfig(
apiKey: 'YOUR_API_KEY',
integrationId: 123456,
iframeId: 789,
extraPaymentKeyData: {'lock_order_when_paid': true},
extraOrderData: {'notes': 'VIP customer'},
)
Merchant order ID #
Link Paymob orders back to your own order IDs for reconciliation:
PaymobOrder(
amount: 150.0,
currency: 'EGP',
merchantOrderId: 'MY-ORDER-001',
items: [OrderItem(name: 'Deposit', amount: 150.0, quantity: 1)],
)
Full BillingData example #
BillingData(
firstName: 'Ahmed',
lastName: 'Mohamed',
email: 'ahmed@example.com',
phone: '+201234567890',
city: 'Cairo',
country: 'EGY',
street: 'Tahrir Square',
postalCode: '11511',
extra: {'custom_field': 'value'}, // any extra Paymob billing field
)
๐ฏ Direct Methods #
// Card only
await Paymob.payWithCard(context: context, config: config, order: order, billing: billing);
// Wallet only
await Paymob.payWithWallet(context: context, config: config, order: order, billing: billing);
// Kiosk only
await Paymob.payWithKiosk(context: context, config: config, order: order, billing: billing);
PaymobConfig #
โ๏ธ PaymobConfig Parameters #
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| apiKey | String | โ | โ | Your Paymob API Key |
| integrationId | int | โ | โ | Card integration ID |
| iframeId | int | โ | โ | Iframe ID from dashboard |
| walletIntegrationId | int? | โ | null | Wallet integration ID |
| kioskIntegrationId | int? | โ | null | Kiosk integration ID |
| isSandbox | bool | โ | true | Switch between sandbox / production |
| paymentMode | PaymentMode | โ | api | api (native UI) or webview |
| tokenExpiration | int | โ | 3600 | Payment-key lifetime in seconds |
| extraPaymentKeyData | Map? | โ | null | Extra fields for the payment-key request |
| extraOrderData | Map? | โ | null | Extra fields for the order request |
๐ PaymentResult #
| Property | Type | Description |
|---|---|---|
| isSuccess | bool | Payment completed successfully |
| isPending | bool | Kiosk reference generated / Wallet OTP sent |
| isCancelled | bool | User cancelled |
| transactionId | String? | Transaction ID or Kiosk bill reference |
| errorMessage | String? | Error message if failed |
| rawResponse | Map? | Full Paymob API response |
๐ Getting Paymob Credentials #
- Go to Paymob Dashboard
- API Key โ Settings โ Account Info
- Card Integration ID โ Developers โ Payment Integrations โ Card
- Wallet Integration ID โ Developers โ Payment Integrations โ Wallet
- Kiosk Integration ID โ Developers โ Payment Integrations โ Kiosk
- Iframe ID โ Developers โ Iframes
๐งช Sandbox Test Cards #
| Card | Number | Expiry | CVV |
|---|---|---|---|
| โ Success | 4987654321098769 |
Any future date | Any 3 digits |
| โ Failure | 4111111111111111 |
Any future date | Any 3 digits |
๐จโ๐ป Author #
Abanob Nabeh
๐ License #
MIT License โ feel free to use in commercial projects.