cashfree-pg-api-contract
Version:
This package contains the contract for Cashfree PG
465 lines (464 loc) • 17.8 kB
JavaScript
"use strict";
// noinspection JSUnusedGlobalSymbols
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CFSubsNBPayment = exports.CFSubsUPIPayment = exports.CFSubsCardPayment = exports.CFSubsNB = exports.CFNBPayment = exports.CFUPIPayment = exports.CFCardPayment = exports.CFUPIIntentCheckoutPayment = exports.CFWebCheckoutPayment = exports.CFSubscriptionCheckoutPayment = exports.CFDropCheckoutPayment = exports.CFWebThemeBuilder = exports.CFIntentThemeBuilder = exports.CFThemeBuilder = exports.CFPaymentComponentBuilder = exports.CFPaymentModes = exports.CFNB = exports.CFUPI = exports.UPIMode = exports.ElementCard = exports.SavedCard = exports.Card = exports.CFSubscriptionSession = exports.CFSession = exports.CFEnvironment = void 0;
var CFEnvironment;
(function (CFEnvironment) {
CFEnvironment["PRODUCTION"] = "PRODUCTION";
CFEnvironment["SANDBOX"] = "SANDBOX";
})(CFEnvironment = exports.CFEnvironment || (exports.CFEnvironment = {}));
var CFSession = /** @class */ (function () {
function CFSession(sessionID, orderID, environment) {
if (sessionID === null || sessionID.trim() === '') {
throw new Error('sessionID cannot be empty');
}
if (orderID === null || orderID.trim() === '') {
throw new Error('orderID cannot be empty');
}
if (environment === null || environment.trim() === '') {
throw new Error('environment cannot be empty');
}
this.payment_session_id = sessionID;
this.orderID = orderID;
this.environment = CFEnvironment[environment];
}
return CFSession;
}());
exports.CFSession = CFSession;
var CFSubscriptionSession = /** @class */ (function () {
function CFSubscriptionSession(subscriptionSessionId, subscriptionId, environment) {
if (subscriptionSessionId === null || subscriptionSessionId.trim() === '') {
throw new Error('subscription_session_id cannot be empty');
}
if (subscriptionId === null || subscriptionId.trim() === '') {
throw new Error('subscription_id cannot be empty');
}
if (environment === null || environment.trim() === '') {
throw new Error('environment cannot be empty');
}
this.subscription_session_id = subscriptionSessionId;
this.subscription_id = subscriptionId;
this.environment = CFEnvironment[environment];
}
return CFSubscriptionSession;
}());
exports.CFSubscriptionSession = CFSubscriptionSession;
var Card = /** @class */ (function () {
function Card(cardNumber, cardHolderName, cardExpiryMM, cardExpiryYY, cardCvv, saveCard) {
if (cardNumber === null || cardNumber.trim() === '') {
throw new Error('cardNumber cannot be empty');
}
if (cardHolderName === null || cardHolderName.trim() === '') {
throw new Error('cardHolderName cannot be empty');
}
if (cardExpiryMM === null || cardExpiryMM.trim() === '') {
throw new Error('cardExpiryMM cannot be empty');
}
if (cardExpiryYY === null || cardExpiryYY.trim() === '') {
throw new Error('cardExpiryYY cannot be empty');
}
if (cardCvv === null || cardCvv.trim() === '') {
throw new Error('cardCvv cannot be empty');
}
this.cardNumber = cardNumber;
this.cardHolderName = cardHolderName;
this.cardExpiryMM = cardExpiryMM;
this.cardExpiryYY = cardExpiryYY;
this.cardCvv = cardCvv;
this.saveCard = saveCard;
}
return Card;
}());
exports.Card = Card;
var SavedCard = /** @class */ (function () {
function SavedCard(instrumentId, cardCvv) {
if (cardCvv === null || cardCvv.trim() === '') {
throw new Error('cardCvv cannot be empty');
}
if (instrumentId === null || instrumentId.trim() === '') {
throw new Error('instrumentId cannot be empty');
}
this.instrumentId = instrumentId;
this.cardCvv = cardCvv;
}
return SavedCard;
}());
exports.SavedCard = SavedCard;
var ElementCard = /** @class */ (function (_super) {
__extends(ElementCard, _super);
function ElementCard(cardHolderName, cardExpiryMM, cardExpiryYY, cardCvv, saveCard) {
return _super.call(this, "CF", cardHolderName, cardExpiryMM, cardExpiryYY, cardCvv, saveCard) || this;
}
return ElementCard;
}(Card));
exports.ElementCard = ElementCard;
var UPIMode;
(function (UPIMode) {
UPIMode["COLLECT"] = "COLLECT";
UPIMode["INTENT"] = "INTENT";
})(UPIMode = exports.UPIMode || (exports.UPIMode = {}));
var CFUPI = /** @class */ (function () {
function CFUPI(mode, id) {
if (mode === null || mode === undefined) {
throw new Error('upi mode cannot be empty. It can be either COLLECT/INTENT');
}
if (id === null || id.trim() === '') {
throw new Error('id cannot be empty');
}
this.mode = mode;
this.id = id;
}
return CFUPI;
}());
exports.CFUPI = CFUPI;
var CFNB = /** @class */ (function () {
function CFNB(bankCode) {
if (bankCode === null || bankCode === undefined) {
throw new Error("bankCode cannot be empty.");
}
this.bankCode = bankCode;
}
return CFNB;
}());
exports.CFNB = CFNB;
var CFPaymentModes;
(function (CFPaymentModes) {
CFPaymentModes["CARD"] = "CARD";
CFPaymentModes["UPI"] = "UPI";
CFPaymentModes["NB"] = "NB";
CFPaymentModes["WALLET"] = "WALLET";
CFPaymentModes["EMI"] = "EMI";
CFPaymentModes["PAY_LATER"] = "PAY_LATER";
CFPaymentModes["PAYPAL"] = "PAYPAL";
})(CFPaymentModes = exports.CFPaymentModes || (exports.CFPaymentModes = {}));
var CFPaymentComponentBuilder = /** @class */ (function () {
function CFPaymentComponentBuilder() {
this.hashset = new Set();
}
CFPaymentComponentBuilder.prototype.enableAllModes = function () {
this.hashset.add(CFPaymentModes.CARD);
this.hashset.add(CFPaymentModes.UPI);
this.hashset.add(CFPaymentModes.NB);
this.hashset.add(CFPaymentModes.WALLET);
this.hashset.add(CFPaymentModes.EMI);
this.hashset.add(CFPaymentModes.PAY_LATER);
this.hashset.add(CFPaymentModes.PAYPAL);
};
CFPaymentComponentBuilder.prototype.build = function () {
if (this.hashset.size === 0) {
this.enableAllModes();
}
return {
hashset: this.hashset
};
};
CFPaymentComponentBuilder.prototype.add = function (cfPaymentModes) {
this.hashset.add(cfPaymentModes);
return this;
};
return CFPaymentComponentBuilder;
}());
exports.CFPaymentComponentBuilder = CFPaymentComponentBuilder;
var CFThemeBuilder = /** @class */ (function () {
function CFThemeBuilder() {
this.navigationBarBackgroundColor = '#6A3FD3';
this.navigationBarTextColor = '#FFFFFF';
this.buttonBackgroundColor = '#6A3FD3';
this.buttonTextColor = '#FFFFFF';
this.backgroundColor = '#FFFFFF';
this.primaryTextColor = '#11385b';
this.secondaryTextColor = '#808080';
}
CFThemeBuilder.prototype.setNavigationBarBackgroundColor = function (value) {
this.navigationBarBackgroundColor = value;
return this;
};
CFThemeBuilder.prototype.setNavigationBarTextColor = function (value) {
this.navigationBarTextColor = value;
return this;
};
CFThemeBuilder.prototype.setButtonBackgroundColor = function (value) {
this.buttonBackgroundColor = value;
return this;
};
CFThemeBuilder.prototype.setButtonTextColor = function (value) {
this.buttonTextColor = value;
return this;
};
CFThemeBuilder.prototype.setPrimaryTextColor = function (value) {
this.primaryTextColor = value;
return this;
};
CFThemeBuilder.prototype.setSecondaryTextColor = function (value) {
this.secondaryTextColor = value;
return this;
};
CFThemeBuilder.prototype.setBackgroundColor = function (value) {
this.backgroundColor = value;
return this;
};
CFThemeBuilder.prototype.build = function () {
return {
navigationBarBackgroundColor: this.navigationBarBackgroundColor,
navigationBarTextColor: this.navigationBarTextColor,
buttonBackgroundColor: this.buttonBackgroundColor,
backgroundColor: this.backgroundColor,
buttonTextColor: this.buttonTextColor,
primaryTextColor: this.primaryTextColor,
secondaryTextColor: this.secondaryTextColor
};
};
return CFThemeBuilder;
}());
exports.CFThemeBuilder = CFThemeBuilder;
var CFIntentThemeBuilder = /** @class */ (function () {
function CFIntentThemeBuilder() {
this.backgroundColor = '#FFFFFF';
this.primaryTextColor = '#11385b';
}
CFIntentThemeBuilder.prototype.setBackgroundColor = function (value) {
this.backgroundColor = value;
return this;
};
CFIntentThemeBuilder.prototype.setPrimaryTextColor = function (value) {
this.primaryTextColor = value;
return this;
};
CFIntentThemeBuilder.prototype.build = function () {
var cfTheme = new CFThemeBuilder().build();
return {
buttonBackgroundColor: cfTheme.buttonBackgroundColor,
buttonTextColor: cfTheme.buttonTextColor,
navigationBarBackgroundColor: cfTheme.navigationBarTextColor,
navigationBarTextColor: cfTheme.navigationBarTextColor,
secondaryTextColor: cfTheme.secondaryTextColor,
backgroundColor: this.backgroundColor,
primaryTextColor: this.primaryTextColor
};
};
return CFIntentThemeBuilder;
}());
exports.CFIntentThemeBuilder = CFIntentThemeBuilder;
var CFWebThemeBuilder = /** @class */ (function () {
function CFWebThemeBuilder() {
this.navigationBarBackgroundColor = '#6A3FD3';
this.navigationBarTextColor = '#FFFFFF';
}
CFWebThemeBuilder.prototype.setNavigationBarBackgroundColor = function (value) {
this.navigationBarBackgroundColor = value;
return this;
};
CFWebThemeBuilder.prototype.setNavigationBarTextColor = function (value) {
this.navigationBarTextColor = value;
return this;
};
CFWebThemeBuilder.prototype.build = function () {
var cfTheme = new CFThemeBuilder().build();
return {
buttonBackgroundColor: cfTheme.buttonBackgroundColor,
buttonTextColor: cfTheme.buttonTextColor,
navigationBarBackgroundColor: this.navigationBarBackgroundColor,
navigationBarTextColor: this.navigationBarBackgroundColor,
secondaryTextColor: cfTheme.secondaryTextColor,
backgroundColor: cfTheme.backgroundColor,
primaryTextColor: cfTheme.buttonTextColor
};
};
return CFWebThemeBuilder;
}());
exports.CFWebThemeBuilder = CFWebThemeBuilder;
var CFDropCheckoutPayment = /** @class */ (function () {
function CFDropCheckoutPayment(session, components, theme) {
this.components = Array.from(new CFPaymentComponentBuilder().build().hashset);
this.theme = new CFThemeBuilder().build();
this.session = session;
if (components !== null) {
this.components = Array.from(components.hashset);
}
if (theme !== null) {
this.theme = theme;
}
}
CFDropCheckoutPayment.prototype.getSession = function () {
return this.session;
};
CFDropCheckoutPayment.prototype.getComponents = function () {
return this.components;
};
CFDropCheckoutPayment.prototype.getTheme = function () {
return this.theme;
};
return CFDropCheckoutPayment;
}());
exports.CFDropCheckoutPayment = CFDropCheckoutPayment;
var CFSubscriptionCheckoutPayment = /** @class */ (function () {
function CFSubscriptionCheckoutPayment(session, theme) {
this.theme = new CFWebThemeBuilder().build();
this.session = session;
if (theme !== null) {
this.theme = theme;
}
}
CFSubscriptionCheckoutPayment.prototype.getSession = function () {
return this.session;
};
CFSubscriptionCheckoutPayment.prototype.getTheme = function () {
return this.theme;
};
return CFSubscriptionCheckoutPayment;
}());
exports.CFSubscriptionCheckoutPayment = CFSubscriptionCheckoutPayment;
var CFWebCheckoutPayment = /** @class */ (function () {
function CFWebCheckoutPayment(session, theme) {
this.theme = new CFWebThemeBuilder().build();
this.session = session;
if (theme !== null) {
this.theme = theme;
}
}
CFWebCheckoutPayment.prototype.getSession = function () {
return this.session;
};
CFWebCheckoutPayment.prototype.getTheme = function () {
return this.theme;
};
return CFWebCheckoutPayment;
}());
exports.CFWebCheckoutPayment = CFWebCheckoutPayment;
var CFUPIIntentCheckoutPayment = /** @class */ (function () {
function CFUPIIntentCheckoutPayment(session, theme) {
this.theme = new CFThemeBuilder().build();
this.session = session;
if (theme !== null) {
this.theme = theme;
}
}
CFUPIIntentCheckoutPayment.prototype.getSession = function () {
return this.session;
};
CFUPIIntentCheckoutPayment.prototype.getTheme = function () {
return this.theme;
};
return CFUPIIntentCheckoutPayment;
}());
exports.CFUPIIntentCheckoutPayment = CFUPIIntentCheckoutPayment;
var CFCardPayment = /** @class */ (function () {
function CFCardPayment(session, card) {
this.session = session;
this.card = card;
}
CFCardPayment.prototype.getSession = function () {
return this.session;
};
CFCardPayment.prototype.getCard = function () {
return this.card;
};
return CFCardPayment;
}());
exports.CFCardPayment = CFCardPayment;
var CFUPIPayment = /** @class */ (function () {
function CFUPIPayment(session, upi) {
this.session = session;
this.upi = upi;
}
CFUPIPayment.prototype.getSession = function () {
return this.session;
};
CFUPIPayment.prototype.getUpi = function () {
return this.upi;
};
return CFUPIPayment;
}());
exports.CFUPIPayment = CFUPIPayment;
var CFNBPayment = /** @class */ (function () {
function CFNBPayment(session, nb) {
this.session = session;
this.nb = nb;
}
CFNBPayment.prototype.getSession = function () {
return this.session;
};
CFNBPayment.prototype.getNb = function () {
return this.nb;
};
return CFNBPayment;
}());
exports.CFNBPayment = CFNBPayment;
var CFSubsNB = /** @class */ (function () {
function CFSubsNB(accountHolderName, accountNumber, accountBankCode, accountType) {
var required = [
[accountHolderName, "accountHolderName"],
[accountNumber, "accountNumber"],
[accountBankCode, "accountBankCode"],
[accountType, "accountType"],
];
for (var _i = 0, required_1 = required; _i < required_1.length; _i++) {
var _a = required_1[_i], value = _a[0], name_1 = _a[1];
if (value == null)
throw new Error("".concat(name_1, " cannot be empty."));
}
this.accountHolderName = accountHolderName;
this.accountNumber = accountNumber;
this.accountBankCode = accountBankCode;
this.accountType = accountType;
}
return CFSubsNB;
}());
exports.CFSubsNB = CFSubsNB;
var CFSubsCardPayment = /** @class */ (function () {
function CFSubsCardPayment(session, card) {
this.session = session;
this.card = card;
}
CFSubsCardPayment.prototype.getSession = function () {
return this.session;
};
CFSubsCardPayment.prototype.getCard = function () {
return this.card;
};
return CFSubsCardPayment;
}());
exports.CFSubsCardPayment = CFSubsCardPayment;
var CFSubsUPIPayment = /** @class */ (function () {
function CFSubsUPIPayment(session, upi) {
this.session = session;
this.upi = upi;
}
CFSubsUPIPayment.prototype.getSession = function () {
return this.session;
};
CFSubsUPIPayment.prototype.getUpi = function () {
return this.upi;
};
return CFSubsUPIPayment;
}());
exports.CFSubsUPIPayment = CFSubsUPIPayment;
var CFSubsNBPayment = /** @class */ (function () {
function CFSubsNBPayment(session, nb) {
this.session = session;
this.nb = nb;
}
CFSubsNBPayment.prototype.getSession = function () {
return this.session;
};
CFSubsNBPayment.prototype.getNb = function () {
return this.nb;
};
return CFSubsNBPayment;
}());
exports.CFSubsNBPayment = CFSubsNBPayment;