Comparing version 0.1.2 to 0.1.3
@@ -109,2 +109,12 @@ 'use strict'; | ||
/** | ||
* Decrypt data response from Alepay | ||
* | ||
* @param data {string} | ||
*/ | ||
; | ||
_proto.decryptData = function decryptData(data) { | ||
return this._rsa.decrypt(data); | ||
} | ||
/** | ||
* Make a request to Alepay | ||
@@ -111,0 +121,0 @@ * |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("crypto")),n=e(require("node-rsa")),r=e(require("rsa-key")),o=e(require("phin"));function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var i={sandbox:"https://alepay-sandbox.nganluong.vn",live:"https://alepay.vn"},a=function(){function e(e){this._encryptedKey=e,this._key=new n,this.loadKey()}var t=e.prototype;return t.loadKey=function(){var e=new r(this._encryptedKey).exportKey("public","pem","pkcs1");this._key.importKey(e),this._key.setOptions({environment:"node",encryptionScheme:"pkcs1"})},t.encrypt=function(e){return this._key.encrypt(e,"base64")},t.decrypt=function(e){return this._key.decryptPublic(Buffer.from(e,"base64"),"utf-8")},e}();exports.Alepay=function(){function e(e){this._env=e.env||"sandbox",this._rsa=new a(e.encryptedKey),this._apiToken=e.token,this._checksum=e.checksum}var n=e.prototype;return n._createChecksum=function(e){return t.createHash("md5").update(""+e+this._checksum).digest("hex")},n._isResponseValid=function(e,t){return this._createChecksum(e)===t},n.request=function(e,t){var n=this,r=this._rsa.encrypt(JSON.stringify(t)),a=this._createChecksum(r);return o({url:i[this._env]+e,method:"POST",parse:"json",timeout:5e3,data:{token:this._apiToken,data:r,checksum:a}}).then((function(e){if(e.body.data){if(!n._isResponseValid(e.body.data,e.body.checksum))throw new Error("Encrypted data invalid");var t=n._rsa.decrypt(e.body.data);try{t=JSON.parse(t)}catch(e){}return s({},e.body,{data:t})}return e.body}))},n.createRequestPayment=function(e){return this.request("/checkout/v1/request-order",e)},n.getTransactionHistory=function(e){return void 0===e&&(e={}),this.request("/checkout/v1/get-transaction-history",e)},n.getTransactionInfo=function(e){return this.request("/checkout/v1/get-transaction-info",{transactionCode:e})},n.oneClickPayment=function(e){return this.request("/checkout/v1/request-tokenization-payment",e)},n.getBanksDomestic=function(e){return this.request("/checkout/v1/get-banks-domestic",{amount:e})},e}(),exports.RSA=a; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("crypto")),n=e(require("node-rsa")),r=e(require("rsa-key")),s=e(require("phin"));function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var o={sandbox:"https://alepay-sandbox.nganluong.vn",live:"https://alepay.vn"},a=function(){function e(e){this._encryptedKey=e,this._key=new n,this.loadKey()}var t=e.prototype;return t.loadKey=function(){var e=new r(this._encryptedKey).exportKey("public","pem","pkcs1");this._key.importKey(e),this._key.setOptions({environment:"node",encryptionScheme:"pkcs1"})},t.encrypt=function(e){return this._key.encrypt(e,"base64")},t.decrypt=function(e){return this._key.decryptPublic(Buffer.from(e,"base64"),"utf-8")},e}();exports.Alepay=function(){function e(e){this._env=e.env||"sandbox",this._rsa=new a(e.encryptedKey),this._apiToken=e.token,this._checksum=e.checksum}var n=e.prototype;return n._createChecksum=function(e){return t.createHash("md5").update(""+e+this._checksum).digest("hex")},n._isResponseValid=function(e,t){return this._createChecksum(e)===t},n.decryptData=function(e){return this._rsa.decrypt(e)},n.request=function(e,t){var n=this,r=this._rsa.encrypt(JSON.stringify(t)),a=this._createChecksum(r);return s({url:o[this._env]+e,method:"POST",parse:"json",timeout:5e3,data:{token:this._apiToken,data:r,checksum:a}}).then((function(e){if(e.body.data){if(!n._isResponseValid(e.body.data,e.body.checksum))throw new Error("Encrypted data invalid");var t=n._rsa.decrypt(e.body.data);try{t=JSON.parse(t)}catch(e){}return i({},e.body,{data:t})}return e.body}))},n.createRequestPayment=function(e){return this.request("/checkout/v1/request-order",e)},n.getTransactionHistory=function(e){return void 0===e&&(e={}),this.request("/checkout/v1/get-transaction-history",e)},n.getTransactionInfo=function(e){return this.request("/checkout/v1/get-transaction-info",{transactionCode:e})},n.oneClickPayment=function(e){return this.request("/checkout/v1/request-tokenization-payment",e)},n.getBanksDomestic=function(e){return this.request("/checkout/v1/get-banks-domestic",{amount:e})},e}(),exports.RSA=a; | ||
//# sourceMappingURL=alepay.cjs.production.min.js.map |
@@ -34,2 +34,8 @@ export declare type AlepayEnv = 'sandbox' | 'live'; | ||
/** | ||
* Decrypt data response from Alepay | ||
* | ||
* @param data {string} | ||
*/ | ||
decryptData(data: string): any; | ||
/** | ||
* Make a request to Alepay | ||
@@ -36,0 +42,0 @@ * |
@@ -103,2 +103,12 @@ import Crypto from 'crypto'; | ||
/** | ||
* Decrypt data response from Alepay | ||
* | ||
* @param data {string} | ||
*/ | ||
; | ||
_proto.decryptData = function decryptData(data) { | ||
return this._rsa.decrypt(data); | ||
} | ||
/** | ||
* Make a request to Alepay | ||
@@ -105,0 +115,0 @@ * |
{ | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -55,2 +55,11 @@ import Crypto from 'crypto'; | ||
/** | ||
* Decrypt data response from Alepay | ||
* | ||
* @param data {string} | ||
*/ | ||
decryptData(data: string) { | ||
return this._rsa.decrypt(data); | ||
} | ||
/** | ||
* Make a request to Alepay | ||
@@ -57,0 +66,0 @@ * |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51647
608