@martcarrefour/robokassa
Version:
Robokassa Node.JS integration (Note: Original repository is now actively maintained)
61 lines • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Robokassa = void 0;
const calculateSendingSignatureValue_1 = require("./internal/calculateSendingSignatureValue");
const calculateReceivingSignatureValue_1 = require("./internal/calculateReceivingSignatureValue");
//https://docs.robokassa.ru/
class Robokassa {
constructor(options) {
this.options = {
...options,
hashAlgorithm: options.hashAlgorithm ?? 'md5',
url: options.url ?? 'https://auth.robokassa.ru/Merchant/Index.aspx',
isTest: options.isTest ?? false,
};
}
generatePaymentUrl(order) {
if (!order.invId) {
order.invId = 0;
}
if (typeof order.outSum === 'number') {
order.outSum = order.outSum.toFixed(2);
}
const { userParameters, receipt, ...usualOrderParameters } = order;
const orderWithCapitalizedKeys = Object.fromEntries(Object.entries(usualOrderParameters).map(([key, value]) => [
`${key[0].toUpperCase()}${key.slice(1)}`,
value,
]));
const queryParams = {
MerchantLogin: this.options.merchantLogin,
IsTest: this.options.isTest ? 1 : undefined,
...orderWithCapitalizedKeys,
Receipt: receipt ? JSON.stringify(receipt) : undefined,
...userParameters,
SignatureValue: (0, calculateSendingSignatureValue_1.calculateSendingSignatureValue)({
hashAlgorithm: this.options.hashAlgorithm,
merchantLogin: this.options.merchantLogin,
password1: this.options.password1,
order,
}),
};
return `${this.options.url}?${this.queryString(queryParams)}`;
}
checkPayment(response) {
const expectedSignatureValue = (0, calculateReceivingSignatureValue_1.calculateReceivingSignatureValue)({
hashAlgorithm: this.options.hashAlgorithm,
password2: this.options.password2,
response,
});
return (!!response.SignatureValue &&
expectedSignatureValue.toLowerCase() ===
response.SignatureValue.toLowerCase());
}
queryString(queryParams) {
return Object.entries(queryParams)
.filter(([_, value]) => value !== undefined)
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
.join('&');
}
}
exports.Robokassa = Robokassa;
//# sourceMappingURL=Robokassa.js.map