Skip to content

Instantly share code, notes, and snippets.

@maatthc
Created May 3, 2018 08:13
Show Gist options
  • Save maatthc/82ee1038980149f8ae84f9ec5f151731 to your computer and use it in GitHub Desktop.
Save maatthc/82ee1038980149f8ae84f9ec5f151731 to your computer and use it in GitHub Desktop.
var CardIO = null;
try {
CardIO = UIViewController.extend({
setup: function() {
CardIOUtilities.preload();
},
init: function() {
var self = this.super.init();
if (self) {
// The base class initialized successfully
console.log("Initialized");
}
console.log("card IO utilities loaded");
return self;
},
scanCard: function(viewController) {
var self = this;
return new Promise(function (resolve, reject) {
self.resolve = resolve;
self.reject = reject;
var scanViewController = CardIOPaymentViewController.new().initWithPaymentDelegate(self);
scanViewController.delegate = self;
scanViewController.modalPresentationStyle = UIModalPresentationFormSheet;
viewController.presentViewControllerAnimatedCompletion(scanViewController,true,null);
});
},
userDidProvideCreditCardInfoInPaymentViewController: function(info, paymentViewController) {
paymentViewController.dismissViewControllerAnimatedCompletion(true,null);
if(this.resolve) this.resolve(info);
console.log("did receive card number:", info.redactedCardNumber);
},
userDidCancelPaymentViewController: function(paymentViewController) {
debugger;
console.log("cancel");
paymentViewController.dismissViewControllerAnimatedCompletion(true,null);
if(this.reject) this.reject();
}
}, {
name: "CardIO",
protocols: [CardIOPaymentViewControllerDelegate]
});
CardIO.ObjCProtocols = [CardIOPaymentViewControllerDelegate];
} catch (e) {
console.log(e.message);
}
exports.CardIO = CardIO.new();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment