From f5a47a2639aaed301348ed8881c70981ac488b3f Mon Sep 17 00:00:00 2001 From: momodevelopment Date: Thu, 14 Jun 2018 12:41:34 +0700 Subject: [PATCH] Update README.md --- ios/ios-swift-CocoaPods/README.md | 117 ++++++++++++++---------------- 1 file changed, 54 insertions(+), 63 deletions(-) diff --git a/ios/ios-swift-CocoaPods/README.md b/ios/ios-swift-CocoaPods/README.md index ddadb99..afdde5c 100644 --- a/ios/ios-swift-CocoaPods/README.md +++ b/ios/ios-swift-CocoaPods/README.md @@ -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 @@ -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. @@ -37,14 +37,13 @@ Step 1. Config file Plist CFBundleURLSchemes - com.abcFoody.LuckyLuck + momopartner0001 LSApplicationQueriesSchemes - com.momo.appv2.ios - com.mservice.com.vn.MoMoTransfer + momo NSAppTransportSecurity @@ -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 } ``` @@ -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" //: app uniqueueId provided by MoMo , get from business.momo.vn. PLEASE MAKE SURE TO ADD 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)" @@ -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.