Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
momodevelopment authored Jun 14, 2018
1 parent 13f6eb3 commit f5a47a2
Showing 1 changed file with 54 additions and 63 deletions.
117 changes: 54 additions & 63 deletions ios/ios-swift-CocoaPods/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# MomoiOSSwiftSdkV2

[![CI Status](http://img.shields.io/travis/momodevelopment/MomoiOSSwiftSdkV2.svg?style=flat)](https://travis-ci.org/momodevelopment/MomoiOSSwiftSdkV2)
[![Version](https://img.shields.io/cocoapods/v/MomoiOSSwiftSdkV2.svg?style=flat)](http://cocoapods.org/pods/MomoiOSSwiftSdkV2)
[![License](https://img.shields.io/cocoapods/l/MomoiOSSwiftSdkV2.svg?style=flat)](http://cocoapods.org/pods/MomoiOSSwiftSdkV2)
[![Platform](https://img.shields.io/cocoapods/p/MomoiOSSwiftSdkV2.svg?style=flat)](http://cocoapods.org/pods/MomoiOSSwiftSdkV2)
[![CI Status](http://img.shields.io/travis/momodevelopment/MomoiOSSwiftSdk.svg?style=flat)](https://travis-ci.org/momodevelopment/MomoiOSSwiftSdkV2)
[![Version](https://img.shields.io/cocoapods/v/MomoiOSSwiftSdk.svg?style=flat)](http://cocoapods.org/pods/MomoiOSSwiftSdk)
[![License](https://img.shields.io/cocoapods/l/MomoiOSSwiftSdk.svg?style=flat)](http://cocoapods.org/pods/MomoiOSSwiftSdk)
[![Platform](https://img.shields.io/cocoapods/p/MomoiOSSwiftSdk.svg?style=flat)](http://cocoapods.org/pods/MomoiOSSwiftSdk)

## Example

Expand All @@ -17,7 +17,7 @@ MomoiOSSwiftSdkV2 is available through [CocoaPods](http://cocoapods.org). To ins
it, simply add the following line to your Podfile:

```ruby
pod 'MomoiOSSwiftSdkV2', :git => 'https://github.com/momodevelopment/MomoiOSSwiftSdkV2.git',:branch => "master"
pod 'MomoiOSSwiftSdk', :git => 'https://github.com/momodevelopment/MomoiOSSwiftSdk.git',:branch => "master"
```

At a minimum, MoMo SDK is designed to work with iOS 8.0 or newest.
Expand All @@ -37,14 +37,13 @@ Step 1. Config file Plist
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.abcFoody.LuckyLuck</string>
<string>momopartner0001</string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.momo.appv2.ios</string>
<string>com.mservice.com.vn.MoMoTransfer</string>
<string>momo</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
Expand All @@ -55,10 +54,16 @@ Step 1. Config file Plist
Step 2. Import SDK
AppDelegate instance
```
import MomoiOSSwiftSdk
open func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
MoMoPayment.sharedInstance.handleOpenUrl(url: url, sourceApp: sourceApplication!)
return true
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
MoMoPayment.handleOpenUrl(url: url, sourceApp: sourceApplication!)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
MoMoPayment.handleOpenUrl(url: url, sourceApp: "")
return true
}
```

Expand All @@ -68,21 +73,51 @@ Step 3. Update Layout Payment
MOMO NOTIFICATION KEYS SHOULD BE REMOVED WHEN THE VIEWCONTROLLERS DEALLOCATING OR DISMISSING COMPLETED
(Notification keys: NoficationCenterTokenReceived , NoficationCenterTokenStartRequest)
```
import MomoiOSSwiftSdk
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(self.NoficationCenterTokenReceived), name:NSNotification.Name(rawValue: "NoficationCenterTokenReceived"), object: nil)
// NotificationCenter.default.addObserver(self, selector: #selector(self.NoficationCenterTokenReceived), name:NSNotification.Name(rawValue: "NoficationCenterTokenReceivedUri"), object: nil)
MoMoPayment.sharedInstance.initMerchant(merchantCode: "SCB01", merchantName: "Manchester United", merchantNameLabel: "Nhà cung cấp")
//STEP 1: addObserver Notification
NotificationCenter.default.addObserver(self, selector: #selector(self.NoficationCenterTokenReceived), name:NSNotification.Name(rawValue: "NoficationCenterTokenReceived"), object: nil)
// NotificationCenter.default.addObserver(self, selector: #selector(self.NoficationCenterTokenReceived), name:NSNotification.Name(rawValue: "NoficationCenterTokenReceivedUri"), object: nil)
//
//STEP 2: INIT MERCHANT AND PAYMENT INFO. YOU CAN MODIFY ANYTIME IF NEED
let paymentinfo = NSMutableDictionary()
paymentinfo["merchantcode"] = "CGV01"
paymentinfo["merchantname"] = "CGV Cinemas"
paymentinfo["merchantnamelabel"] = "Service"
paymentinfo["amount"] = payment_amount
paymentinfo["fee"] = payment_fee_display
paymentinfo["description"] = "Thanh toán vé xem phim"
paymentinfo["extra"] = "{\"key1\":\"value1\",\"key2\":\"value2\"}"
paymentinfo["username"] = payment_userId
paymentinfo["appScheme"] = "momopartnerscheme001" //<partnerSchemeId>: app uniqueueId provided by MoMo , get from business.momo.vn. PLEASE MAKE SURE TO ADD <partnerSchemeId> TO PLIST file ( URL types > URL Schemes ). View more detail on https://github.com/momo-wallet/mobile-sdk/tree/master/ios
MoMoPayment.createPaymentInformation(info: paymentinfo)
initOrderAndButtonAction()
//STEP 3: INIT LAYOUT - ADD BUTTON PAYMENT VIA MOMO
let buttonPay = UIButton()
buttonPay.frame = CGRect(x: 20, y: 200, width: 260, height: 40)
// Button title: ENGLISH = MoMo Wallet , VIETNAMESE = Ví MoMo
buttonPay.setTitle("Pay Via MoMo Wallet", for: .normal)
buttonPay.setTitleColor(UIColor.white, for: .normal)
buttonPay.titleLabel!.font = UIFont.systemFont(ofSize: 15)
buttonPay.backgroundColor = UIColor.purple
// Add Button Action to OPEN MOMO APP
buttonPay.addTarget(self, action: #selector(self.gettoken), for: .touchUpInside) //see @objc func gettoken()
self.view.addSubview(buttonPay)
}
@objc func gettoken() {
MoMoPayment.requestToken()
}
```
#Handle MoMoNotificationReceive
```
@objc func NoficationCenterTokenReceived(notif: NSNotification) {
@objc func NoficationCenterTokenReceived(notif: NSNotification) {
//Token Replied - Call Payment to MoMo Server
print("::MoMoPay Log::Received Token Replied::\(notif.object!)")
lblMessage.text = "RequestToken response:\n \(notif.object as Any)"
Expand Down Expand Up @@ -119,55 +154,11 @@ override func viewDidLoad() {
lblMessage.text = "RequestToken response:\n \(notif.object!) | Fail token. Please check input params "
}
}
```
Add Button Action to Pay Via MOMO
Button title: EN = MoMo Wallet , VI = Ví MoMo
```
func initOrderAndButtonAction() {
//STEP 1: INIT ORDER INFO
NSMutableDictionary *paymentinfo = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:99000],@"amount",
[NSNumber numberWithInt:0],@"fee",
@"Buy CGV Cinemas",@"description",
@"{\"key1\":\"value1\",\"key2\":\"value2\"}",@"extra", //OPTIONAL
@"vi",@"language",
username,@"username",
@"Người dùng",@"usernamelabel",
nil];
MoMoPayment.sharedInstance.setupEnvironment(environment: MoMoConfig.MOMO_ENVIRONEMENT.PRODUCTION)
//Setup amount. YOU CAN UPDATE ANYTIME IF NEED
let paymentinfo = NSMutableDictionary()
paymentinfo["amount"] = payment_amount
paymentinfo["fee"] = payment_fee_display
paymentinfo["description"] = "Buy Vietjet Air Ticket"
paymentinfo["extra"] = "{\"key1\":\"value1\",\"key2\":\"value2\"}"
paymentinfo["username"] = payment_userId
paymentinfo["appScheme"] = "vntrip.vn.app"
MoMoPayment.sharedInstance.createPaymentInformation(info: paymentinfo)
//STEP 2: ADD BUTTON ACTION TO PAY VIA MOMO WALLET
//buttonAction will open MoMo app to pay
let btnPay = UIButton()
btnPay.frame = CGRect(x: 10, y: 100, width: 260, height: 40)
btnPay.setTitle("Pay Via MoMo Wallet", for: .normal)
btnPay.setTitleColor(UIColor.white, for: .normal)
btnPay.titleLabel!.font = UIFont.systemFont(ofSize: 15)
btnPay.backgroundColor = UIColor.purple
//btnPay.addTarget(self, action: #selector(MoMoPayment.sharedInstance.requestToken), for: UIControlEvents.touchUpInside)
//paymentArea.addSubview(btnPay)
btnPay = MoMoPayment.sharedInstance.addMoMoPayCustomButton(button: btnPay, forControlEvents: .touchUpInside, toView: paymentArea)
}
```

## Author

MoMo Development Team

## License

MomoiOSSwiftSdkV2 is available under the MIT license. See the LICENSE file for more info.
MomoiOSSwiftSdk is available under the MIT license. See the LICENSE file for more info.

0 comments on commit f5a47a2

Please sign in to comment.