Payment Gateway SDK — Flutter
Integrate DigetPay payments into your Flutter application using the official digetpay_plugin package.
The Flutter SDK (digetpay_plugin) is a pure-Dart package for Android and iOS. It provides DigetPay Hosted Checkout in a WebView, so raw card data stays out of your app, plus direct payment APIs for card, saved-card, Apple Pay and Tamara payments.
Requirements
| Requirement | Supported Version |
|---|---|
| Package | digetpay_plugin 1.0.1 |
| Dart SDK | 3.11 or later |
| Android | Android 7.0+ (API 24+) |
| iOS | iOS 13.0+ |
| Platforms | Android / iOS |
Flutter Web and desktop are not supported in the current SDK version.
Installation
Add the package to your Flutter app:
flutter pub add digetpay_pluginOr add it to your pubspec.yaml:
dependencies:
digetpay_plugin: ^1.0.1Then install the dependencies:
flutter pub getQuick Start
1. Initialize the SDK
Initialize the SDK once when your app starts:
import 'package:digetpay_plugin/digetpay_plugin.dart';
DigetPaySdk.initialize(
apiKey: '<your-mobile-api-key>',
baseUrl: 'https://api.digetpay.com/v1',
);| Parameter | Required | Description |
|---|---|---|
apiKey | Yes | Your mobile API key. Your Test key runs Test Mode and your Live key runs Live Mode. |
baseUrl | Yes | https://api.digetpay.com/v1 for both Test and Live. |
logger | No | A function that receives redacted debug messages. Off by default. It never receives the API key, card data, tokens or request bodies. |
Pass
https://api.digetpay.com/v1asbaseUrl. Your API key decides whether the SDK runs in Test Mode or Live Mode; the URL is the same.
Calling any SDK method before
initialize()throwsDigetPaySdkIsNotInitializedException. Callinginitialize()again replaces the key, for example to switch from your Test key to your Live key.
2. Launch Hosted Checkout
Hosted Checkout is the recommended payment flow:
await DigetPaySdk.checkout()
.setOrder(
DigetPaySaleOrder(
id: orderId,
description: 'Coffee',
currency: 'SAR',
amount: 15,
),
)
.setPayer(
DigetPayPayer(
firstName: 'Ahmed',
lastName: 'Ali',
address: 'King Fahd Road',
country: 'SA',
city: 'Riyadh',
zip: '00000',
email: '[email protected]',
phone: '+966500000000',
),
)
.onSessionCreated((sessionId) {
// Save sessionId with your order
})
.onTransactionSuccess((res) {
// Payment approved: res.paymentDetails
})
.onTransactionFailure((res) {
// Payment failed: res.declineReason, res.status, res.errorCode
})
.onDismiss(() {
// Customer closed the checkout
})
.start(context);The SDK creates the checkout session, opens the DigetPay payment page in a WebView, handles 3-D Secure, checks the payment status, and returns the result to your callbacks.
setResultUrls(successUrl: ..., failureUrl: ...)is optional. Use it only if your merchant account requires specific return URLs.
cardPay()from earlier versions still works but is deprecated. Usecheckout().
Hosted Checkout
The customer enters their card details on the DigetPay payment page, not inside your app.
The SDK handles:
- Checkout session creation
- The hosted payment page
- 3-D Secure
- Payment status check
- Success, failure and cancellation callbacks
The result is decided by a status check, not by the page the WebView lands on.
Do not fulfill an order based on the app callback alone. Save the session ID, and confirm the payment from your backend with
GET /payment/checkout/status?sessionId=...before you fulfill the order.
Payment Results
Exactly one callback fires for each checkout:
| Callback | When it is triggered |
|---|---|
onTransactionSuccess | The status check returned an approved payment. Read res.paymentDetails. |
onTransactionFailure | Any other final result. Read res.declineReason, res.status, res.errorCode. |
onDismiss | The customer closed or left the checkout before a final result |
onSessionCreated fires before the payment page opens and gives you the session ID.
Available Methods
| Method | What it does |
|---|---|
checkout() | Hosted Checkout in a WebView (recommended) |
getCheckoutSessionTransaction(sessionId) | Gets the payment made through a checkout session |
sale(SaleRequest) | Card sale with card details entered in your own UI |
authorize(SaleRequest) | Card authorization (hold) instead of a sale |
tokenizationSale(TokenizationSaleRequest) | Charges a saved card token |
getPaymentStatus(id) | Gets the status of a direct payment |
refundS2s(transactionId, amount) | Full or partial refund of a direct payment |
applePay(ApplePaySaleRequest) | Charges an Apple Pay token |
tamaraSale(TamaraSaleRequest) | Starts a Tamara buy-now-pay-later payment |
completePayment(...) | Runs 3-D Secure or redirect steps in a WebView, then confirms the result |
getPaymentStatus and getCheckoutSessionTransaction return null if the payment is not found or the request fails.
PCI DSS scope.
sale()andauthorize()send the card number and CVV through your app, which increases your PCI DSS responsibilities. Prefercheckout()unless your app has been assessed for the required PCI responsibilities.
Direct Payments and 3-D Secure
sale(), authorize(), tokenizationSale(), applePay() and tamaraSale() return a DigetPayResponse. If the payment needs 3-D Secure or a redirect (needsRedirect is true), pass the response to completePayment():
final res = await DigetPaySdk.sale(SaleRequest(
orderId: orderId,
amount: 10,
currency: 'SAR',
saveToken: false,
customer: Customer(name: 'Ahmed Ali', email: '[email protected]', phone: '+966500000000'),
card: CardDto(
cardNumber: cardNumber,
cardHolder: cardHolder,
cardExpiryMonth: '01',
cardExpiryYear: '2039',
cardCvv: cvv,
),
successUrl: 'https://yourstore.com/payment/success',
failureUrl: 'https://yourstore.com/payment/failure',
));
if (res.needsRedirect) {
final result = await DigetPaySdk.completePayment(
context: context,
response: res,
successUrl: 'https://yourstore.com/payment/success',
failureUrl: 'https://yourstore.com/payment/failure',
);
// result.outcome: approved, declined, pending or dismissed
}The SDK computes the request hash for you.
Declines and HTTP errors do not throw exceptions. They return a
DigetPayResponsewithisSuccessset tofalse. Always check the result.
Saved Cards (Tokenization)
- Make a
sale()withsaveToken: true. - When the payment succeeds, read the token (
TKN-...) from the response card details and store it on your server. - Charge the saved card later with
tokenizationSale(). No card details or hash are needed:
final res = await DigetPaySdk.tokenizationSale(TokenizationSaleRequest(
orderId: newOrderId,
amount: 10,
currency: 'SAR',
token: savedToken,
successUrl: 'https://yourstore.com/payment/callback',
));Use a new orderId for every charge.
saveTokenreplacesrecurringInit, andtokenizationSale()replacesrecurringS2s(), from earlier SDK versions.
A card token can start new charges. Keep it on your server, and never log it or show it in your app.
Apple Pay
Apple Pay is available on iOS with applePay(ApplePaySaleRequest). Create the token from your Apple Pay result with ApplePayToken.fromPayResult(...) or ApplePayToken.fromMap(...).
In Xcode, add the Apple Pay capability to your app (this adds the com.apple.developer.in-app-payments entitlement). Treat the Apple Pay token as a payment credential: do not log or store it.
Refunds
Use refundS2s(transactionId, amount) for full or partial refunds of direct payments. A refund that is accepted is not final yet; confirm it before you mark the order as refunded.
Platform Setup
Android
- Set
minSdkVersionto 24 inandroid/app/build.gradle. - Add the Internet permission to
android/app/src/main/AndroidManifest.xml. Release builds do not include it automatically:
<uses-permission android:name="android.permission.INTERNET"/>iOS
- Set the deployment target to iOS 13.0 or later in
ios/Podfileand on the Runner target. - DigetPay uses HTTPS, so the default App Transport Security settings work. Do not add
NSAllowsArbitraryLoadsin production. - For Apple Pay, add the Apple Pay capability (see above).
Security
- The API key is built into your app and can be extracted. Use a restricted or publishable mobile API key. Never put a server-side secret in the app, and rotate the key if it is exposed.
- Prefer
checkout(): raw card data does not pass through your app. sale()andauthorize()handle raw card data and increase your PCI DSS responsibilities.- Keep card tokens and Apple Pay tokens out of logs and the UI.
- The masked card number is safe to display. The cardholder name and customer details are personal data; limit where you log or store them.
- Keep privileged operations and order fulfillment on your backend.
SDK Versioning
| Item | Current Version |
|---|---|
| Flutter SDK | 1.0.1 |
| Package | digetpay_plugin |
| License | MIT |
| Platforms | Android / iOS |
Upgrading from 0.5.x
| 0.5.x | 1.0.1 |
|---|---|
cardPay() | checkout() (old name still works, deprecated) |
recurringInit | saveToken |
recurringS2s() | tokenizationSale() |
externalPayment() | tamaraSale() |
| Apple Pay not available | applePay() available (new request shape) |
Check the package changelog before upgrading.
Version Compatibility
| Platform | Minimum Version |
|---|---|
| Android | 7.0 / API 24 |
| iOS | 13.0 |
| Flutter Web | Not supported |
| Flutter Desktop | Not supported |
Version and platform requirements may change in future releases.
Full DocumentationThe
digetpay_pluginpackage page has the full API reference, request and response models, and examples.
Related
Updated about 1 month ago

