payrex-node 0.1.3 → 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 CHANGED
@@ -1,5 +1,18 @@
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
+
8
+ ## [0.1.4] - 2024-07-23
9
+
10
+ - Move the deprecated capture_type attribute.
11
+
12
+ ## [0.1.3] - 2024-07-22
13
+
14
+ - Add the new payment_method_options attribute.
15
+
3
16
  ## [0.1.2] - 2024-05-23
4
17
 
5
18
  - Update error handling.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payrex-node",
3
- "version": "0.1.3",
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 = qs.stringify(payload, { arrayFormat: 'brackets' });
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 = data.payment_intent;
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;
@@ -2,7 +2,6 @@ function MerchantEntity(apiResource) {
2
2
  const data = apiResource.data;
3
3
 
4
4
  this.id = data.id;
5
- this.resource = data.resource;
6
5
  this.connectionType = data.connection_type;
7
6
  this.livemode = data.livemode;
8
7
  this.createdAt = data.created_at;
@@ -2,9 +2,7 @@ function PaymentIntentEntity(apiResource) {
2
2
  const data = apiResource.data;
3
3
 
4
4
  this.id = data.id;
5
- this.resource = data.resource;
6
5
  this.amount = data.amount;
7
- this.captureType = data.capture_type;
8
6
  this.clientSecret = data.client_secret;
9
7
  this.currency = data.currency;
10
8
  this.description = data.description;
@@ -2,7 +2,6 @@ function PaymentMethodEntity(apiResource) {
2
2
  const data = apiResource.data;
3
3
 
4
4
  this.id = data.id;
5
- this.resource = data.resource;
6
5
  this.type = data.type;
7
6
  this.billingDetails = data.billing_details;
8
7
  this.livemode = data.livemode;
@@ -2,7 +2,6 @@ function RefundEntity(apiResource) {
2
2
  const data = apiResource.data;
3
3
 
4
4
  this.id = data.id;
5
- this.resource = data.resource;
6
5
  this.amount = data.amount;
7
6
  this.currency = data.currency;
8
7
  this.livemode = data.livemode;
@@ -2,7 +2,6 @@ function WebhookEntity(apiResource) {
2
2
  const data = apiResource.data;
3
3
 
4
4
  this.id = data.id;
5
- this.resource = data.resource;
6
5
  this.secretKey = data.secret_key;
7
6
  this.status = data.status;
8
7
  this.description = data.description;
@@ -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;