@payos/node
Advanced tools
@@ -9,2 +9,3 @@ export declare const ERROR_MESSAGE: { | ||
| INTERNAL_SERVER_ERROR: string; | ||
| INVALID_PARAMETER: string; | ||
| }; | ||
@@ -11,0 +12,0 @@ export declare const ERROR_CODE: { |
+7
-6
@@ -5,9 +5,10 @@ "use strict"; | ||
| exports.ERROR_MESSAGE = { | ||
| NO_SIGNATURE: "No signature", | ||
| NO_DATA: "No data", | ||
| INVALID_SIGNATURE: "Invalid signature", | ||
| NO_SIGNATURE: "No signature.", | ||
| NO_DATA: "No data.", | ||
| INVALID_SIGNATURE: "Invalid signature.", | ||
| DATA_NOT_INTEGRITY: "The data is unreliable because the signature of the response does not match the signature of the data", | ||
| WEBHOOK_URL_INVALID: "Webhook URL invalid", | ||
| UNAUTHORIZED: "Unauthorized", | ||
| INTERNAL_SERVER_ERROR: "Internal Server Error" | ||
| WEBHOOK_URL_INVALID: "Webhook URL invalid.", | ||
| UNAUTHORIZED: "Unauthorized.", | ||
| INTERNAL_SERVER_ERROR: "Internal Server Error.", | ||
| INVALID_PARAMETER: "Invalid Parameter." | ||
| }; | ||
@@ -14,0 +15,0 @@ exports.ERROR_CODE = { |
+66
-49
@@ -71,13 +71,23 @@ "use strict"; | ||
| PayOS.prototype.createPaymentLink = function (paymentData) { | ||
| var _a, _b; | ||
| var _a; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var url, signaturePaymentRequest, paymentLinkRes, paymentLinkResSignature, error_1, errorData, errorMessage; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| var orderCode, amount, returnUrl, cancelUrl, description, requiredPaymentData_1, requiredKeys, keysError, msgError, url, signaturePaymentRequest, paymentLinkRes, paymentLinkResSignature, error_1, errorMessage; | ||
| return __generator(this, function (_b) { | ||
| switch (_b.label) { | ||
| case 0: | ||
| orderCode = paymentData.orderCode, amount = paymentData.amount, returnUrl = paymentData.returnUrl, cancelUrl = paymentData.cancelUrl, description = paymentData.description; | ||
| if (!(paymentData && orderCode && amount && returnUrl && cancelUrl && description)) { | ||
| requiredPaymentData_1 = { orderCode: orderCode, amount: amount, returnUrl: returnUrl, cancelUrl: cancelUrl, description: description }; | ||
| requiredKeys = Object.keys(requiredPaymentData_1); | ||
| keysError = requiredKeys.filter(function (key) { | ||
| return requiredPaymentData_1[key] == undefined || requiredPaymentData_1[key] == null; | ||
| }); | ||
| msgError = "".concat(constants_1.ERROR_MESSAGE.INVALID_PARAMETER, " ").concat(keysError.join(', '), " must not be undefined or null."); | ||
| throw new Error(msgError); | ||
| } | ||
| url = "".concat(PAYOS_BASE_URL, "/v2/payment-requests"); | ||
| signaturePaymentRequest = (0, create_signature_1.createSignatureOfPaymentRequest)(paymentData, this.checksumKey); | ||
| _c.label = 1; | ||
| _b.label = 1; | ||
| case 1: | ||
| _c.trys.push([1, 3, , 4]); | ||
| _b.trys.push([1, 3, , 4]); | ||
| return [4 /*yield*/, (0, axios_1.default)({ | ||
@@ -94,3 +104,3 @@ method: "POST", | ||
| case 2: | ||
| paymentLinkRes = _c.sent(); | ||
| paymentLinkRes = _b.sent(); | ||
| if (paymentLinkRes.code == "00") { | ||
@@ -107,6 +117,4 @@ paymentLinkResSignature = (0, create_signature_1.createSignatureFromObj)(paymentLinkRes.data, this.checksumKey); | ||
| case 3: | ||
| error_1 = _c.sent(); | ||
| errorData = ((_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _a === void 0 ? void 0 : _a.data) || (error_1 === null || error_1 === void 0 ? void 0 : error_1.response) || error_1; | ||
| console.error(errorData); | ||
| errorMessage = ((_b = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _b === void 0 ? void 0 : _b.message) || (error_1 === null || error_1 === void 0 ? void 0 : error_1.message) || error_1; | ||
| error_1 = _b.sent(); | ||
| errorMessage = ((_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _a === void 0 ? void 0 : _a.message) || (error_1 === null || error_1 === void 0 ? void 0 : error_1.message) || error_1; | ||
| throw new Error(errorMessage); | ||
@@ -123,12 +131,17 @@ case 4: return [2 /*return*/]; | ||
| PayOS.prototype.getPaymentLinkInfomation = function (orderId) { | ||
| var _a, _b; | ||
| var _a; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var url, paymentLinkInfoRes, paymentLinkInfoResSignature, error_2, errorData, errorMessage; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| var url, paymentLinkInfoRes, paymentLinkInfoResSignature, error_2, errorMessage; | ||
| return __generator(this, function (_b) { | ||
| switch (_b.label) { | ||
| case 0: | ||
| if (!orderId | ||
| || (typeof orderId == 'number' && (!Number.isInteger(orderId) || orderId <= 0)) | ||
| || (typeof orderId == 'string' && orderId.length == 0)) { | ||
| throw new Error(constants_1.ERROR_MESSAGE.INVALID_PARAMETER); | ||
| } | ||
| url = "".concat(PAYOS_BASE_URL, "/v2/payment-requests/").concat(orderId); | ||
| _c.label = 1; | ||
| _b.label = 1; | ||
| case 1: | ||
| _c.trys.push([1, 3, , 4]); | ||
| _b.trys.push([1, 3, , 4]); | ||
| return [4 /*yield*/, (0, axios_1.default)({ | ||
@@ -144,3 +157,3 @@ method: "GET", | ||
| case 2: | ||
| paymentLinkInfoRes = _c.sent(); | ||
| paymentLinkInfoRes = _b.sent(); | ||
| if (paymentLinkInfoRes.code == "00") { | ||
@@ -157,6 +170,4 @@ paymentLinkInfoResSignature = (0, create_signature_1.createSignatureFromObj)(paymentLinkInfoRes.data, this.checksumKey); | ||
| case 3: | ||
| error_2 = _c.sent(); | ||
| errorData = ((_a = error_2 === null || error_2 === void 0 ? void 0 : error_2.response) === null || _a === void 0 ? void 0 : _a.data) || (error_2 === null || error_2 === void 0 ? void 0 : error_2.response) || error_2; | ||
| console.error(errorData); | ||
| errorMessage = ((_b = error_2 === null || error_2 === void 0 ? void 0 : error_2.response) === null || _b === void 0 ? void 0 : _b.message) || (error_2 === null || error_2 === void 0 ? void 0 : error_2.message) || error_2; | ||
| error_2 = _b.sent(); | ||
| errorMessage = ((_a = error_2 === null || error_2 === void 0 ? void 0 : error_2.response) === null || _a === void 0 ? void 0 : _a.message) || (error_2 === null || error_2 === void 0 ? void 0 : error_2.message) || error_2; | ||
| throw new Error(errorMessage); | ||
@@ -173,8 +184,11 @@ case 4: return [2 /*return*/]; | ||
| PayOS.prototype.confirmWebhook = function (webhookUrl) { | ||
| var _a, _b, _c, _d, _e; | ||
| var _a, _b, _c, _d; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var url, data, error_3, errorData, errorMessage; | ||
| return __generator(this, function (_f) { | ||
| switch (_f.label) { | ||
| var url, data, error_3, errorMessage; | ||
| return __generator(this, function (_e) { | ||
| switch (_e.label) { | ||
| case 0: | ||
| if (!webhookUrl || webhookUrl.length == 0) { | ||
| throw new Error(constants_1.ERROR_MESSAGE.INVALID_PARAMETER); | ||
| } | ||
| url = "".concat(PAYOS_BASE_URL, "/confirm-webhook"); | ||
@@ -184,5 +198,5 @@ data = { | ||
| }; | ||
| _f.label = 1; | ||
| _e.label = 1; | ||
| case 1: | ||
| _f.trys.push([1, 3, , 4]); | ||
| _e.trys.push([1, 3, , 4]); | ||
| return [4 /*yield*/, (0, axios_1.default)({ | ||
@@ -197,11 +211,11 @@ method: "POST", | ||
| data: data, | ||
| })]; | ||
| }).then(function (response) { return response.data; })]; | ||
| case 2: | ||
| _f.sent(); | ||
| _e.sent(); | ||
| return [2 /*return*/, webhookUrl]; | ||
| case 3: | ||
| error_3 = _f.sent(); | ||
| errorData = ((_a = error_3 === null || error_3 === void 0 ? void 0 : error_3.response) === null || _a === void 0 ? void 0 : _a.data) || (error_3 === null || error_3 === void 0 ? void 0 : error_3.response) || error_3; | ||
| console.error(errorData); | ||
| if (((_b = error_3.response) === null || _b === void 0 ? void 0 : _b.status) === 400) | ||
| error_3 = _e.sent(); | ||
| // const errorData = error?.response?.data || error?.response || error; | ||
| // console.error(errorData); | ||
| if (((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.status) === 400) | ||
| throw new custom_error_1.PayOSError({ | ||
@@ -211,3 +225,3 @@ code: constants_1.ERROR_CODE.INTERNAL_SERVER_ERROR, | ||
| }); | ||
| else if (((_c = error_3.response) === null || _c === void 0 ? void 0 : _c.status) === 401) | ||
| else if (((_b = error_3.response) === null || _b === void 0 ? void 0 : _b.status) === 401) | ||
| throw new custom_error_1.PayOSError({ | ||
@@ -217,3 +231,3 @@ code: constants_1.ERROR_CODE.UNAUTHORIZED, | ||
| }); | ||
| else if (String((_d = error_3.response) === null || _d === void 0 ? void 0 : _d.status).startsWith('5')) { | ||
| else if (String((_c = error_3.response) === null || _c === void 0 ? void 0 : _c.status).startsWith('5')) { | ||
| throw new custom_error_1.PayOSError({ | ||
@@ -224,3 +238,3 @@ code: constants_1.ERROR_CODE.INTERNAL_SERVER_ERROR, | ||
| } | ||
| errorMessage = ((_e = error_3 === null || error_3 === void 0 ? void 0 : error_3.response) === null || _e === void 0 ? void 0 : _e.message) || (error_3 === null || error_3 === void 0 ? void 0 : error_3.message) || error_3; | ||
| errorMessage = ((_d = error_3 === null || error_3 === void 0 ? void 0 : error_3.response) === null || _d === void 0 ? void 0 : _d.message) || (error_3 === null || error_3 === void 0 ? void 0 : error_3.message) || error_3; | ||
| throw new Error(errorMessage); | ||
@@ -238,13 +252,18 @@ case 4: return [2 /*return*/]; | ||
| PayOS.prototype.cancelPaymentLink = function (orderId, cancellationReason) { | ||
| var _a, _b; | ||
| var _a; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var url, data, cancelPaymentLinkResponse, paymentLinkInfoResSignature, error_4, errorData, errorMessage; | ||
| return __generator(this, function (_c) { | ||
| switch (_c.label) { | ||
| var url, data, cancelPaymentLinkResponse, paymentLinkInfoResSignature, error_4, errorMessage; | ||
| return __generator(this, function (_b) { | ||
| switch (_b.label) { | ||
| case 0: | ||
| if (!orderId | ||
| || (typeof orderId == 'number' && (!Number.isInteger(orderId) || orderId <= 0)) | ||
| || (typeof orderId == 'string' && orderId.length == 0)) { | ||
| throw new Error(constants_1.ERROR_MESSAGE.INVALID_PARAMETER); | ||
| } | ||
| url = "".concat(PAYOS_BASE_URL, "/v2/payment-requests/").concat(orderId, "/cancel"); | ||
| data = cancellationReason ? { cancellationReason: cancellationReason } : null; | ||
| _c.label = 1; | ||
| _b.label = 1; | ||
| case 1: | ||
| _c.trys.push([1, 3, , 4]); | ||
| _b.trys.push([1, 3, , 4]); | ||
| return [4 /*yield*/, (0, axios_1.default)({ | ||
@@ -259,5 +278,5 @@ method: "POST", | ||
| data: data | ||
| })]; | ||
| }).then(function (response) { return response.data; })]; | ||
| case 2: | ||
| cancelPaymentLinkResponse = _c.sent(); | ||
| cancelPaymentLinkResponse = _b.sent(); | ||
| if (cancelPaymentLinkResponse.code == "00") { | ||
@@ -277,6 +296,4 @@ paymentLinkInfoResSignature = (0, create_signature_1.createSignatureFromObj)(cancelPaymentLinkResponse.data, this.checksumKey); | ||
| case 3: | ||
| error_4 = _c.sent(); | ||
| errorData = ((_a = error_4 === null || error_4 === void 0 ? void 0 : error_4.response) === null || _a === void 0 ? void 0 : _a.data) || (error_4 === null || error_4 === void 0 ? void 0 : error_4.response) || error_4; | ||
| console.error(errorData); | ||
| errorMessage = ((_b = error_4 === null || error_4 === void 0 ? void 0 : error_4.response) === null || _b === void 0 ? void 0 : _b.message) || (error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || error_4; | ||
| error_4 = _b.sent(); | ||
| errorMessage = ((_a = error_4 === null || error_4 === void 0 ? void 0 : error_4.response) === null || _a === void 0 ? void 0 : _a.message) || (error_4 === null || error_4 === void 0 ? void 0 : error_4.message) || error_4; | ||
| throw new Error(errorMessage); | ||
@@ -283,0 +300,0 @@ case 4: return [2 /*return*/]; |
+1
-0
@@ -24,2 +24,3 @@ export type DataType<T> = T | null | undefined; | ||
| buyerAddress?: string; | ||
| expiredAt?: number; | ||
| }; | ||
@@ -26,0 +27,0 @@ export type CheckoutResponseDataType = { |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var sort_obj_by_key_1 = require("./sort-obj-by-key"); | ||
| var convertObjToQueryStr = function (object) { | ||
| return Object.keys(object) | ||
| .map(function (key) { return "".concat(key, "=").concat(object[key]); }) | ||
| .filter(function (key) { return object[key] !== undefined; }) | ||
| .map(function (key) { | ||
| var value = object[key]; | ||
| // Sort nested object | ||
| if (value && Array.isArray(value)) { | ||
| value = JSON.stringify(value.map(function (val) { return (0, sort_obj_by_key_1.default)(val); })); | ||
| } | ||
| // Set empty string if null | ||
| if ([null, undefined, 'undefined', 'null'].includes(value)) { | ||
| value = ''; | ||
| } | ||
| return "".concat(key, "=").concat(value); | ||
| }) | ||
| .join('&'); | ||
| }; | ||
| exports.default = convertObjToQueryStr; |
+2
-2
| { | ||
| "name": "@payos/node", | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", | ||
| "description": "", | ||
@@ -28,4 +28,4 @@ "main": "lib/index.js", | ||
| "type": "git", | ||
| "url": "https://github.com/payOSHQ/payos-lib-be.git" | ||
| "url": "https://github.com/payOSHQ/payos-lib-node.git" | ||
| } | ||
| } |
+1
-0
@@ -56,2 +56,3 @@ The payOS Node library provides convenient access to the payOS API from applications written in server-side JavaScript. | ||
| buyerAddress?: string; | ||
| expiredAt?: number; | ||
| } | ||
@@ -58,0 +59,0 @@ ``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33617
5.23%585
5.98%226
0.44%0
-100%