Skip to main content

flutter_paymob 2.0.0 copy "flutter_paymob: ^2.0.0" to clipboard
flutter_paymob: ^2.0.0 copied to clipboard

Accept Paymob card and mobile-wallet payments in Flutter through the official native Paymob Android and iOS SDKs (Intention API).

๐Ÿš€ 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 #

  1. minSdk 23 and data binding in android/app/build.gradle(.kts):

    android {
        defaultConfig {
            minSdk = 23
        }
        buildFeatures {
            dataBinding = true
        }
    }
    
  2. MainActivity must extend FlutterFragmentActivity:

    import io.flutter.embedding.android.FlutterFragmentActivity
    
    class MainActivity : FlutterFragmentActivity()
    
  3. The plugin registers its bundled SDK repo and JitPack automatically. If your settings.gradle uses RepositoriesMode.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_secret to the app (Production flow). Passing secretKey to 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.

  1. 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_secret from the response to the app.

  2. 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 equal amount.
  • Only one checkout can be open at a time.

๐Ÿ› ๏ธ Troubleshooting #

  • Android: Could not find com.paymob.sdk:Paymob-SDK โ€” your settings.gradle blocks project repositories; add the repos from the Android setup step 3.
  • Android crash when opening checkout โ€” MainActivity must extend FlutterFragmentActivity, and dataBinding must be on.
  • iOS: deployment target error โ€” set platform :ios, '15.0' and run pod install again.
  • failure right away โ€” check the public key matches the account/region that created the intention, and that the intention hasn't expired.

๐Ÿ“ž Contact #

Ahmed Hosni - LinkedIn

The bundled Paymob native SDKs are ยฉ Paymob, distributed under the MIT license of PaymobAccept/flutter_sdk.

35
likes
150
points
112
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Accept Paymob card and mobile-wallet payments in Flutter through the official native Paymob Android and iOS SDKs (Intention API).

Repository (GitHub)
View/report issues

Topics

#payments #paymob #payment-gateway

License

GPL-3.0 (license)

Dependencies

flutter, http

More

Packages that depend on flutter_paymob

Packages that implement flutter_paymob