https://github.com/minhvn/momo.vn
Using Payment App In App with MoMo
https://github.com/minhvn/momo.vn
appinapp momo momoapi payment
Last synced: 5 months ago
JSON representation
Using Payment App In App with MoMo
- Host: GitHub
- URL: https://github.com/minhvn/momo.vn
- Owner: minhvn
- License: mit
- Created: 2020-05-01T04:55:32.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-09-05T08:51:04.000Z (over 3 years ago)
- Last Synced: 2023-08-20T22:33:46.771Z (almost 3 years ago)
- Topics: appinapp, momo, momoapi, payment
- Language: Swift
- Size: 138 KB
- Stars: 16
- Watchers: 1
- Forks: 20
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# momo_vn
## Getting Started
* Need register your application at momo business home page : https://business.momo.vn, detail: https://developers.momo.vn/#/home?id=t%c3%a0i-kho%e1%ba%a3n-doanh-nghi%e1%bb%87p
* Download testapp, test account at: https://developers.momo.vn/#/docs/testing_information
### 1. Android set up:
* Step 1: Request Internet permission at ```AndroidManifest.xml``` file:
```xml
```
### 2. iOS set up:
* Step 1: Update ```Info.plist``` file as below:
```xml
CFBundleURLTypes
CFBundleURLName
CFBundleURLSchemes
partnerSchemeId
LSApplicationQueriesSchemes
momo
NSAppTransportSecurity
NSAllowsArbitraryLoads
```
* Step 2: Define call back url for momo at ```AppDelegate.swift ``` file:
```swift
import momo_vn
```
```swift
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
}
```
### See more setup at: https://developers.momo.vn/#/
## Usage
* Import
```Dart
import 'package:momo_vn/momo_vn.dart';
```
* Init
```Dart
void initState() {
super.initState();
_momoPay = MomoVn();
_momoPay.on(MomoVn.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_momoPay.on(MomoVn.EVENT_PAYMENT_ERROR, _handlePaymentError);
initPlatformState();
}
```
* Create data Object
```Dart
MomoPaymentInfo options = MomoPaymentInfo(
merchantname: "Tên đối tác",
merchantcode: 'Mã đối tác',
appScheme: "1221212",
amount: 6000000000,
orderId: '12321312',
orderLabel: 'Label để hiển thị Mã giao dịch',
merchantnamelabel: "Tiêu đề tên cửa hàng",
fee: 0,
description: 'Mô tả chi tiết',
username: 'Định danh user (id/email/...)',
partner: 'merchant',
extra: "{\"key1\":\"value1\",\"key2\":\"value2\"}",
isTestMode: true
);
```
* Open MoMo application
```Dart
try {
_momoPay.open(options);
} catch (e) {
debugPrint(e);
}
```
* Get result
```Dart
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);
}
```