Skip to main content

sela_pay 1.0.0 copy "sela_pay: ^1.0.0" to clipboard
sela_pay: ^1.0.0 copied to clipboard

In-app checkout for Sela Pay. Accept Libyan payment methods inside your Flutter app with a ready-made themed sheet or your own UI.

sela_pay #

In-app checkout for Sela Pay. Accept Libyan payment methods inside your Flutter app, with a ready-made checkout you can theme or with your own screens.

  • Payment methods that confirm with a bank code (OTP) are completed entirely inside the app.
  • Bank cards are paid on the bank's own card page, with 3-D Secure, shown in an in-app web view. Card details never pass through your app or your server.
  • Arabic and English, right-to-left aware.

How it works #

  1. Your server creates a checkout session with your secret access token and gets a session_id and a session_token.
  2. Your server gives those two values to the app.
  3. The app presents the checkout.
  4. Sela Pay sends your server a signed payment.success webhook. Fulfil the order then.

The session token can only pay that one order, for the amount your server set. It cannot read your account, refund or transfer. Your secret access token never goes into the app.

Install #

dependencies:
  sela_pay: ^1.0.0

Requires Flutter 3.24 or later. Android minSdkVersion 21 or later, iOS 12 or later (from webview_flutter).

1. Create a session on your server #

curl -X POST https://pay.selapay.ly/api/v1/checkout/sessions \
  -H "Authorization: Bearer $SELA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"amount": "25.00", "invoice_no": "ORDER_12345"}'
{
  "status": 201,
  "result": {
    "session_id": "cs_…",
    "session_token": "cst_…",
    "amount": 25,
    "currency": "LYD",
    "invoice_no": "ORDER_12345",
    "environment": "production",
    "expires_at": "2026-12-04T01:20:00+02:00"
  }
}

A token that starts with sl_test_ creates a sandbox session; one that starts with sl_live_ creates a live one. invoice_no must be unique per order. A session lasts 20 minutes. Optional fields: gateways (a list that limits the methods offered) and lang (ar or en, for the card page).

2. Present the checkout #

import 'package:sela_pay/sela_pay.dart';

final result = await SelaCheckout.present(
  context,
  sessionId: sessionId,
  sessionToken: sessionToken,
);

if (result.isSuccess) {
  // Show a thank-you screen. Fulfil the order from the webhook.
}

result.status is paid, failed or cancelled.

Theme #

Everything you leave out follows your app's ThemeData.

SelaCheckout.present(
  context,
  sessionId: sessionId,
  sessionToken: sessionToken,
  locale: 'ar',
  theme: const SelaCheckoutTheme(
    primary: Color(0xFF0B6E4F),
    onPrimary: Colors.white,
    radius: 14,
    fontFamily: 'Cairo',
    showBadge: false,
  ),
);

Build your own UI #

final client = SelaCheckoutClient(sessionId: sessionId, sessionToken: sessionToken);

final session = await client.load();          // amount, merchant, methods
final method = session.gateways.first;

final next = await client.start(method, mobileNumber: '0912001234');

switch (next) {
  case SelaOtpSent(:final otpLength):
    // Ask the customer for the code, then:
    final result = await client.confirm(code);
  case SelaCardRedirect(:final url, :final returnUrl):
    // Open `url` in a web view. When it navigates to `returnUrl`, close it, then:
    final result = await client.waitForCard();
}

client.close();

Each method lists the customer fields it needs in SelaGateway.fields: mobile_number, identity_card, birth_year. Errors are thrown as SelaPayException with a code such as INVALID_OTP.

Confirm on your server #

The result the app receives is for display. Your server learns about the payment from the signed payment.success webhook, or by asking:

curl https://pay.selapay.ly/api/v1/transaction/ORDER_12345 \
  -H "Authorization: Bearer $SELA_TOKEN"

Test values #

With a sandbox session: mobile number 0912001234, card number 123456789, code 1111 for Edfali and 111111 for the other methods.

Documentation #

https://pay.selapay.ly/docs/mobile-apps/flutter

0
likes
150
points
--
downloads

Documentation

API reference

Publisher

verified publisherselapay.ly

Weekly Downloads

In-app checkout for Sela Pay. Accept Libyan payment methods inside your Flutter app with a ready-made themed sheet or your own UI.

Homepage

Topics

#payments #checkout #libya

License

MIT (license)

Dependencies

flutter, http, webview_flutter

More

Packages that depend on sela_pay