UNPKG

nativescript-paystack

Version:

Nativescript integration for Paystack payment platform.

88 lines 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var paystack_common_1 = require("./paystack.common"); var utils_1 = require("tns-core-modules/utils/utils"); var NSPayment = (function (_super) { __extends(NSPayment, _super); function NSPayment() { return _super !== null && _super.apply(this, arguments) || this; } NSPayment.prototype.initialize = function (params) { this._card = PSTCKCardParams.new(); this._card.number = "" + params.number; this._card.cvc = "" + params.cvc; this._card.expYear = +params.year; this._card.expMonth = +params.month; this._transaction = PSTCKTransactionParams.new(); this._transaction.amount = +params.amount; this._transaction.email = params.email; }; NSPayment.prototype.addCustomField = function (name, value) { try { this._transaction.setCustomFieldValueDisplayedAsError(value, name); } catch (error) { throw new Error("An error occured while adding a Custom field"); } return this; }; NSPayment.prototype.addMetadata = function (name, value) { try { this._transaction.setMetadataValueForKeyError(value, name); } catch (error) { throw new Error("An error occured while adding a Metadata"); } return this; }; NSPayment.prototype.charge = function () { var _this = this; return new Promise(function (resolve, reject) { _this._transaction.additionalAPIParameters = NSDictionary.dictionaryWithObjectForKey("true", "enforce_otp"); var App = utils_1.ios.getter(UIApplication, UIApplication.sharedApplication); PSTCKAPIClient.sharedClient().chargeCardForTransactionOnViewControllerDidEndWithErrorDidRequestValidationWillPresentDialogDismissedDialogDidTransactionSuccess(_this._card, _this._transaction, App.keyWindow.rootViewController, function (error, reference) { return reject({ code: error.code, message: error.localizedDescription, reference: reference }); }, function () { }, function () { _this.notify({ eventName: paystack_common_1.Payment.openDialogEvent, object: _this }); }, function () { _this.notify({ eventName: paystack_common_1.Payment.closeDialogEvent, object: _this }); }, function (reference) { return resolve({ reference: reference }); }); }); }; return NSPayment; }(paystack_common_1.Payment)); exports.NSPayment = NSPayment; var NSPaystack = (function (_super) { __extends(NSPaystack, _super); function NSPaystack() { return _super !== null && _super.apply(this, arguments) || this; } NSPaystack.prototype.getPublicKey = function () { return Paystack.defaultPublicKey(); }; NSPaystack.prototype.initialize = function (publicKey) { this.setPublicKey(publicKey); return this; }; NSPaystack.prototype.setPublicKey = function (publicKey) { Paystack.setDefaultPublicKey(publicKey); return this; }; NSPaystack.prototype.payment = function (params) { return new NSPayment(params); }; return NSPaystack; }(paystack_common_1.Common)); exports.NSPaystack = NSPaystack; //# sourceMappingURL=paystack.ios.js.map