securepay
Version:
https://www.securepay.com.au/
66 lines (65 loc) • 3.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.CardPaymentClient = void 0;
var card_payment_client_callback_events_enum_1 = require("./../enums/card-payment-client-callback-events.enum");
var js_sdk_url_enum_1 = require("../enums/js-sdk-url.enum");
var CardPaymentClient = /** @class */ (function () {
function CardPaymentClient(options) {
var _this = this;
this.securePayUiLoaded = false;
options.callback && (this.callback = options.callback);
this.sandbox = options.sandbox;
this.clientId = options.clientId;
this.merchantCode = options.merchantCode;
this.containerId = options.containerId;
var scriptEl = document.createElement('script');
this.scriptId = 'securepay-js-id-' + new Date().getTime().toString();
scriptEl.id = this.scriptId;
scriptEl.onload = function () {
_this.init();
};
scriptEl.src = this.sandbox ? js_sdk_url_enum_1.JsSdkUrl.SANDBOX_UI : js_sdk_url_enum_1.JsSdkUrl.UI;
document.head.appendChild(scriptEl);
}
/**
* Initial
*/
CardPaymentClient.prototype.init = function () {
var _this = this;
this.securePayUI = new securePayUI.init({
containerId: this.containerId,
scriptId: this.scriptId,
clientId: this.clientId,
merchantCode: this.merchantCode,
card: {
onTokeniseSuccess: function (tokenisedCard) {
_this.callback && _this.callback(card_payment_client_callback_events_enum_1.CardPaymentClientCallbackEvents.ON_TOKENISE_SUCCESS, tokenisedCard);
},
onTokeniseError: function (errors) {
_this.callback && _this.callback(card_payment_client_callback_events_enum_1.CardPaymentClientCallbackEvents.ON_TOKENISE_ERROR, errors);
},
onCardTypeChange: function (cardType) {
_this.callback && _this.callback(card_payment_client_callback_events_enum_1.CardPaymentClientCallbackEvents.ON_CARD_TYPE_CHANGE, cardType);
},
onBINChange: function (cardBIN) {
_this.callback && _this.callback(card_payment_client_callback_events_enum_1.CardPaymentClientCallbackEvents.ON_BIN_CHANGE, cardBIN);
},
onFormValidityChange: function (valid) {
_this.callback && _this.callback(card_payment_client_callback_events_enum_1.CardPaymentClientCallbackEvents.ON_FORM_VALIDITY_CHANGE, valid);
},
},
onLoadComplete: function () {
_this.securePayUiLoaded = true;
_this.callback && _this.callback(card_payment_client_callback_events_enum_1.CardPaymentClientCallbackEvents.ON_LOAD_COMPLETE);
}
});
};
/**
* Fire Tokenise
*/
CardPaymentClient.prototype.tokenise = function () {
this.securePayUI.tokenise();
};
return CardPaymentClient;
}());
exports.CardPaymentClient = CardPaymentClient;
;