payrex-node 1.3.0 → 1.5.0

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,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.5.0] - 2025-05-30
4
+
5
+ - Add list payout transactions endpoint.
6
+ - Add Payout and PayoutTransaction resources.
7
+
8
+ ## [1.4.0] - 2025-05-15
9
+
10
+ - Add get payment by id endpoint
11
+
3
12
  ## [1.3.0] - 2025-04-23
4
13
 
5
14
  - Add customer session endpoints.
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "payrex-node",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "PayRex Node JS Library",
5
5
  "keywords": [
6
6
  "payrex",
7
7
  "payment processing",
8
8
  "credit cards",
9
+ "gcash",
10
+ "qrph",
11
+ "maya",
9
12
  "api"
10
13
  ],
11
14
  "homepage": "https://github.com/payrexhq/payrex-node",
package/src/HttpClient.js CHANGED
@@ -26,7 +26,7 @@ HttpClient.prototype.request = async function ({ path, method, payload }) {
26
26
 
27
27
  let data = null;
28
28
 
29
- if (method === 'post' || method === 'put') {
29
+ if (['post', 'put'].includes(method.toLowerCase())) {
30
30
  data = qs.stringify(
31
31
  payload,
32
32
  {
@@ -36,13 +36,20 @@ HttpClient.prototype.request = async function ({ path, method, payload }) {
36
36
  }
37
37
 
38
38
  try {
39
- const response = await axios.request({
39
+ const requestPayload = {
40
40
  method: method,
41
41
  url: url,
42
42
  auth: auth,
43
43
  headers: headers,
44
- data: data,
45
- });
44
+ }
45
+
46
+ if(['get', 'delete'].includes(method.toLowerCase()) && payload !== null && payload !== undefined) {
47
+ requestPayload.params = payload
48
+ } else {
49
+ requestPayload.data = data
50
+ }
51
+
52
+ const response = await axios.request(requestPayload);
46
53
 
47
54
  return new ApiResource(response.data);
48
55
  } catch (error) {
@@ -0,0 +1,23 @@
1
+ function PaymentEntity(apiResource) {
2
+ const data = apiResource.data;
3
+
4
+ this.id = data.id;
5
+ this.amount = data.amount
6
+ this.amountRefunded = data.amount_refunded
7
+ this.billing = data.billing
8
+ this.currency = data.currency
9
+ this.description = data.description
10
+ this.fee = data.fee
11
+ this.livemode = data.livemode
12
+ this.metadata = data.metadata
13
+ this.netAmount = data.net_amount
14
+ this.paymentIntentId = data.payment_intent_id
15
+ this.status = data.status
16
+ this.customer = data.customer
17
+ this.paymentMethod = data.payment_method
18
+ this.refunded = data.refunded
19
+ this.createdAt = data.created_at;
20
+ this.updatedAt = data.updated_at;
21
+ }
22
+
23
+ module.exports = PaymentEntity;
@@ -0,0 +1,14 @@
1
+ function PayoutEntity(apiResource) {
2
+ const data = apiResource.data;
3
+
4
+ this.id = data.id;
5
+ this.amount = data.amount;
6
+ this.destination = data.destination;
7
+ this.livemode = data.livemode;
8
+ this.netAmount = data.net_amount;
9
+ this.status = data.status;
10
+ this.createdAt = data.created_at;
11
+ this.updatedAt = data.updated_at;
12
+ }
13
+
14
+ module.exports = PayoutEntity;
@@ -0,0 +1,13 @@
1
+ function PayoutTransactionEntity(apiResource) {
2
+ const data = apiResource.data;
3
+
4
+ this.id = data.id;
5
+ this.amount = data.amount;
6
+ this.payoutId = data.payout_id;
7
+ this.transactionType = data.transaction_type;
8
+ this.transactionId = data.transaction_id;
9
+ this.createdAt = data.created_at;
10
+ this.updatedAt = data.updated_at;
11
+ }
12
+
13
+ module.exports = PayoutTransactionEntity;
@@ -0,0 +1,20 @@
1
+ const BaseService = require('./BaseService');
2
+ const PaymentEntity = require('../entities/PaymentEntity');
3
+
4
+ function PaymentService(client) {
5
+ BaseService.call(this, client);
6
+ this.path = 'payments';
7
+ }
8
+
9
+ PaymentService.prototype.retrieve = function (id) {
10
+ return this.request({
11
+ path: `${this.path}/${id}`,
12
+ method: 'get',
13
+ }).then(function (response) {
14
+ return new PaymentEntity(response);
15
+ });
16
+ };
17
+
18
+ Object.setPrototypeOf(PaymentService.prototype, BaseService.prototype);
19
+
20
+ module.exports = PaymentService;
@@ -0,0 +1,32 @@
1
+ const BaseService = require('./BaseService');
2
+ const PayoutTransactionEntity = require('../entities/PayoutTransactionEntity');
3
+ const ListingEntity = require('../entities/ListingEntity');
4
+ const ApiResource = require('../ApiResource');
5
+
6
+ function PayoutService(client) {
7
+ BaseService.call(this, client);
8
+
9
+ this.path = 'payouts';
10
+ }
11
+
12
+ PayoutService.prototype.listTransactions = function (id, payload) {
13
+ return this.request({
14
+ path: `${this.path}/${id}/transactions`,
15
+ payload: payload,
16
+ method: 'get',
17
+ }).then(function (response) {
18
+ const responseData = response.data.data;
19
+
20
+ const data = responseData.map((row) => {
21
+ const apiResource = new ApiResource(row);
22
+
23
+ return new PayoutTransactionEntity(apiResource);
24
+ });
25
+
26
+ return new ListingEntity(data, response.data.has_more);
27
+ });
28
+ };
29
+
30
+ Object.setPrototypeOf(PayoutService.prototype, BaseService.prototype);
31
+
32
+ module.exports = PayoutService;
@@ -4,13 +4,17 @@ const CheckoutSessionService = require('./CheckoutSessionService');
4
4
  const CustomerSessionService = require('./CustomerSessionService');
5
5
  const CustomerService = require('./CustomerService');
6
6
  const PaymentIntentService = require('./PaymentIntentService');
7
+ const PaymentService = require('./PaymentService');
8
+ const PayoutService = require('./PayoutService');
7
9
  const RefundService = require('./RefundService');
8
10
  const WebhookService = require('./WebhookService');
9
11
 
10
12
  module.exports = {
11
13
  checkoutSessions: CheckoutSessionService,
12
14
  customerSessions: CustomerSessionService,
15
+ payments: PaymentService,
13
16
  paymentIntents: PaymentIntentService,
17
+ payouts: PayoutService,
14
18
  customers: CustomerService,
15
19
  billingStatements: BillingStatementService,
16
20
  billingStatementLineItems: BillingStatementLineItemService,
package/test2.js DELETED
@@ -1,55 +0,0 @@
1
- const payrex = require('payrex-node')(
2
- 'sk_live_znE26cM4ZbZP3mfTLeZsnw7EceWHKiPN'
3
- );
4
-
5
- const RequestInvalidError = require('./src/errors/RequestInvalidError');
6
- const AuthenticationInvalidError = require('./src/errors/AuthenticationInvalidError');
7
- const ResourceNotFoundError = require('./src/errors/ResourceNotFoundError');
8
-
9
- // try {
10
- // const paymentIntent = await payrex.paymentIntents.create({ amount: 10000 });
11
- // } catch (error) {
12
- // console.log('caught error!')
13
- // if (error instanceof ResourceNotFoundError) {
14
- // // handle error if a resource does not exist.
15
- // } else if (error instanceof AuthenticationInvalidError) {
16
- // // handle authentication error
17
- // } else if (error instanceof RequestInvalidError) {
18
- // console.log('handle error if there\'s validation error');
19
-
20
- // error.errors.forEach((e) => {
21
- // console.log(e.code);
22
- // console.log(e.detail);
23
- // });
24
- // }
25
- // }
26
-
27
- (async () => {
28
- try {
29
- const paymentIntent = await payrex.paymentIntents.create({ amount: 10000 });
30
- } catch (error) {
31
- console.log('caught error!');
32
- console.log(error.name);
33
- if (error.name === 'ResourceNotFoundError') {
34
- // handle error if a resource does not exist.
35
- } else if (error.name === 'AuthenticationInvalidError') {
36
- // handle authentication error
37
- } else if (error.name === 'RequestInvalidError') {
38
- console.log("handle error if there's validation error");
39
-
40
- error.errors.forEach((e) => {
41
- console.log(e.code);
42
- console.log(e.detail);
43
- });
44
- }
45
- }
46
- })();
47
-
48
- const refund = await payrex.refunds.update(
49
- 're_xPy5nb7p6R7jG4ZPEJu5WvVCb8Lz31qx',
50
- {
51
- metadata: {
52
- 'some_key3': 'some_val3'
53
- }
54
- }
55
- )