payrex-node 1.4.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,10 @@
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
+
3
8
  ## [1.4.0] - 2025-05-15
4
9
 
5
10
  - Add get payment by id endpoint
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payrex-node",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "PayRex Node JS Library",
5
5
  "keywords": [
6
6
  "payrex",
@@ -8,6 +8,7 @@
8
8
  "credit cards",
9
9
  "gcash",
10
10
  "qrph",
11
+ "maya",
11
12
  "api"
12
13
  ],
13
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,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,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;
@@ -5,6 +5,7 @@ const CustomerSessionService = require('./CustomerSessionService');
5
5
  const CustomerService = require('./CustomerService');
6
6
  const PaymentIntentService = require('./PaymentIntentService');
7
7
  const PaymentService = require('./PaymentService');
8
+ const PayoutService = require('./PayoutService');
8
9
  const RefundService = require('./RefundService');
9
10
  const WebhookService = require('./WebhookService');
10
11
 
@@ -13,6 +14,7 @@ module.exports = {
13
14
  customerSessions: CustomerSessionService,
14
15
  payments: PaymentService,
15
16
  paymentIntents: PaymentIntentService,
17
+ payouts: PayoutService,
16
18
  customers: CustomerService,
17
19
  billingStatements: BillingStatementService,
18
20
  billingStatementLineItems: BillingStatementLineItemService,