Flutter Package
Flutter Package — Merchant installation and setup
Overview
Libyan Payments for MyPay (libyan_payments_for_mypay) adds native in-app checkout to your iOS and Android Flutter apps so customers can pay with local Libyan methods without leaving your app. Your merchant backend creates the payment and opens a Native Checkout session; the app receives only session credentials. Final order status comes from a signed webhook, not from the checkout UI alone.
Guide version: 1.0.4 (aligned with package libyan_payments_for_mypay 1.0.4).
Requirements
| Requirement | Detail |
|---|---|
| Flutter | 3.24 or newer |
| Dart SDK | 3.10 or newer |
| Android | Host Activity should be a FlutterFragmentActivity |
| iOS | Deployment target 15.0 or newer |
| Merchant backend | A server you control that can call the MyPay Pay API with your secrets (never embed secrets in the app) |
| HTTPS | Strongly recommended for production webhook delivery |
| MyPay merchant account | Active, with API and gateway access enabled |
What you need from the MyPay dashboard
Before integrating the package, prepare the following in your MyPay merchant dashboard:
- Client ID and Secret ID (integration / API credentials) — used only on your backend.
- Webhook URL and Webhook Secret (used to verify signatures on incoming webhook requests).
- Enable the payment gateways you want to offer in MyPay gateway settings (aliases such as Banking card
moamalat,sadad,edfali).
Architecture and security
Merchant backend Flutter app (libyan_payments_for_mypay)
──────────────── ──────────────────────────
1. POST /authentication/token
2. POST /payment/create
3. POST /checkout/sessions (mode: native)
→ session_id + session_token ──────► 4. MyPayCheckout.present / Client
5. Signed webhook (source of truth) ◄─── UI success is UX only
[!IMPORTANT] Never put
client_id,secret_id, or webhook secrets in the Flutter app or in the package configuration. Pass onlysession_idandsession_tokento the device. After the session is open, the package authenticates withX-MyPay-Session-Token— do not put the payment access token on the device.
[!WARNING] UI success, deep links, and in-app result screens are not fulfillment authority. Confirm paid status with a signed webhook (
X-MyPay-Signature) before fulfilling the order. See Webhooks.
Backend prerequisites (Native Checkout)
On your server, for each order:
- Obtain an access token — see Authentication.
- Create the payment — see Payments (
POST /payment/create). Keepreturn_url/cancel_url(required by the API even for native apps; you may use deep links or backend URLs). - Open a native session — see Payments → Native Checkout Session:
POST /checkout/sessions
Authorization: Bearer {access_token}
Content-Type: application/json
{
"payment_token": "ABC123XYZ789",
"mode": "native"
}
- Return only
session_idandsession_tokenfrom that response to your Flutter app (over your own authenticated API).
[!NOTE] Use the same environment for backend and app: production base
https://mypay.ly/pay/api/v1/or sandboxhttps://mypay.ly/pay/sandbox/api/v1/, matched withMyPayEnvironment.productionorMyPayEnvironment.sandbox.
Installation steps
1) Add the package
In your app pubspec.yaml:
dependencies:
libyan_payments_for_mypay: ^1.0.4
Then run flutter pub get.
Package on pub.dev: libyan_payments_for_mypay.
2) Platform hosts
- Android: Use
FlutterFragmentActivityas the embedding activity. - iOS: Set the deployment target to 15.0+.
MyPay and gateway marks are bundled inside the package. Keep your own brand logo in your app chrome — the package does not display a merchant logo.
Configuration — Themed UI
Your app chooses the gateway alias (there is no in-package gateway picker). Present checkout after your backend returns session credentials:
final result = await MyPayCheckout.present(
context: context,
sessionId: session.sessionId,
sessionToken: session.sessionToken,
environment: MyPayEnvironment.sandbox,
gatewayAlias: 'sadad', // chosen in your app
locale: const Locale('ar'),
theme: const MyPayCheckoutTheme(
primaryColor: Color(0xFF0B6E4F),
showMyPayBadge: true, // package MyPay mark + “Powered by MyPay”
),
// Optional UX helpers only — not fulfillment:
// successDeepLink: Uri.parse('myapp://payment/success'),
// cancelDeepLink: Uri.parse('myapp://payment/cancel'),
);
if (result.isSuccess) {
await merchantApi.refreshOrder(orderId); // still confirm via webhook
}
Theme and strings
MyPayCheckoutTheme: colors, border radius,showMyPayBadge.locale: e.g.Locale('ar')for Arabic UI copy; you can also supply customMyPayCheckoutStrings(includingMyPayCheckoutStrings.ar).
Headless / custom UI (optional)
For a fully custom payment screen, use MyPayCheckoutClient:
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');
// Call dispose() when finished.
[!IMPORTANT] Banking card (alias
moamalat): Always use the package card path — themed UI, or headlesspayWithMoamalatSdk. 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. 3-D Secure uses an in-app WebView only when required.
Masrafi Pay, Yasr Pay, and Sahara Pay in the themed UI (masrafi-pay, yasr-pay, sahary-pay) use identity / purchase-code entry only.
How payments are confirmed
- Closing the checkout sheet or opening a success deep link is not enough on its own to finalize an order safely.
- The authoritative source for final payment status is a signed webhook from MyPay (
X-MyPay-Signature). See Webhooks. - Match the order using the
customvalue you sent inpayment/create, then fulfill on your backend.
Sandbox testing
- Use sandbox API credentials and
MyPayEnvironment.sandboxin the app. - Open a native session against the sandbox base URL.
- Use the sandbox test cards, mobiles, purchase codes, and OTP values from Test Data (success OTP is
111111for the documented success cases). Covers banking card (moamalat), SADAD, Edfali, Mobicash, and MITF aliases. - For Banking card in sandbox: select alias
moamalat, pay on the package card form, complete optional 3DS with OTP111111, then confirm the webhook shows paid. Failure cases (insufficient funds / provider error / timeout) are listed in Test Data.
[!TIP] If the session expires mid-flow (
expires_infrom open session is typically up to 600 seconds), create a new payment token and open a new native session — do not reuse an expiredsession_token.
Supported gateways (aliases)
Pass these aliases as gatewayAlias (themed UI) or to selectGateway (headless). The gateway must also be enabled on your merchant account.
| Alias | Method |
|---|---|
moamalat |
Banking card |
masrafi-pay |
Masrafi Pay |
yasr-pay |
Yasr Pay |
sahary-pay |
Sahara / Sahary Pay |
edfali |
Edfali |
sadad |
SADAD |
mobicash |
Mobicash |
Gateway logos for these aliases are bundled in the package. Hosted-only methods (for example prepaid card redirect) are outside this native package flow.
Troubleshooting
| Issue | What to check |
|---|---|
| Session or auth errors in the app | Backend opened /checkout/sessions with mode: "native", and the app uses the matching sandbox/production environment |
| Gateway not available | Alias enabled in MyPay gateway settings; check available_gateways in the session open response |
| Order does not complete after a successful UI | Webhook Secret matches, HTTPS is available, and nothing blocks POST to your webhook URL; do not fulfill on UI success alone |
| Sandbox vs production errors | Align dashboard keys, backend base URL, and MyPayEnvironment |
| Android activity issues | Switch the host to FlutterFragmentActivity |
| iOS build / embed issues | Raise the deployment target to 15.0+ |
Privacy and tracking (summary)
- Operational tracking on MyPay’s side is limited (for example connectivity checks, webhook health, and compliance-related support), per platform policy.
- Banking card data is entered in the package UI and must not be stored or relayed by your merchant backend.
- Prefer confirming fulfillment from signed webhooks rather than storing raw payment credentials on the device.
Related docs
- Authentication
- Payments
- Webhooks
- Test Data
- WooCommerce — WordPress plugin (hosted checkout + webhook)
- Odoo — Odoo 18 modules (hosted checkout + Status / optional webhook)