Libyan Payments for MyPay (libyan_payments_for_mypay)
Native in-app MyPay checkout for Flutter (iOS / Android). Your merchant backend holds API secrets; the app only receives a checkout session.
Requirements
- Flutter
>=3.24.0and Dart^3.10.0 - Android: host
Activityshould be aFlutterFragmentActivity - iOS: deployment target 15.0+
- A MyPay merchant account with API credentials and a server you control for Pay API calls
Security
- Never put
client_id,secret_id, or webhook secrets in the app or this package. - Your merchant backend calls Pay API v1 (
authentication/token,payment/create,POST /checkout/sessions) and returns onlysession_id+session_tokento the app. - After the session is open, device calls use
X-MyPay-Session-Tokenonly (no payment access token on device). - UI success is not fulfillment authority — confirm with signed webhooks (
X-MyPay-Signature).
Backend (short)
For each order on your server:
POST /authentication/tokenPOST /payment/createPOST /checkout/sessionswith{ "payment_token": "...", "mode": "native" }- Return only
session_idandsession_tokento the Flutter app
Full API details: Payments (Native Checkout) · Merchant guide: Flutter Package
Install
dependencies:
libyan_payments_for_mypay: ^1.0.3
import 'package:libyan_payments_for_mypay/libyan_payments_for_mypay.dart';
Example
A merchant demo app lives in example/. Paste session_id / session_token from your backend, pick a gateway alias, and call themed checkout:
cd example
flutter pub get
flutter run
See example/README.md.
Payment methods
Gateways available through Native Checkout (alias in parentheses):
| Alias | Method |
|---|---|
moamalat |
Banking card |
sadad |
SADAD |
edfali |
Edfali |
mobicash |
Mobicash |
masrafi-pay |
Masrafi Pay |
yasr-pay |
Yasr Pay |
sahary-pay |
Sahara Pay |
Your app passes the chosen alias as gatewayAlias (the package does not show a gateway picker).
Themed UI
Your app chooses gatewayAlias (there is no in-package gateway picker):
final result = await MyPayCheckout.present(
context: context,
sessionId: session.sessionId,
sessionToken: session.sessionToken,
environment: MyPayEnvironment.sandbox,
gatewayAlias: 'sadad',
locale: const Locale('ar'),
theme: const MyPayCheckoutTheme(
primaryColor: Color(0xFF0B6E4F),
showMyPayBadge: true, // package MyPay mark + “Powered by MyPay”
),
);
if (result.isSuccess) {
await merchantApi.refreshOrder(orderId); // still confirm via webhook
}
Headless client
final client = MyPayCheckoutClient(
sessionId: session.sessionId,
sessionToken: session.sessionToken,
environment: MyPayEnvironment.production,
);
final gateways = await client.listGateways();
await client.selectGateway('sadad');
await client.start(mobile: '0912345678', birthYear: '1990');
await client.confirmOtp('1234');
Banking card (gateway alias moamalat): always use payWithMoamalatSdk (or the themed UI). The package shows a native card form and completes the banking-card steps through the MyPay session. Do not build a custom form that posts card data (PAN/CVV) to your API or to MyPay. 3DS uses an in-app WebView only when required. After 3DS, the package distinguishes paid, failed (issuer/NPG decline), and cancelled (buyer closed the challenge); GET /checkout/sessions/{id} mirrors that status. Fulfill only from a signed webhook.
Branding in this package
- MyPay mark: bundled; shown when
showMyPayBadge: true. - Gateway marks: bundled and shown for the selected
gatewayAlias. - Keep your merchant brand in your own app UI. Do not copy these assets into the host app unless you build a fully custom (headless) UI.
Platform notes
- Android host should use
FlutterFragmentActivity. - iOS deployment target 15.0+.
- Banking card entry uses the package Flutter form (works on iOS Simulator).
- Masrafi Pay, Yasr Pay, and Sahara Pay (
masrafi-pay,yasr-pay,sahary-pay) themed UI uses identity / purchase-code entry only (no in-app QR camera). - Localize banking-card fields and 3DS copy via
MyPayCheckoutStrings(useMyPayCheckoutStrings.aror custom strings forbankingCardNumberHint,bankingCardHolderHint,bankingCardExpiryHint,bankingCardInvalidError,threeDsTitle,continueThreeDs).
AndroidX / AGP 9 and PaySky (NUMO)
The Android plugin still compiles against PaySky’s NUMO PayButton SDK for optional native helpers. That SDK historically pulls older com.android.support / card.io pieces and may declare its own Application in a merged manifest.
Recommended host-app setup on AndroidX + AGP 8/9:
- Keep AndroidX enabled (
android.useAndroidX=true). Enable Jetifier if a transitive support artifact remains (android.enableJetifier=true). - Prefer the package Flutter card form + NPG session APIs (themed UI /
payWithMoamalatSdk) — do not embed PaySky’s own checkout UI. - If manifest merge fails on a custom
Application, resolve withtools:replace="android:name"(or merge rules) on your hostAndroidManifest.xml. - If Gradle still resolves
com.android.support, exclude it in the host app:
configurations.configureEach {
exclude group: "com.android.support"
exclude group: "io.card"
}
Full removal of the NUMO dependency is planned for a later release once the HTTP-only path covers every native helper.
Sandbox
- Banking card end-to-end checklist:
doc/SANDBOX_MOAMALAT.md - Sandbox cards and OTP: Test Data
Docs
License
MIT — see LICENSE.