payrex-node 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/package.json +2 -3
- package/src/HttpClient.js +3 -2
- package/src/entities/CheckoutSessionEntity.js +5 -3
- package/src/entities/MerchantEntity.js +0 -1
- package/src/entities/PaymentIntentEntity.js +0 -1
- package/src/entities/PaymentMethodEntity.js +0 -1
- package/src/entities/RefundEntity.js +0 -1
- package/src/entities/WebhookEntity.js +0 -1
- package/src/helpers/Parameter.js +35 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.5] - 2024-07-24
|
|
4
|
+
|
|
5
|
+
- Finalize the checkout session endpoints.
|
|
6
|
+
- Remove the resource attribute from all resources. This is the standard implementation across all PayRex SDKs.
|
|
7
|
+
|
|
3
8
|
## [0.1.4] - 2024-07-23
|
|
4
9
|
|
|
5
10
|
- Move the deprecated capture_type attribute.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payrex-node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "PayRex Node JS Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payrex",
|
|
@@ -30,8 +30,7 @@
|
|
|
30
30
|
"prettier": "^3.2.5"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"axios": "^1.6.8"
|
|
34
|
-
"qs": "^6.12.1"
|
|
33
|
+
"axios": "^1.6.8"
|
|
35
34
|
},
|
|
36
35
|
"license": "MIT",
|
|
37
36
|
"scripts": {
|
package/src/HttpClient.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const axios = require('axios');
|
|
2
|
-
const qs = require('qs');
|
|
3
2
|
|
|
4
3
|
const ApiResource = require('./ApiResource');
|
|
5
4
|
const RequestInvalidError = require('./errors/RequestInvalidError');
|
|
6
5
|
const AuthenticationInvalidError = require('./errors/AuthenticationInvalidError');
|
|
7
6
|
const ResourceNotFoundError = require('./errors/ResourceNotFoundError');
|
|
8
7
|
const BaseError = require('./errors/BaseError');
|
|
8
|
+
const Parameter = require('./helpers/Parameter');
|
|
9
9
|
|
|
10
10
|
function HttpClient(apiKey, baseUrl) {
|
|
11
11
|
this.apiKey = apiKey;
|
|
@@ -25,8 +25,9 @@ HttpClient.prototype.request = async function ({ path, method, payload }) {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
let data = null;
|
|
28
|
+
|
|
28
29
|
if (method === 'post' || method === 'put') {
|
|
29
|
-
data =
|
|
30
|
+
data = Parameter.encode(payload);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
try {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
const PaymentIntentEntity = require("./PaymentIntentEntity");
|
|
2
|
+
|
|
1
3
|
function CheckoutSessionEntity(apiResource) {
|
|
2
4
|
const data = apiResource.data;
|
|
3
5
|
|
|
4
6
|
this.id = data.id;
|
|
5
|
-
this.resource = data.resource;
|
|
6
7
|
this.customerReferenceId = data.customer_reference_id;
|
|
7
8
|
this.clientSecret = data.client_secret;
|
|
8
9
|
this.status = data.status;
|
|
@@ -10,12 +11,13 @@ function CheckoutSessionEntity(apiResource) {
|
|
|
10
11
|
this.lineItems = data.line_items;
|
|
11
12
|
this.livemode = data.livemode;
|
|
12
13
|
this.url = data.url;
|
|
13
|
-
this.paymentIntent =
|
|
14
|
+
this.paymentIntent = new PaymentIntentEntity({
|
|
15
|
+
data: data.payment_intent
|
|
16
|
+
});
|
|
14
17
|
this.metadata = data.metadata;
|
|
15
18
|
this.successUrl = data.success_url;
|
|
16
19
|
this.cancelUrl = data.cancel_url;
|
|
17
20
|
this.paymentMethods = data.payment_methods;
|
|
18
|
-
this.captureType = data.capture_type;
|
|
19
21
|
this.description = data.description;
|
|
20
22
|
this.submitType = data.submit_type;
|
|
21
23
|
this.expiresAt = data.expires_at;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function Parameter() {}
|
|
2
|
+
|
|
3
|
+
Parameter.encode = (params, prefix = '') => {
|
|
4
|
+
const finalQuery = [];
|
|
5
|
+
|
|
6
|
+
for(const [key, value] of Object.entries(params)) {
|
|
7
|
+
let newKey = prefix === '' ? key : `${prefix}[${key}]`
|
|
8
|
+
|
|
9
|
+
if(prefix === '') {
|
|
10
|
+
newKey = key;
|
|
11
|
+
} else {
|
|
12
|
+
if(
|
|
13
|
+
!isNaN(key) &&
|
|
14
|
+
!Array.isArray(value) &&
|
|
15
|
+
(typeof value !== 'object' && value !== null)
|
|
16
|
+
) {
|
|
17
|
+
newKey = `${prefix}[]`;
|
|
18
|
+
} else {
|
|
19
|
+
newKey = `${prefix}[${key}]`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if(typeof value === 'object' && value !== null) {
|
|
24
|
+
finalQuery.push(Parameter.encode(value, newKey));
|
|
25
|
+
} else {
|
|
26
|
+
finalQuery.push(
|
|
27
|
+
`${encodeURI(newKey)}=${encodeURI(value)}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return finalQuery.join('&');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = Parameter;
|