๐ Flutter Paymob โ Native Paymob Checkout for Flutter
Accept cards and mobile wallets with Paymob's official native Android & iOS SDKs and the Intention API.
Version 2 replaces the old iframe/WebView flow with Paymob's native checkout screens. Coming from 1.x? See Migrating from 1.x.
๐ฅ Installation
dependencies:
flutter_paymob: ^2.0.0
The Paymob Android SDK (1.10.1) and PaymobSDK.xcframework are bundled in the package โ nothing else to download.
Android setup
-
minSdk 23 and data binding in
android/app/build.gradle(.kts):android { defaultConfig { minSdk = 23 } buildFeatures { dataBinding = true } } -
MainActivitymust extendFlutterFragmentActivity:import io.flutter.embedding.android.FlutterFragmentActivity class MainActivity : FlutterFragmentActivity() -
The plugin registers its bundled SDK repo and JitPack automatically. If your
settings.gradleusesRepositoriesMode.FAIL_ON_PROJECT_REPOS, add them there yourself:dependencyResolutionManagement { repositories { google() mavenCentral() maven { url = uri("https://jitpack.io") } // path of flutter_paymob in your pub cache / checkout: maven { url = uri("<flutter_paymob path>/android/libs") } } }
ProGuard/R8 rules for the SDK ship with the plugin.
iOS setup
Minimum iOS 15.0. In ios/Podfile:
platform :ios, '15.0'
then run cd ios && pod install.
๐ Paymob keys
From the Paymob dashboard:
| Key | Where | Example |
|---|---|---|
| Public key | Settings โ Account info | egy_pk_test_... |
| Secret key | Settings โ Account info | egy_sk_test_... |
| Integration IDs | Developers โ Payment Integrations | 123456 |
โ ๏ธ The secret key must not ship in a production app. Create the intention on your backend and send only the
client_secretto the app (Production flow). PassingsecretKeyto the app is fine for testing and prototypes.
๐ง Initialize
void main() {
WidgetsFlutterBinding.ensureInitialized();
FlutterPaymob.instance.initialize(
publicKey: 'egy_pk_test_...',
secretKey: 'egy_sk_test_...', // testing only โ see above
cardIntegrationId: 123456,
walletIntegrationId: 654321,
region: PaymobRegion.egypt, // saudiArabia, uae, oman, pakistan
customization: const PaymobCustomization(
appName: 'My Store',
buttonBackgroundColor: Colors.deepPurple,
buttonTextColor: Colors.white,
),
);
runApp(const MyApp());
}
โก Usage
Pay with card ๐ณ
final result = await FlutterPaymob.instance.payWithCard(
amount: 150, // 150.00 EGP
currency: 'EGP',
billingData: BillingData(
firstName: 'Ahmed',
lastName: 'Hosni',
email: 'ahmed@example.com',
phoneNumber: '+201010101010',
),
);
if (result.isSuccessful) {
print('๐ Paid, transaction ${result.transactionID}');
}
Pay with wallet ๐ฑ
The user enters the wallet number in Paymob's screen.
final result = await FlutterPaymob.instance.payWithWallet(amount: 150);
All payment methods in one screen
final result = await FlutterPaymob.instance.checkout(
amount: 150,
integrationIds: [123456, 654321], // default: card + wallet from initialize()
);
All three also accept items, extras, specialReference, notificationUrl, customization and an onPayment callback.
๐ Production flow (recommended)
-
Your backend calls Paymob:
POST https://accept.paymob.com/v1/intention/ Authorization: Token <SECRET_KEY> Content-Type: application/json { "amount": 15000, "currency": "EGP", "payment_methods": [123456, 654321], "items": [], "billing_data": { "first_name": "Ahmed", "last_name": "Hosni", "email": "...", "phone_number": "..." }, "notification_url": "https://your-backend.com/paymob/webhook" }and returns the
client_secretfrom the response to the app. -
The app opens the checkout:
FlutterPaymob.instance.initialize(publicKey: 'egy_pk_live_...'); final result = await FlutterPaymob.instance.pay(clientSecret: clientSecretFromBackend);
๐ก PaymobPaymentResult
| Field | Type | Meaning |
|---|---|---|
status |
PaymentStatus |
successful, failure, cancelled, pending |
isSuccessful / isFailure / isCancelled / isPending |
bool |
Shortcuts for status |
transactionID |
String? |
Paymob transaction id |
responseCode |
String? |
txn_response_code |
amountCents |
int? |
Amount charged |
message |
String? |
data.message, or the error message |
transactionDetails |
Map<String, dynamic>? |
Everything Paymob returned (on success) |
errorMessage |
String? |
Why it failed |
switch (result.status) {
case PaymentStatus.successful: /* show receipt */ break;
case PaymentStatus.pending: /* wait for webhook */ break;
case PaymentStatus.cancelled: /* user closed it */ break;
case PaymentStatus.failure: print(result.message); break;
}
Network / API errors while creating an intention throw a PaymobException.
๐จ PaymobCustomization
| Option | Platform | Description |
|---|---|---|
appName |
both | Name at the top of the checkout |
androidAppLogo |
Android | Drawable / mipmap name, e.g. "ic_launcher" |
iosAppLogo |
iOS | Flutter asset key ("assets/logo.png") or asset-catalog name |
buttonBackgroundColor / buttonTextColor |
both | Pay button colours |
showSaveCard / saveCardDefault |
both | "Save card" checkbox |
showTransactionResult |
both | Show Paymob's result screen before returning |
failureCallBackVersion |
both | V1 (default) or V2 |
isKeyboardHandlingEnabled |
iOS | Let the SDK avoid the keyboard |
Set a default in initialize() or override per payment.
๐ Migrating from 1.x
| 1.x | 2.x |
|---|---|
initialize(apiKey:, integrationID:, walletIntegrationId:, iFrameID:) |
initialize(publicKey:, secretKey:, cardIntegrationId:, walletIntegrationId:) |
payWithCard(context:, currency:, amount:, onPayment:) |
payWithCard(amount:, currency:, onPayment:) โ returns the result too |
payWithWallet(context:, number:, ...) |
payWithWallet(amount:, ...) โ number is typed in Paymob's screen |
title, logo, appBarColor |
PaymobCustomization |
PaymentPaymobResponse |
PaymobPaymentResult (success, transactionID, message still work) |
Also: Android MainActivity โ FlutterFragmentActivity, dataBinding = true, minSdk 23; iOS 15.0.
๐งช Test data
| Type | Number | Expiry | CVV | OTP / PIN |
|---|---|---|---|---|
| Card | 5123 4567 8901 2346 | 12/30 | 123 | โ |
| Wallet | 01010101010 | โ | โ | 123456 |
Use your test public/secret keys and test integration IDs.
๐จ Notes
- Always confirm payments on your backend with Paymob's webhook (
notification_url) and HMAC. The in-app result is for UI only. - When you pass
items, their total must equalamount. - Only one checkout can be open at a time.
๐ ๏ธ Troubleshooting
- Android:
Could not find com.paymob.sdk:Paymob-SDKโ yoursettings.gradleblocks project repositories; add the repos from the Android setup step 3. - Android crash when opening checkout โ
MainActivitymust extendFlutterFragmentActivity, anddataBindingmust be on. - iOS: deployment target error โ set
platform :ios, '15.0'and runpod installagain. failureright away โ check the public key matches the account/region that created the intention, and that the intention hasn't expired.
๐ Links
๐ Contact
The bundled Paymob native SDKs are ยฉ Paymob, distributed under the MIT license of PaymobAccept/flutter_sdk.
Libraries
- billing_data
- flutter_paymob
- Paymob payments for Flutter through the native Paymob Android & iOS SDKs.
- paymob_customization
- paymob_intention
- paymob_response