Last active
September 3, 2015 17:58
-
-
Save matiasgualino/b021cf9fc7f4c549ae83 to your computer and use it in GitHub Desktop.
MercadoPago iOS (Swift) SDK - Vault management with no saved cards, issuers and installments sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import CoreData | |
import MercadoPagoSDK | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
var nav: UINavigationController? | |
func application(application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
self.window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
self.window?.backgroundColor = UIColor.whiteColor() | |
self.nav = UINavigationController() | |
initMercadoPagoVault() | |
self.window?.rootViewController = self.nav | |
self.window?.makeKeyAndVisible() | |
return true | |
} | |
func initMercadoPagoVault() { | |
let supportedPaymentTypes = ["credit_card", "debit_card", "prepaid_card", "ticket", "atm"] | |
let vaultViewController = MercadoPago.startVaultViewController( | |
"444a9ef5-8a6b-429f-abdf-587639155d88", | |
merchantBaseUrl: "https://www.mercadopago.com", | |
merchantGetCustomerUri: "/checkout/examples/getCustomer", | |
merchantAccessToken: "mla-cards-data", | |
amount: 10.0, | |
supportedPaymentTypes: supportedPaymentTypes) { | |
(paymentMethod, tokenId, issuerId, installments) -> Void in | |
let alert = UIAlertController() | |
alert.title = "Payment Info" | |
alert.message = "Token = \(tokenId). \n " | |
+ "Payment method = \(paymentMethod.toJsonString()). \n" | |
+ "Installments = \(installments!). " | |
+ "IssuerId = \(issuerId != nil ? issuerId! : issuerId)" | |
alert.addAction(UIAlertAction(title: "Finish", | |
style: .Default, handler: { action in | |
switch action.style{ | |
case .Default: | |
self.nav!.popToRootViewControllerAnimated(true) | |
self.nav!.popViewControllerAnimated(true) | |
self.initMercadoPagoVault() | |
case .Cancel: | |
println("cancel") | |
case .Destructive: | |
println("destructive") | |
} | |
})) | |
self.nav!.presentViewController(alert, animated: true, completion: nil) | |
} | |
// Put vaultController at the top of navigator. | |
self.nav!.pushViewController(vaultViewController, animated: false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment