Pass Micro Transaction
Platform Support
| Android | iOS |
|---|---|
| âī¸ | âī¸ |
đ¨ Installation
dependencies:
pass_mtx: ^1.0.0
â Import
import 'package:pass_mtx/pass_mtx.dart';
đšī¸ Usage/Example
Initialization & Check connection
Create a PassMtx instance, then initialize it. Use init for the staging
environment while developing and switch to initProd for production. Both take
only your appId and clientId.
import 'package:pass_mtx/pass_mtx.dart';
final passMtxPlugin = PassMtx();
// Initialize for Staging ENV
await passMtxPlugin.init(String appId, String clientId);
// Initialize for Production ENV
await passMtxPlugin.initProd(String appId, String clientId);
// Get Pass API status
await passMtxPlugin.getPassPing();
// Get Pass version info
await passMtxPlugin.getPassVersion();
// Initialization example using 'kReleaseMode'
String passInitResult;
try {
if (kReleaseMode) {
passInitResult = await passMtxPlugin.initProd(appId, clientId) ??
'Unknown platform version';
} else {
passInitResult = await passMtxPlugin.init(appId, clientId) ??
'Unknown platform version';
}
} on PlatformException {
passInitResult = 'Failed to get platform version.';
}
Card Methods
Methods to list, register, configure and delete the cards a user has added to
their PASS wallet.
// Get card tokens by userId
await passMtxPlugin.getCard(String userId);
// Delete a user card
await passMtxPlugin.deleteCard(String userId, String cardRef);
// Set the default card
await passMtxPlugin.setDefaultCard(String userId, String cardRef);
Reading the card list
getCard returns a JSON string. Parse it and read the cards from ret.cards:
final result = await passMtxPlugin.getCard(userId);
if (result != null) {
final resultJson = json.decode(result);
if (resultJson['status_code'] == 'ok') {
for (final card in resultJson['ret']['cards'] as List<dynamic>) {
// card['masked_pan'], card['expire_date'], card['network'], card['card_ref'] ...
}
}
}
Card registration
To register a new card, generate a registration token and open the returned
card form in a WebView. generateCardRegistrationToken takes the userId, a
callbackUrl, and an ECDH (prime256v1) public key in PEM format.
// Generate the card registration token
final result = await passMtxPlugin.generateCardRegistrationToken(
userId,
callbackUrl, // e.g. "http://pass.mn/card-callback/"
ecdhPublicKeyPem, // prime256v1 EC public key, PEM encoded
);
// Extract the token_id and open the card form in a WebView
final tokenId = json.decode(result)['ret']['token_id'].toString();
// https://ecomstg.pass.mn/openapi/inapp/card-form/?token_id=$tokenId
Load the card form with your client/app id headers, and treat the
openapi/v3/inapp/card-success callback path as a successful registration:
WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onPageFinished: (String url) {
if (Uri.parse(url).path.contains('openapi/v3/inapp/card-success')) {
// card registered successfully
}
},
),
)
..loadRequest(Uri.parse(cardFormUrl), headers: {
'Inapp-Client-Id': clientId,
'Inapp-App-Id': appId,
});
Purchase
Direct Purchase
Pass MTX includes the micro transaction method makePassPurchase. The
paymentAmount field must be multiplied by 100 from the original amount. If the
user enters 1000, send 1000 * 100 through paymentAmount.
// Make Pass Purchase
makePassPurchase(String userId, String orderId, String paymentToken, String expDate, String paymentAmount, String dbRefNo, String description)
// Make purchase example
final amount = amountController.text; // e.g. "1000"
final realAmount = (int.parse(amount) * 100).toString();
final now = DateTime.now();
final formattedDate = DateFormat('yyyyMMddHHmmss').format(now);
final orderId = "INAPPV1${now.millisecondsSinceEpoch}";
String passPurchaseResult;
try {
passPurchaseResult = await passMtxPlugin.makePassPurchase(
"1", // userId
orderId, // orderId
tokenController.text, // paymentToken
"2605", // expDate
realAmount, // paymentAmount
"DTB$formattedDate", // dbRefNo
"pass txn test", // description
) ??
'Make Purchase Failed';
} on PlatformException {
passPurchaseResult = 'Failed to get platform version.';
}
Customer Presented Mode Purchase
// Get a CPM QR code for the order
passGetQr(String userId, String orderId, String payToken, String expDate, String ttl)
// Inquire the presented QR scanned by the scanner and get the payment process
orderEnquery(String userId, String orderId)
// Optional: when the amount is above the CVM limit
orderConfirm(
String userId,
String orderId,
String confirmMethod,
String confirmResult,
String payToken,
String expDate)
// Cancel an order by the user
orderCancel(String userId, String orderId)
đ License
/*
#################################################################################
# #
# COPYRIGHT (C) DATABANK LLC since 2017 #
# #
# ALL RIGHTS RESERVED BY DATABANK LLC. THIS PROGRAM MUST BE #
# USED SOLELY FOR THE PURPOSES OF DATABANK LLC AND ITS USERS. #
# NO PART OF THIS PROGRAM MAY BE MODIFIED IN SOURCE OR BINARY FORM BY OTHERS #
# WITHOUT THE PRIOR WRITTEN PERMISSION OF DATABANK LLC. #
# #
# USE OF COPYRIGHT NOTICE DOES NOT EVIDENCE PUBLICATION OF THE PROGRAM. #
# #
#################################################################################
*/