momo-payment-gateway
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -7,64 +7,64 @@ export declare class MomoPayment { | ||
constructor({ partnerCode, accessKey, secretKey, endpoint }: { | ||
partnerCode: string; | ||
accessKey: string; | ||
secretKey: string; | ||
endpoint: string; | ||
partnerCode: any; | ||
accessKey: any; | ||
secretKey: any; | ||
endpoint: any; | ||
}); | ||
createPayment({ requestId, orderId, amount, orderInfo, redirectUrl, ipnUrl, extraData }: { | ||
requestId: string; | ||
orderId: string; | ||
amount: number; | ||
orderInfo: string; | ||
redirectUrl: string; | ||
ipnUrl: string; | ||
extraData?: string; | ||
requestId: any; | ||
orderId: any; | ||
amount: any; | ||
orderInfo: any; | ||
redirectUrl: any; | ||
ipnUrl: any; | ||
extraData?: string | undefined; | ||
}): Promise<any>; | ||
refundPayment({ requestId, orderId, amount, transId }: { | ||
requestId: string; | ||
orderId: string; | ||
amount: number; | ||
transId: number; | ||
requestId: any; | ||
orderId: any; | ||
amount: any; | ||
transId: any; | ||
}): Promise<any>; | ||
verifySignature({ signature, requestId, orderId, amount, orderInfo, orderType, transId, message, responseTime, resultCode, payType, extraData, }: { | ||
signature: string; | ||
requestId: string; | ||
orderId: string; | ||
amount: number; | ||
orderInfo: string; | ||
orderType: string; | ||
transId: number; | ||
message: string; | ||
responseTime: number; | ||
resultCode: number; | ||
payType: string; | ||
extraData?: string; | ||
signature: any; | ||
requestId: any; | ||
orderId: any; | ||
amount: any; | ||
orderInfo: any; | ||
orderType: any; | ||
transId: any; | ||
message: any; | ||
responseTime: any; | ||
resultCode: any; | ||
payType: any; | ||
extraData?: string | undefined; | ||
}): boolean; | ||
verifyPayment({ partnerCode, orderId, requestId, amount, orderInfo, orderType, transId, resultCode, message, payType, responseTime, extraData, signature, }: { | ||
partnerCode: string; | ||
orderId: string; | ||
requestId: string; | ||
amount: number; | ||
orderInfo: string; | ||
orderType: string; | ||
transId: number; | ||
resultCode: number; | ||
message: string; | ||
payType: string; | ||
responseTime: number; | ||
extraData: string; | ||
signature: string; | ||
partnerCode: any; | ||
orderId: any; | ||
requestId: any; | ||
amount: any; | ||
orderInfo: any; | ||
orderType: any; | ||
transId: any; | ||
resultCode: any; | ||
message: any; | ||
payType: any; | ||
responseTime: any; | ||
extraData: any; | ||
signature: any; | ||
}): Promise<{ | ||
type: string; | ||
orderId: string; | ||
requestId: string; | ||
amount: number; | ||
orderInfo: string; | ||
orderType: string; | ||
transId: number; | ||
resultCode: number; | ||
message: string; | ||
payType: string; | ||
responseTime: number; | ||
extraData: string; | ||
orderId: any; | ||
requestId: any; | ||
amount: any; | ||
orderInfo: any; | ||
orderType: any; | ||
transId: any; | ||
resultCode: any; | ||
message: any; | ||
payType: any; | ||
responseTime: any; | ||
extraData: any; | ||
}>; | ||
} |
@@ -40,3 +40,3 @@ "use strict"; | ||
exports.MomoPayment = void 0; | ||
var crypto = require("crypto"); | ||
var CryptoJS = require("crypto-js"); | ||
var node_fetch_1 = require("node-fetch"); | ||
@@ -54,3 +54,3 @@ var MomoPayment = /** @class */ (function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestType, rawSignature, signature, res, error_1; | ||
var requestType, rawSignature, createHmacString, signature, res, error_1; | ||
return __generator(this, function (_c) { | ||
@@ -84,6 +84,7 @@ switch (_c.label) { | ||
requestType; | ||
signature = crypto | ||
.createHmac('sha256', this.secretKey) | ||
.update(rawSignature) | ||
.digest('hex'); | ||
createHmacString = function (privateKey, ts) { | ||
var hmac = CryptoJS.HmacSHA256(ts, privateKey).toString(CryptoJS.enc.Hex); | ||
return hmac; | ||
}; | ||
signature = createHmacString(this.secretKey, rawSignature); | ||
return [4 /*yield*/, (0, node_fetch_1.default)("".concat(this.endpoint, "/v2/gateway/api/create"), { | ||
@@ -123,3 +124,3 @@ method: 'POST', | ||
return __awaiter(this, void 0, void 0, function () { | ||
var signatureRaw, signature, res; | ||
var signatureRaw, createHmacString, signature, res; | ||
return __generator(this, function (_b) { | ||
@@ -132,6 +133,7 @@ switch (_b.label) { | ||
signatureRaw = "accessKey=".concat(this.accessKey, "&amount=").concat(amount, "&description=&orderId=").concat(orderId, "&partnerCode=").concat(this.partnerCode, "&requestId=").concat(requestId, "&transId=").concat(transId); | ||
signature = crypto | ||
.createHmac('sha256', this.secretKey) | ||
.update(signatureRaw) | ||
.digest('hex'); | ||
createHmacString = function (privateKey, ts) { | ||
var hmac = CryptoJS.HmacSHA256(ts, privateKey).toString(CryptoJS.enc.Hex); | ||
return hmac; | ||
}; | ||
signature = createHmacString(this.secretKey, signatureRaw); | ||
return [4 /*yield*/, (0, node_fetch_1.default)("".concat(this.endpoint, "/v2/gateway/api/refund"), { | ||
@@ -171,6 +173,7 @@ method: 'POST', | ||
var signatureRaw = "accessKey=".concat(this.accessKey, "&amount=").concat(amount, "&extraData=").concat(extraData, "&message=").concat(message, "&orderId=").concat(orderId, "&orderInfo=").concat(orderInfo, "&orderType=").concat(orderType, "&partnerCode=").concat(this.partnerCode, "&payType=").concat(payType, "&requestId=").concat(requestId, "&responseTime=").concat(responseTime, "&resultCode=").concat(resultCode, "&transId=").concat(transId); | ||
var genSignature = crypto | ||
.createHmac('sha256', this.secretKey) | ||
.update(signatureRaw) | ||
.digest('hex'); | ||
var createHmacString = function (privateKey, ts) { | ||
var hmac = CryptoJS.HmacSHA256(ts, privateKey).toString(CryptoJS.enc.Hex); | ||
return hmac; | ||
}; | ||
var genSignature = createHmacString(this.secretKey, signatureRaw); | ||
return genSignature === signature; | ||
@@ -181,36 +184,32 @@ }; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var signatureRaw, signatureValue; | ||
var signatureRaw, createHmacString, signatureValue; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
orderInfo = decodeURI(orderInfo); | ||
message = decodeURI(message); | ||
signatureRaw = "accessKey=".concat(this.accessKey, "&amount=").concat(amount, "&extraData=").concat(extraData, "&message=").concat(message, "&orderId=").concat(orderId, "&orderInfo=").concat(orderInfo, "&orderType=").concat(orderType, "&partnerCode=").concat(partnerCode, "&payType=").concat(payType, "&requestId=").concat(requestId, "&responseTime=").concat(responseTime, "&resultCode=").concat(resultCode, "&transId=").concat(transId); | ||
return [4 /*yield*/, crypto | ||
.createHmac('sha256', this.secretKey) | ||
.update(signatureRaw) | ||
.digest('hex')]; | ||
case 1: | ||
signatureValue = _b.sent(); | ||
if (resultCode.toString() !== '0') { | ||
throw new Error('The transaction was not completed.'); | ||
} | ||
if (signatureValue !== signature) { | ||
throw new Error('The transaction was not completed.'); | ||
} | ||
return [2 /*return*/, { | ||
type: 'momo', | ||
orderId: orderId, | ||
requestId: requestId, | ||
amount: amount, | ||
orderInfo: orderInfo, | ||
orderType: orderType, | ||
transId: transId, | ||
resultCode: resultCode, | ||
message: message, | ||
payType: payType, | ||
responseTime: responseTime, | ||
extraData: extraData, | ||
}]; | ||
orderInfo = decodeURI(orderInfo); | ||
message = decodeURI(message); | ||
signatureRaw = "accessKey=".concat(this.accessKey, "&amount=").concat(amount, "&extraData=").concat(extraData, "&message=").concat(message, "&orderId=").concat(orderId, "&orderInfo=").concat(orderInfo, "&orderType=").concat(orderType, "&partnerCode=").concat(partnerCode, "&payType=").concat(payType, "&requestId=").concat(requestId, "&responseTime=").concat(responseTime, "&resultCode=").concat(resultCode, "&transId=").concat(transId); | ||
createHmacString = function (privateKey, ts) { | ||
var hmac = CryptoJS.HmacSHA256(ts, privateKey).toString(CryptoJS.enc.Hex); | ||
return hmac; | ||
}; | ||
signatureValue = createHmacString(this.secretKey, signatureRaw); | ||
if (resultCode.toString() !== '0') { | ||
throw new Error('The transaction was not completed.'); | ||
} | ||
if (signatureValue !== signature) { | ||
throw new Error('The transaction was not completed.'); | ||
} | ||
return [2 /*return*/, { | ||
type: 'momo', | ||
orderId: orderId, | ||
requestId: requestId, | ||
amount: amount, | ||
orderInfo: orderInfo, | ||
orderType: orderType, | ||
transId: transId, | ||
resultCode: resultCode, | ||
message: message, | ||
payType: payType, | ||
responseTime: responseTime, | ||
extraData: extraData, | ||
}]; | ||
}); | ||
@@ -217,0 +216,0 @@ }); |
{ | ||
"name": "momo-payment-gateway", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"description": "Payment with Momo Wallet via QR code", | ||
@@ -31,8 +31,9 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"crypto-js": "^4.2.0", | ||
"node-fetch": "^2.6.1" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.6.4", | ||
"@types/node": "^17.0.34" | ||
"@types/node": "^17.0.34", | ||
"typescript": "^4.6.4" | ||
} | ||
} | ||
} |
@@ -5,3 +5,3 @@ # API MoMo Payment Gateway | ||
It's currently using for https://reebok.com.vn | ||
It's currently using for [Reebok](https://reebok.com.vn), [Thefaceshop](https://thefaceshop.com.vn), [BeautyBox](https://beautybox.com.vn),... | ||
@@ -142,2 +142,2 @@ We also wrote other payment gateway: | ||
[MIT](https://choosealicense.com/licenses/mit/) | ||
18712
142
2
286
+ Addedcrypto-js@^4.2.0
+ Addedcrypto-js@4.2.0(transitive)