UNPKG

@atomixdesign/nodepay-core

Version:
132 lines (131 loc) 5.29 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Context = void 0; var debug_1 = __importDefault(require("debug")); var log = debug_1.default('nodepay:core'); var _hasOwnProperty = function (object, methodName) { return Object.prototype.hasOwnProperty.call(object, methodName); }; var Context = /** @class */ (function () { function Context(gateway) { this.gateway = gateway; return augmentWithNoSuchMethod(this); } Context.prototype.use = function (adapter) { this.gateway = adapter; }; Object.defineProperty(Context.prototype, "name", { get: function () { return this.gateway.name; }, enumerable: false, configurable: true }); Object.defineProperty(Context.prototype, "shortName", { get: function () { return this.gateway.shortName; }, enumerable: false, configurable: true }); Context.prototype.dispatch = function (methodName, arguments_) { if (_hasOwnProperty(this.gateway.__proto__, methodName)) { return this.gateway.__proto__[methodName].apply(this.gateway, Object.values(arguments_)); } throw new Error("Method not implemented: " + methodName + ", class " + this.gateway.constructor.name); }; Context.prototype.createBankAccount = function (bankAccount) { log("calling createBankAccount on " + this.gateway.constructor.name); log({ bankAccount: bankAccount }); return this.dispatch('createBankAccount', { bankAccount: bankAccount }); }; Context.prototype.addCustomer = function (customerDetails, creditCard, bankAccount) { log("calling addCustomer on " + this.gateway.constructor.name); log({ customerDetails: customerDetails }); log({ creditCard: creditCard }); log({ bankAccount: bankAccount }); return this.dispatch('addCustomer', { customerDetails: customerDetails, creditCard: creditCard, bankAccount: bankAccount, }); }; Context.prototype.updateCustomer = function (reference, customerDetails, creditCard, bankAccount) { log("calling updateCustomer on " + this.gateway.constructor.name); log({ reference: reference }); log({ customerDetails: customerDetails }); log({ creditCard: creditCard }); log({ bankAccount: bankAccount }); return this.dispatch('updateCustomer', { reference: reference, customerDetails: customerDetails, creditCard: creditCard, bankAccount: bankAccount, }); }; Context.prototype.directDebit = function (directDebitCharge) { log("calling directDebit on " + this.gateway.constructor.name); log({ directDebitCharge: directDebitCharge }); return this.dispatch('directDebit', { directDebitCharge: directDebitCharge, }); }; Context.prototype.charge = function (onceOffCharge, creditCard) { log("calling charge on " + this.gateway.constructor.name); log({ onceOffCharge: onceOffCharge }); log({ creditCard: creditCard }); return this.dispatch('charge', { onceOffCharge: onceOffCharge, creditCard: creditCard, }); }; Context.prototype.chargeRecurring = function () { var arguments_ = []; for (var _i = 0; _i < arguments.length; _i++) { arguments_[_i] = arguments[_i]; } log("calling chargeRecurring on " + this.gateway.constructor.name); log({ arguments_: arguments_ }); return this.dispatch('chargeRecurring', __assign({}, arguments_)); }; Context.prototype.__noSuchMethod__ = function (name, arguments_) { log('warning: no such method on standard interface'); log("non-standard method " + name + " called on " + this.gateway.constructor.name); log('attempting dispatch'); return this.dispatch(name, __assign({}, arguments_)); }; return Context; }()); exports.Context = Context; function augmentWithNoSuchMethod(object) { return new Proxy(object, { get: function (target, p) { if (p in target || p in new Promise(function () { })) { return target[p]; } else if (typeof target.__noSuchMethod__ == 'function') { return function () { var arguments_ = []; for (var _i = 0; _i < arguments.length; _i++) { arguments_[_i] = arguments[_i]; } return target.__noSuchMethod__.call(target, p, arguments_); }; } }, }); }