payrex-node 0.1.7 → 1.0.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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.0] - 2024-09-04
4
+
5
+ - Add billing statement endpoints
6
+ - Add customer endpoints
7
+
8
+ Breaking change
9
+ - Standardize the use of arrays in resources. The `payment_intent` attribute of CheckoutSession resource is now an array. Previously, this attribute is a PaymentIntent resource.
10
+
3
11
  ## [0.1.7] - 2024-07-30
4
12
 
5
13
  - Add amount_capturable and amount_received for hold then capture partial amount support.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payrex-node",
3
- "version": "0.1.7",
3
+ "version": "1.0.0",
4
4
  "description": "PayRex Node JS Library",
5
5
  "keywords": [
6
6
  "payrex",
@@ -0,0 +1,24 @@
1
+ function BillingStatementEntity(apiResource) {
2
+ const data = apiResource.data;
3
+
4
+ this.id = data.id;
5
+ this.amount = data.amount;
6
+ this.currency = data.currency;
7
+ this.customerId = data.customer_id;
8
+ this.description = data.description;
9
+ this.dueAt = data.due_at;
10
+ this.finalizedAt = data.finalized_at;
11
+ this.billingStatementNumber = data.billing_statement_number;
12
+ this.billingStatementUrl = data.billing_statement_url;
13
+ this.lineItems = data.line_items;
14
+ this.livemode = data.livemode;
15
+ this.metadata = data.metadata;
16
+ this.paymentIntent = data.payment_intent;
17
+ this.status = data.status;
18
+ this.paymentSettings = data.payment_settings;
19
+ this.customer = data.customer;
20
+ this.createdAt = data.created_at;
21
+ this.updatedAt = data.updated_at;
22
+ }
23
+
24
+ module.exports = BillingStatementEntity;
@@ -0,0 +1,14 @@
1
+ function BillingStatementLineItemEntity(apiResource) {
2
+ const data = apiResource.data;
3
+
4
+ this.id = data.id;
5
+ this.unitPrice = data.unit_price;
6
+ this.quantity = data.quantity;
7
+ this.billingStatementId = data.billing_statement_id;
8
+ this.description = data.description;
9
+ this.livemode = data.livemode;
10
+ this.createdAt = data.created_at;
11
+ this.updatedAt = data.updated_at;
12
+ }
13
+
14
+ module.exports = BillingStatementLineItemEntity;
@@ -1,5 +1,3 @@
1
- const PaymentIntentEntity = require("./PaymentIntentEntity");
2
-
3
1
  function CheckoutSessionEntity(apiResource) {
4
2
  const data = apiResource.data;
5
3
 
@@ -11,9 +9,7 @@ function CheckoutSessionEntity(apiResource) {
11
9
  this.lineItems = data.line_items;
12
10
  this.livemode = data.livemode;
13
11
  this.url = data.url;
14
- this.paymentIntent = new PaymentIntentEntity({
15
- data: data.payment_intent
16
- });
12
+ this.paymentIntent = data.payment_intent;
17
13
  this.metadata = data.metadata;
18
14
  this.successUrl = data.success_url;
19
15
  this.cancelUrl = data.cancel_url;
@@ -0,0 +1,16 @@
1
+ function CustomerEntity(apiResource) {
2
+ const data = apiResource.data;
3
+
4
+ this.id = data.id;
5
+ this.billingStatementPrefix = data.billing_statement_prefix;
6
+ this.currency = data.currency;
7
+ this.email = data.email;
8
+ this.livemode = data.livemode;
9
+ this.name = data.name;
10
+ this.metadata = data.metadata;
11
+ this.nextBillingStatementSequenceNumber = data.next_billing_statement_sequence_number;
12
+ this.createdAt = data.created_at;
13
+ this.updatedAt = data.updated_at;
14
+ }
15
+
16
+ module.exports = CustomerEntity;
@@ -0,0 +1,8 @@
1
+ function DeletedEntity(apiResource) {
2
+ const data = apiResource.data;
3
+
4
+ this.id = data.id;
5
+ this.deleted = data.deleted;
6
+ }
7
+
8
+ module.exports = DeletedEntity;
@@ -0,0 +1,51 @@
1
+ const BaseService = require('./BaseService');
2
+ const BillingStatementLineItemEntity = require('../entities/BillingStatementLineItemEntity');
3
+ const DeletedEntity = require('../entities/DeletedEntity');
4
+
5
+ function BillingStatementLineItemService(client) {
6
+ BaseService.call(this, client);
7
+
8
+ this.path = 'billing_statement_line_items';
9
+ }
10
+
11
+ BillingStatementLineItemService.prototype.create = function (payload) {
12
+ return this.request({
13
+ path: this.path,
14
+ payload: payload,
15
+ method: 'post',
16
+ }).then(function (response) {
17
+ return new BillingStatementLineItemEntity(response);
18
+ });
19
+ };
20
+
21
+ BillingStatementLineItemService.prototype.retrieve = function (id) {
22
+ return this.request({
23
+ path: `${this.path}/${id}`,
24
+ method: 'get',
25
+ }).then(function (response) {
26
+ return new BillingStatementLineItemEntity(response);
27
+ });
28
+ };
29
+
30
+ BillingStatementLineItemService.prototype.update = function (id, payload) {
31
+ return this.request({
32
+ path: `${this.path}/${id}`,
33
+ payload: payload,
34
+ method: 'put',
35
+ }).then(function (response) {
36
+ return new BillingStatementLineItemEntity(response);
37
+ });
38
+ };
39
+
40
+ BillingStatementLineItemService.prototype.delete = function (id) {
41
+ return this.request({
42
+ path: `${this.path}/${id}`,
43
+ method: 'delete',
44
+ }).then(function (response) {
45
+ return new DeletedEntity(response);
46
+ });
47
+ };
48
+
49
+ Object.setPrototypeOf(BillingStatementLineItemService.prototype, BaseService.prototype);
50
+
51
+ module.exports = BillingStatementLineItemService;
@@ -0,0 +1,98 @@
1
+ const BaseService = require('./BaseService');
2
+ const BillingStatementEntity = require('../entities/BillingStatementEntity');
3
+ const DeletedEntity = require('../entities/DeletedEntity');
4
+ const ListingEntity = require('../entities/ListingEntity');
5
+ const ApiResource = require('../ApiResource');
6
+
7
+ function BillingStatementService(client) {
8
+ BaseService.call(this, client);
9
+
10
+ this.path = 'billing_statements';
11
+ }
12
+
13
+ BillingStatementService.prototype.create = function (payload) {
14
+ return this.request({
15
+ path: this.path,
16
+ payload: payload,
17
+ method: 'post',
18
+ }).then(function (response) {
19
+ return new BillingStatementEntity(response);
20
+ });
21
+ };
22
+
23
+ BillingStatementService.prototype.retrieve = function (id) {
24
+ return this.request({
25
+ path: `${this.path}/${id}`,
26
+ method: 'get',
27
+ }).then(function (response) {
28
+ return new BillingStatementEntity(response);
29
+ });
30
+ };
31
+
32
+ BillingStatementService.prototype.list = function (payload) {
33
+ return this.request({
34
+ path: this.path,
35
+ payload: payload,
36
+ method: 'get',
37
+ }).then(function (response) {
38
+ const sessionsData = response.data.data;
39
+
40
+ const data = sessionsData.map((session) => {
41
+ const apiResource = new ApiResource(session);
42
+
43
+ return new BillingStatementEntity(apiResource);
44
+ });
45
+
46
+ return new ListingEntity(data, response.data.has_more);
47
+ });
48
+ };
49
+
50
+ BillingStatementService.prototype.update = function (id, payload) {
51
+ return this.request({
52
+ path: `${this.path}/${id}`,
53
+ payload: payload,
54
+ method: 'put',
55
+ }).then(function (response) {
56
+ return new BillingStatementEntity(response);
57
+ });
58
+ };
59
+
60
+ BillingStatementService.prototype.delete = function (id) {
61
+ return this.request({
62
+ path: `${this.path}/${id}`,
63
+ method: 'delete',
64
+ }).then(function (response) {
65
+ return new DeletedEntity(response);
66
+ });
67
+ };
68
+
69
+ BillingStatementService.prototype.finalize = function (id) {
70
+ return this.request({
71
+ path: `${this.path}/${id}/finalize`,
72
+ method: 'post',
73
+ }).then(function (response) {
74
+ return new BillingStatementEntity(response);
75
+ });
76
+ };
77
+
78
+ BillingStatementService.prototype.void = function (id) {
79
+ return this.request({
80
+ path: `${this.path}/${id}/void`,
81
+ method: 'post',
82
+ }).then(function (response) {
83
+ return new BillingStatementEntity(response);
84
+ });
85
+ };
86
+
87
+ BillingStatementService.prototype.markUncollectible = function (id) {
88
+ return this.request({
89
+ path: `${this.path}/${id}/mark_uncollectible`,
90
+ method: 'post',
91
+ }).then(function (response) {
92
+ return new BillingStatementEntity(response);
93
+ });
94
+ };
95
+
96
+ Object.setPrototypeOf(BillingStatementService.prototype, BaseService.prototype);
97
+
98
+ module.exports = BillingStatementService;
@@ -0,0 +1,71 @@
1
+ const BaseService = require('./BaseService');
2
+ const CustomerEntity = require('../entities/CustomerEntity');
3
+ const DeletedEntity = require('../entities/DeletedEntity');
4
+ const ListingEntity = require('../entities/ListingEntity');
5
+ const ApiResource = require('../ApiResource');
6
+
7
+ function CustomerService(client) {
8
+ BaseService.call(this, client);
9
+
10
+ this.path = 'customers';
11
+ }
12
+
13
+ CustomerService.prototype.create = function (payload) {
14
+ return this.request({
15
+ path: this.path,
16
+ payload: payload,
17
+ method: 'post',
18
+ }).then(function (response) {
19
+ return new CustomerEntity(response);
20
+ });
21
+ };
22
+
23
+ CustomerService.prototype.retrieve = function (id) {
24
+ return this.request({
25
+ path: `${this.path}/${id}`,
26
+ method: 'get',
27
+ }).then(function (response) {
28
+ return new CustomerEntity(response);
29
+ });
30
+ };
31
+
32
+ CustomerService.prototype.list = function (payload) {
33
+ return this.request({
34
+ path: this.path,
35
+ payload: payload,
36
+ method: 'get',
37
+ }).then(function (response) {
38
+ const sessionsData = response.data.data;
39
+
40
+ const data = sessionsData.map((session) => {
41
+ const apiResource = new ApiResource(session);
42
+
43
+ return new CustomerEntity(apiResource);
44
+ });
45
+
46
+ return new ListingEntity(data, response.data.has_more);
47
+ });
48
+ };
49
+
50
+ CustomerService.prototype.update = function (id, payload) {
51
+ return this.request({
52
+ path: `${this.path}/${id}`,
53
+ payload: payload,
54
+ method: 'put',
55
+ }).then(function (response) {
56
+ return new CustomerEntity(response);
57
+ });
58
+ };
59
+
60
+ CustomerService.prototype.delete = function (id) {
61
+ return this.request({
62
+ path: `${this.path}/${id}`,
63
+ method: 'delete',
64
+ }).then(function (response) {
65
+ return new DeletedEntity(response);
66
+ });
67
+ };
68
+
69
+ Object.setPrototypeOf(CustomerService.prototype, BaseService.prototype);
70
+
71
+ module.exports = CustomerService;
@@ -1,6 +1,7 @@
1
1
  const crypto = require('crypto');
2
2
  const BaseService = require('./BaseService');
3
3
  const WebhookEntity = require('../entities/WebhookEntity');
4
+ const DeletedEntity = require('../entities/DeletedEntity');
4
5
  const ListingEntity = require('../entities/ListingEntity');
5
6
  const ApiResource = require('../ApiResource');
6
7
  const EventEntity = require('../entities/EventEntity');
@@ -82,7 +83,7 @@ WebhookService.prototype.delete = function (id) {
82
83
  path: `${this.path}/${id}`,
83
84
  method: 'delete',
84
85
  }).then(function (response) {
85
- return new WebhookEntity(response);
86
+ return new DeletedEntity(response);
86
87
  });
87
88
  };
88
89
 
@@ -1,15 +1,17 @@
1
+ const BillingStatementLineItemService = require('./BillingStatementLineItemService');
2
+ const BillingStatementService = require('./BillingStatementService');
1
3
  const CheckoutSessionService = require('./CheckoutSessionService');
2
- const MerchantService = require('./MerchantService');
4
+ const CustomerService = require('./CustomerService');
3
5
  const PaymentIntentService = require('./PaymentIntentService');
4
- const PaymentMethodService = require('./PaymentMethodService');
5
6
  const RefundService = require('./RefundService');
6
7
  const WebhookService = require('./WebhookService');
7
8
 
8
9
  module.exports = {
9
10
  checkoutSessions: CheckoutSessionService,
10
- merchants: MerchantService,
11
11
  paymentIntents: PaymentIntentService,
12
- paymentMethods: PaymentMethodService,
12
+ customers: CustomerService,
13
+ billingStatements: BillingStatementService,
14
+ billingStatementLineItems: BillingStatementLineItemService,
13
15
  refunds: RefundService,
14
16
  webhooks: WebhookService,
15
17
  };
@@ -1,11 +0,0 @@
1
- function MerchantEntity(apiResource) {
2
- const data = apiResource.data;
3
-
4
- this.id = data.id;
5
- this.connectionType = data.connection_type;
6
- this.livemode = data.livemode;
7
- this.createdAt = data.created_at;
8
- this.updatedAt = data.updated_at;
9
- }
10
-
11
- module.exports = MerchantEntity;
@@ -1,13 +0,0 @@
1
- function PaymentMethodEntity(apiResource) {
2
- const data = apiResource.data;
3
-
4
- this.id = data.id;
5
- this.type = data.type;
6
- this.billingDetails = data.billing_details;
7
- this.livemode = data.livemode;
8
- this.metadata = data.metadata;
9
- this.createdAt = data.created_at;
10
- this.updatedAt = data.updated_at;
11
- }
12
-
13
- module.exports = PaymentMethodEntity;
@@ -1,21 +0,0 @@
1
- const BaseService = require('./BaseService');
2
- const MerchantEntity = require('../entities/MerchantEntity');
3
-
4
- function MerchantService(client) {
5
- BaseService.call(this, client);
6
- this.path = 'merchants';
7
- }
8
-
9
- MerchantService.prototype.create = function (payload) {
10
- return this.request({
11
- path: this.path,
12
- payload: payload,
13
- method: 'post',
14
- }).then(function (response) {
15
- return new MerchantEntity(response);
16
- });
17
- };
18
-
19
- Object.setPrototypeOf(MerchantService.prototype, BaseService.prototype);
20
-
21
- module.exports = MerchantService;
@@ -1,21 +0,0 @@
1
- const BaseService = require('./BaseService');
2
- const PaymentMethodEntity = require('../entities/PaymentMethodEntity');
3
-
4
- function PaymentMethodService(client) {
5
- BaseService.call(this, client);
6
- this.path = 'payment_methods';
7
- }
8
-
9
- PaymentMethodService.prototype.create = function (payload) {
10
- return this.request({
11
- path: this.path,
12
- payload: payload,
13
- method: 'post',
14
- }).then(function (response) {
15
- return new PaymentMethodEntity(response);
16
- });
17
- };
18
-
19
- Object.setPrototypeOf(PaymentMethodService.prototype, BaseService.prototype);
20
-
21
- module.exports = PaymentMethodService;