- Step 1: Request Internet permission at
AndroidManifest.xml
file:
<uses-permission android:name="android.permission.INTERNET" />
- Step 1: Update
Info.plist
file as below:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>partnerSchemeId</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>momo</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
- Step 2: Define call back url for momo at
AppDelegate.swift
file:
override func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
MoMoPayment.handleOpenUrl(url: url, sourceApp: sourceApplication!)
return true
}
override func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
MoMoPayment.handleOpenUrl(url: url, sourceApp: "")
return true
}
import 'package:momo_vn/momo_vn.dart';
void initState() {
super.initState();
_momoPay = MomoVn();
_momoPay.on(MomoVn.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_momoPay.on(MomoVn.EVENT_PAYMENT_ERROR, _handlePaymentError);
initPlatformState();
}
MomoPaymentInfo options = MomoPaymentInfo(
merchantname: "momovn",
merchantcode: 'MOMON4SE20220213',
appScheme: "1221212",
amount: 6000000000,
orderId: '12321312',
orderLabel: '0305289153',
merchantnamelabel: "CÔNG TY CỔ PHẦN DỊCH VỤ DI ĐỘNG TRỰC TUYẾN",
fee: 0,
description: 'Mô tả chi tiết',
username: 'Định danh user (id:momovn/email:[email protected])',
partner: '0915101105',
extra: "{\"key1\":\"value1\",\"key2\":\"value2\"}",
isTestMode: true
);
try {
_momoPay.open(options);
} catch (e) {
debugPrint(e);
}
void _setState() {
_payment_status = 'Đã chuyển thanh toán';
if (_momoPaymentResult.isSuccess) {
_payment_status += "\nTình trạng: Thành công.";
_payment_status += "\nSố điện thoại: " + _momoPaymentResult.phonenumber;
_payment_status += "\nExtra: " + _momoPaymentResult.extra;
_payment_status += "\nToken: " + _momoPaymentResult.token;
}
else {
_payment_status += "\nTình trạng: Thất bại.";
_payment_status += "\nExtra: " + _momoPaymentResult.extra;
_payment_status += "\nMã lỗi: " + _momoPaymentResult.status.toString();
}
}
void _handlePaymentSuccess(PaymentResponse response) {
setState(() {
_momoPaymentResult = response;
_setState();
});
Fluttertoast.showToast(msg: "THÀNH CÔNG: " + response.phonenumber, timeInSecForIos: 4);
}
void _handlePaymentError(PaymentResponse response) {
setState(() {
_momoPaymentResult = response;
_setState();
});
Fluttertoast.showToast(msg: "THẤT BẠI: " + response.message.toString(), timeInSecForIos: 4);
}