btrz-api-client 8.33.0 → 8.35.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.
Files changed (160) hide show
  1. package/lib/client-standalone-min.js +3 -3
  2. package/lib/client.js +10 -2
  3. package/lib/endpoints/btrzpay/adyen.js +58 -0
  4. package/lib/endpoints/btrzpay/cardpointe.js +6 -3
  5. package/lib/endpoints/btrzpay/customerCards.js +19 -19
  6. package/lib/endpoints/btrzpay/customers.js +13 -13
  7. package/lib/endpoints/btrzpay/cybersource3ds.js +142 -0
  8. package/lib/endpoints/btrzpay/datalogic.js +64 -28
  9. package/lib/endpoints/btrzpay/oxxo.js +54 -28
  10. package/lib/endpoints/btrzpay/prismaTerminals.js +24 -15
  11. package/lib/endpoints/btrzpay/referenced-payments.js +4 -4
  12. package/lib/endpoints/btrzpay/square.js +8 -8
  13. package/lib/endpoints/btrzpay/stripe-terminals.js +16 -11
  14. package/lib/endpoints/btrzpay/stripe3ds.js +54 -0
  15. package/lib/endpoints/btrzpay/terminalPayments.js +19 -19
  16. package/lib/endpoints/inventory/banks.js +39 -21
  17. package/lib/endpoints/inventory/change-requests.js +59 -31
  18. package/lib/endpoints/inventory/control-classes.js +39 -20
  19. package/lib/endpoints/inventory/countries.js +25 -9
  20. package/lib/endpoints/inventory/custom-content.js +39 -21
  21. package/lib/endpoints/inventory/custom-fields.js +25 -17
  22. package/lib/endpoints/inventory/document-types.js +33 -42
  23. package/lib/endpoints/inventory/external-wallets.js +26 -20
  24. package/lib/endpoints/inventory/fees.js +19 -13
  25. package/lib/endpoints/inventory/filtered-trips.js +34 -8
  26. package/lib/endpoints/inventory/financing-costs.js +19 -14
  27. package/lib/endpoints/inventory/garages.js +19 -14
  28. package/lib/endpoints/inventory/getnet-terminals.js +20 -15
  29. package/lib/endpoints/inventory/gift-certificate-definitions.js +10 -5
  30. package/lib/endpoints/inventory/holidays.js +158 -0
  31. package/lib/endpoints/inventory/insurances.js +17 -13
  32. package/lib/endpoints/inventory/items.js +13 -9
  33. package/lib/endpoints/inventory/labels.js +16 -11
  34. package/lib/endpoints/inventory/marital-status.js +16 -11
  35. package/lib/endpoints/inventory/marketplace-modifiers.js +16 -11
  36. package/lib/endpoints/inventory/mit-terminal-settings.js +15 -10
  37. package/lib/endpoints/inventory/mit-terminals.js +16 -11
  38. package/lib/endpoints/inventory/operation-messages.js +18 -12
  39. package/lib/endpoints/inventory/operation-reasons.js +15 -10
  40. package/lib/endpoints/inventory/pay-on-accounts.js +5 -4
  41. package/lib/endpoints/inventory/payment-terminals.js +15 -10
  42. package/lib/endpoints/inventory/products.js +22 -10
  43. package/lib/endpoints/inventory/promos.js +27 -18
  44. package/lib/endpoints/inventory/segments-information-tables.js +13 -7
  45. package/lib/endpoints/inventory/station-groups.js +2 -4
  46. package/lib/endpoints/inventory/taxes.js +11 -2
  47. package/lib/endpoints/inventory/traveller-card-providers-types.js +6 -6
  48. package/lib/endpoints/inventory/trip-ids.js +67 -0
  49. package/lib/endpoints/inventory/trips.js +60 -13
  50. package/lib/endpoints/inventory/vehicle-types.js +2 -5
  51. package/lib/endpoints/inventory/vehicles.js +4 -2
  52. package/lib/endpoints/invoices/emails.js +15 -5
  53. package/lib/endpoints/invoices/invoices.js +46 -25
  54. package/lib/endpoints/invoices/pdfs.js +15 -8
  55. package/lib/endpoints/invoices/providers.js +42 -25
  56. package/lib/endpoints/invoices/tax-ids.js +11 -7
  57. package/lib/endpoints/notifications/customers.js +1 -1
  58. package/lib/endpoints/notifications/external-customers.js +54 -0
  59. package/lib/endpoints/notifications/pdfs.js +0 -3
  60. package/lib/endpoints/operations/accounting_items.js +7 -1
  61. package/lib/endpoints/operations/flexpasses.js +9 -7
  62. package/lib/endpoints/operations/gift-certificates.js +53 -0
  63. package/lib/endpoints/operations/loans.js +16 -10
  64. package/lib/endpoints/operations/movements.js +17 -6
  65. package/lib/endpoints/operations/pago-express.js +96 -0
  66. package/lib/endpoints/operations/parcels.js +11 -11
  67. package/lib/endpoints/operations/parcels_manifests.js +7 -4
  68. package/lib/endpoints/sales/cancellations.js +43 -31
  69. package/lib/endpoints/sales/cart.js +21 -18
  70. package/lib/endpoints/sales/flexpasses.js +2 -5
  71. package/lib/endpoints/sales/order.js +41 -7
  72. package/lib/endpoints/sales/parcel-quotes.js +2 -2
  73. package/package.json +1 -1
  74. package/src/client.js +10 -2
  75. package/src/endpoints/btrzpay/adyen.js +44 -0
  76. package/src/endpoints/btrzpay/cardpointe.js +6 -4
  77. package/src/endpoints/btrzpay/customerCards.js +19 -19
  78. package/src/endpoints/btrzpay/customers.js +13 -13
  79. package/src/endpoints/btrzpay/cybersource3ds.js +114 -0
  80. package/src/endpoints/btrzpay/datalogic.js +63 -28
  81. package/src/endpoints/btrzpay/oxxo.js +53 -26
  82. package/src/endpoints/btrzpay/prismaTerminals.js +24 -15
  83. package/src/endpoints/btrzpay/referenced-payments.js +4 -4
  84. package/src/endpoints/btrzpay/square.js +8 -8
  85. package/src/endpoints/btrzpay/stripe-terminals.js +17 -10
  86. package/src/endpoints/btrzpay/stripe3ds.js +40 -0
  87. package/src/endpoints/btrzpay/terminalPayments.js +19 -19
  88. package/src/endpoints/inventory/banks.js +39 -21
  89. package/src/endpoints/inventory/change-requests.js +59 -31
  90. package/src/endpoints/inventory/control-classes.js +39 -20
  91. package/src/endpoints/inventory/countries.js +25 -10
  92. package/src/endpoints/inventory/custom-content.js +39 -22
  93. package/src/endpoints/inventory/custom-fields.js +25 -19
  94. package/src/endpoints/inventory/document-types.js +34 -33
  95. package/src/endpoints/inventory/external-wallets.js +25 -20
  96. package/src/endpoints/inventory/fees.js +19 -14
  97. package/src/endpoints/inventory/filtered-trips.js +29 -8
  98. package/src/endpoints/inventory/financing-costs.js +19 -14
  99. package/src/endpoints/inventory/garages.js +19 -14
  100. package/src/endpoints/inventory/getnet-terminals.js +20 -15
  101. package/src/endpoints/inventory/gift-certificate-definitions.js +10 -5
  102. package/src/endpoints/inventory/holidays.js +121 -0
  103. package/src/endpoints/inventory/insurances.js +17 -13
  104. package/src/endpoints/inventory/items.js +13 -9
  105. package/src/endpoints/inventory/labels.js +16 -11
  106. package/src/endpoints/inventory/marital-status.js +16 -11
  107. package/src/endpoints/inventory/marketplace-modifiers.js +16 -11
  108. package/src/endpoints/inventory/mit-terminal-settings.js +15 -10
  109. package/src/endpoints/inventory/mit-terminals.js +16 -11
  110. package/src/endpoints/inventory/operation-messages.js +18 -12
  111. package/src/endpoints/inventory/operation-reasons.js +15 -10
  112. package/src/endpoints/inventory/pay-on-accounts.js +5 -4
  113. package/src/endpoints/inventory/payment-terminals.js +15 -10
  114. package/src/endpoints/inventory/products.js +22 -10
  115. package/src/endpoints/inventory/promos.js +27 -18
  116. package/src/endpoints/inventory/segments-information-tables.js +13 -7
  117. package/src/endpoints/inventory/station-groups.js +2 -4
  118. package/src/endpoints/inventory/taxes.js +11 -2
  119. package/src/endpoints/inventory/traveller-card-providers-types.js +6 -5
  120. package/src/endpoints/inventory/trip-ids.js +54 -0
  121. package/src/endpoints/inventory/trips.js +52 -14
  122. package/src/endpoints/inventory/vehicle-types.js +3 -4
  123. package/src/endpoints/inventory/vehicles.js +4 -3
  124. package/src/endpoints/invoices/emails.js +15 -5
  125. package/src/endpoints/invoices/invoices.js +46 -25
  126. package/src/endpoints/invoices/pdfs.js +15 -8
  127. package/src/endpoints/invoices/providers.js +42 -25
  128. package/src/endpoints/invoices/tax-ids.js +11 -7
  129. package/src/endpoints/notifications/customers.js +1 -1
  130. package/src/endpoints/notifications/external-customers.js +41 -0
  131. package/src/endpoints/notifications/pdfs.js +0 -3
  132. package/src/endpoints/operations/accounting_items.js +7 -2
  133. package/src/endpoints/operations/flexpasses.js +9 -7
  134. package/src/endpoints/operations/gift-certificates.js +39 -0
  135. package/src/endpoints/operations/loans.js +16 -11
  136. package/src/endpoints/operations/movements.js +17 -6
  137. package/src/endpoints/operations/pago-express.js +73 -0
  138. package/src/endpoints/operations/parcels.js +11 -11
  139. package/src/endpoints/operations/parcels_manifests.js +7 -5
  140. package/src/endpoints/sales/cancellations.js +43 -31
  141. package/src/endpoints/sales/cart.js +20 -18
  142. package/src/endpoints/sales/flexpasses.js +3 -4
  143. package/src/endpoints/sales/order.js +34 -7
  144. package/src/endpoints/sales/parcel-quotes.js +2 -2
  145. package/test/endpoints/btrzpay/adyen.tests.js +27 -0
  146. package/test/endpoints/btrzpay/carpointe.tests.js +14 -0
  147. package/test/endpoints/btrzpay/customerCards.test.js +9 -6
  148. package/test/endpoints/btrzpay/cybersource3ds.tests.js +55 -0
  149. package/test/endpoints/btrzpay/stripe-terminals.tests.js +5 -6
  150. package/test/endpoints/btrzpay/stripe3ds.tests.js +31 -0
  151. package/test/endpoints/inventory/banks.test.js +8 -10
  152. package/test/endpoints/inventory/filtered-trips.test.js +6 -0
  153. package/test/endpoints/inventory/holidays.test.js +52 -0
  154. package/test/endpoints/inventory/traveller-card-providers-types.test.js +3 -2
  155. package/test/endpoints/inventory/trip-ids.test.js +27 -0
  156. package/test/endpoints/inventory/trips.test.js +19 -14
  157. package/test/endpoints/notifications/external-customers.test.js +30 -0
  158. package/test/endpoints/operations/gift_certificates.test.js +37 -0
  159. package/test/endpoints/operations/operations.test.js +30 -0
  160. package/test/endpoints/sales/order.test.js +7 -1
@@ -14,19 +14,25 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
14
14
  * @property {string} [providerId] - Provider account id
15
15
  */
16
16
 
17
+ /**
18
+ * Query params for PATCH /orders (btrz-api-sales patch-handler getSpec).
19
+ * @typedef {Object} OrderPatchQuery
20
+ * @property {string} [includePaidOrExpired] - 'true' or 'false'; whether to update when transaction is already paid or expired
21
+ */
22
+
17
23
  /**
18
24
  * Factory for order API (btrz-api-sales).
19
25
  * @param {Object} deps
20
26
  * @param {import("axios").AxiosInstance} deps.client
21
27
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
22
- * @returns {{ create: function, get: function, overwrite: function }}
28
+ * @returns {{ create: function, get: function, overwrite: function, patch: function }}
23
29
  */
24
30
  function orderFactory({client, internalAuthTokenProvider}) {
25
31
  /**
26
- * POST /order - create order.
32
+ * POST /order - create order. Body: orderRequest (cartId, customerInfo, payments, channel, etc.).
27
33
  * @param {Object} opts
28
34
  * @param {string} [opts.token] - API key
29
- * @param {Object} opts.order - Order payload
35
+ * @param {Object} opts.order - Order request body (orderRequest)
30
36
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
31
37
  * @param {Object} [opts.headers] - Optional headers
32
38
  * @returns {Promise<import("axios").AxiosResponse>}
@@ -58,11 +64,11 @@ function orderFactory({client, internalAuthTokenProvider}) {
58
64
  }
59
65
 
60
66
  /**
61
- * POST /orders/:orderId/payments - overwrite order payments.
67
+ * POST /orders/:orderId/payments - overwrite order payments. Body must include payments (array). Endpoint is internal (hideInDocumentation).
62
68
  * @param {Object} opts
63
69
  * @param {string} [opts.token] - API key
64
- * @param {string} opts.orderId - Order id
65
- * @param {Object} opts.payments - Payments payload
70
+ * @param {string} opts.orderId - Order (transaction) id
71
+ * @param {Object} opts.payments - Request body; must include property payments (array of payment objects)
66
72
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
67
73
  * @param {Object} [opts.headers] - Optional headers
68
74
  * @param {OrderPaymentsQuery} [opts.query] - Query params (channel, providerId)
@@ -78,10 +84,31 @@ function orderFactory({client, internalAuthTokenProvider}) {
78
84
  });
79
85
  }
80
86
 
87
+ /**
88
+ * PATCH /orders - complete order creation after referenced payment (e.g. waitForPaymentCompletion). Body: operation (name, data with transactionId, paymentResult). Query: includePaidOrExpired.
89
+ * @param {Object} opts
90
+ * @param {string} [opts.token] - API key
91
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
92
+ * @param {Object} [opts.headers] - Optional headers
93
+ * @param {Object} opts.operation - Operation object: { name, data: { transactionId, paymentResult } }
94
+ * @param {OrderPatchQuery} [opts.query] - Query params (includePaidOrExpired)
95
+ * @returns {Promise<import("axios").AxiosResponse>}
96
+ */
97
+ function patch({token, jwtToken, headers, operation, query = {}}) {
98
+ return client({
99
+ url: "/orders",
100
+ method: "patch",
101
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
102
+ data: {operation},
103
+ params: query
104
+ });
105
+ }
106
+
81
107
  return {
82
108
  create,
83
109
  get,
84
- overwrite
110
+ overwrite,
111
+ patch
85
112
  };
86
113
  }
87
114
 
@@ -12,10 +12,10 @@ const {
12
12
  */
13
13
  function parcelQuotesFactory({client, internalAuthTokenProvider}) {
14
14
  /**
15
- * POST /parcel-quotes - get parcel quote. API does not accept query params.
15
+ * POST /parcel-quotes - request a parcel quote. Body: parcelQuoteData (fromId, toId, productId, channel, parcels). API does not accept query params.
16
16
  * @param {Object} opts
17
17
  * @param {string} [opts.token] - API key
18
- * @param {Object} opts.parcelQuoteData - Parcel quote request payload
18
+ * @param {Object} opts.parcelQuoteData - Parcel quote request: fromId, toId, productId, channel, parcels (array of { fareId, weight, measure })
19
19
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
20
20
  * @param {Object} [opts.headers] - Optional headers
21
21
  * @returns {Promise<import("axios").AxiosResponse>}
@@ -0,0 +1,27 @@
1
+ const {axiosMock, expectRequest} = require("../../test-helpers.js");
2
+ const api = require("../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("btrzpay/adyen", () => {
5
+ const token = "api-key";
6
+ const jwtToken = "jwt-token";
7
+
8
+ afterEach(() => {
9
+ axiosMock.reset();
10
+ });
11
+
12
+ it("should get Adyen payment methods with token", () => {
13
+ axiosMock.onGet("/adyen-payment-methods").reply(expectRequest({statusCode: 200, token}));
14
+ return api.btrzpay.adyen.getPaymentMethods({token});
15
+ });
16
+
17
+ it("should get Adyen payment methods with token and jwtToken", () => {
18
+ axiosMock.onGet("/adyen-payment-methods").reply(expectRequest({statusCode: 200, token, jwtToken}));
19
+ return api.btrzpay.adyen.getPaymentMethods({token, jwtToken});
20
+ });
21
+
22
+ it("should get Adyen payment methods with query params", () => {
23
+ const query = {countryCode: "US", currencyCode: "USD", amount: 100, transactionId: "tx-1"};
24
+ axiosMock.onGet("/adyen-payment-methods", {params: query}).reply(expectRequest({statusCode: 200, token}));
25
+ return api.btrzpay.adyen.getPaymentMethods({token, query});
26
+ });
27
+ });
@@ -49,6 +49,20 @@ describe("btrzpay/cardpointe-terminals", () => {
49
49
  });
50
50
  });
51
51
 
52
+ it("should start the readCard process with providerId query", () => {
53
+ axiosMock.onPost("/cardpointe-terminals/read-card").reply((config) => {
54
+ const {expect} = require("chai");
55
+ expect(config.params).to.deep.equal({providerId: "provider-123"});
56
+ return [200, {readCardResultId: "id"}];
57
+ });
58
+ return api.btrzpay.cardpointeTerminals.readCard.create({
59
+ token,
60
+ jwtToken,
61
+ readCard: {terminalId: "1", merchantId: "2", amount: 10},
62
+ providerId: "provider-123"
63
+ });
64
+ });
65
+
52
66
  it("should call DELETE to reset a connection", () => {
53
67
  axiosMock.onDelete("/cardpointe-terminals/1/2").reply(expectRequest({
54
68
  statusCode: 200, token, jwtToken
@@ -1,5 +1,5 @@
1
- const {axiosMock, expectRequest} = require("../../test-helpers");
2
- const api = require("../../../src/client").createApiClient({baseURL: "http://test.com"});
1
+ const {axiosMock, expectRequest} = require("../../test-helpers.js");
2
+ const api = require("../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
3
 
4
4
  describe("btrzpay/customersCards", () => {
5
5
  const token = "token";
@@ -13,7 +13,8 @@ describe("btrzpay/customersCards", () => {
13
13
  const paymentMethodId = "5ad7804216b426412c19f06f";
14
14
  const customerId = "5ad7804216b426412c19f06g";
15
15
  const customerCardId = "5ad7804216b426412c19f77g";
16
- axiosMock.onGet(`/payment-methods/${paymentMethodId}/customers/${customerId}/cards/${customerCardId}`).reply(expectRequest({statusCode: 200, token}));
16
+ const path = `/payment-methods/${paymentMethodId}/customers/${customerId}/cards/${customerCardId}`;
17
+ axiosMock.onGet(path).reply(expectRequest({statusCode: 200, token}));
17
18
  return api.btrzpay.customerCards.get({
18
19
  token,
19
20
  paymentMethodId,
@@ -35,8 +36,9 @@ describe("btrzpay/customersCards", () => {
35
36
 
36
37
  it("should create a customer card", () => {
37
38
  const paymentMethodId = "5ad7804216b426412c19f06f";
38
- const customerId = "5ad7804216b426412c19f06g";
39
- axiosMock.onPost(`/payment-methods/${paymentMethodId}/customers/${customerId}/cards`).reply(expectRequest({statusCode: 200, token, jwtToken}));
39
+ const customerId = "5ad7804216b426412c19f06g";
40
+ const path = `/payment-methods/${paymentMethodId}/customers/${customerId}/cards`;
41
+ axiosMock.onPost(path).reply(expectRequest({statusCode: 200, token, jwtToken}));
40
42
  return api.btrzpay.customerCards.create({
41
43
  jwtToken,
42
44
  token,
@@ -53,7 +55,8 @@ describe("btrzpay/customersCards", () => {
53
55
  const paymentMethodId = "5ad7804216b426412c19f06f";
54
56
  const customerId = "5ad7804216b426412c19f06g";
55
57
  const customerCardId = "5ad7804216b426412c19f77g";
56
- axiosMock.onDelete(`/payment-methods/${paymentMethodId}/customers/${customerId}/cards/${customerCardId}`).reply(expectRequest({statusCode: 200, token, jwtToken}));
58
+ const path = `/payment-methods/${paymentMethodId}/customers/${customerId}/cards/${customerCardId}`;
59
+ axiosMock.onDelete(path).reply(expectRequest({statusCode: 200, token, jwtToken}));
57
60
  return api.btrzpay.customerCards.remove({
58
61
  jwtToken,
59
62
  token,
@@ -0,0 +1,55 @@
1
+ const {axiosMock, expectRequest} = require("../../test-helpers.js");
2
+ const api = require("../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("btrzpay/cybersource3ds", () => {
5
+ const token = "api-key";
6
+ const jwtToken = "jwt-token";
7
+
8
+ afterEach(() => {
9
+ axiosMock.reset();
10
+ });
11
+
12
+ describe("getToken", () => {
13
+ it("should get 3DS token with transactionId and token", () => {
14
+ const query = {transactionId: "507f1f77bcf86cd799439011"};
15
+ axiosMock.onGet("/cbs-token", {params: query}).reply(expectRequest({statusCode: 200, token}));
16
+ return api.btrzpay.cybersource3ds.getToken({token, query});
17
+ });
18
+
19
+ it("should get 3DS token with transactionId, optional operatingCompanyId, and jwtToken", () => {
20
+ const query = {transactionId: "507f1f77bcf86cd799439011", operatingCompanyId: "507f1f77bcf86cd799439012"};
21
+ axiosMock.onGet("/cbs-token", {params: query}).reply(expectRequest({statusCode: 200, token, jwtToken}));
22
+ return api.btrzpay.cybersource3ds.getToken({token, jwtToken, query});
23
+ });
24
+ });
25
+
26
+ describe("evaluateRisk", () => {
27
+ it("should POST evaluate-risk with riskEvaluation body and token", () => {
28
+ const riskEvaluation = {paymentData: {}, cartPayload: {}, operatingCompanyId: "op1"};
29
+ axiosMock.onPost("/cbs-evaluate-risk", riskEvaluation).reply(expectRequest({statusCode: 200, token, jwtToken}));
30
+ return api.btrzpay.cybersource3ds.evaluateRisk({token, jwtToken, riskEvaluation});
31
+ });
32
+
33
+ it("should POST evaluate-risk with jwtToken and headers", () => {
34
+ const riskEvaluation = {paymentData: {}};
35
+ axiosMock.onPost("/cbs-evaluate-risk", riskEvaluation).reply(expectRequest({statusCode: 200, token, jwtToken}));
36
+ return api.btrzpay.cybersource3ds.evaluateRisk({token, jwtToken, riskEvaluation, headers: {"X-Custom": "v"}});
37
+ });
38
+ });
39
+
40
+ describe("payerAuthenticationEnrollment", () => {
41
+ it("should POST payer authentication enrollment with body and token", () => {
42
+ const body = {paymentData: {}, operatingCompanyId: "op1"};
43
+ axiosMock.onPost("/cbs-pa-enrollment", body).reply(expectRequest({statusCode: 200, token, jwtToken}));
44
+ return api.btrzpay.cybersource3ds.payerAuthenticationEnrollment({token, jwtToken, body});
45
+ });
46
+ });
47
+
48
+ describe("validatePayerAuthenticationEnrollment", () => {
49
+ it("should POST validate payer authentication with body and token", () => {
50
+ const body = {paymentData: {}, processorTransactionId: "proc-tx-1"};
51
+ axiosMock.onPost("/cbs-validate-pa-enrollment", body).reply(expectRequest({statusCode: 200, token, jwtToken}));
52
+ return api.btrzpay.cybersource3ds.validatePayerAuthenticationEnrollment({token, jwtToken, body});
53
+ });
54
+ });
55
+ });
@@ -26,18 +26,17 @@ describe("btrzpay/stripe-terminals", () => {
26
26
  });
27
27
 
28
28
  it("should simulate a stripe terminal payment", () => {
29
- const data = {ccNumber: "4242424242424242"};
29
+ const stripePayment = {ccNumber: "4242424242424242"};
30
30
  const terminalId = "tm_123";
31
- axiosMock.onPost(`/stripe-terminals/${terminalId}/simulate`).reply(expectRequest({
32
- statusCode: 200, token, jwtToken, data
31
+ const body = {stripePayment};
32
+ axiosMock.onPost(`/stripe-terminals/${terminalId}/simulate`, body).reply(expectRequest({
33
+ statusCode: 200, token, jwtToken
33
34
  }));
34
35
  return api.btrzpay.stripeTerminals.simulate({
35
36
  id: terminalId,
36
37
  token,
37
38
  jwtToken,
38
- data: {
39
- stripePayment: data
40
- }
39
+ stripePayment
41
40
  });
42
41
  });
43
42
  });
@@ -0,0 +1,31 @@
1
+ const {axiosMock, expectRequest} = require("../../test-helpers.js");
2
+ const api = require("../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("btrzpay/stripe3ds", () => {
5
+ const token = "api-key";
6
+ const jwtToken = "jwt-token";
7
+
8
+ afterEach(() => {
9
+ axiosMock.reset();
10
+ });
11
+
12
+ describe("createPaymentIntent", () => {
13
+ it("should POST stripe-payment-intent with providerName and data using token and jwtToken", () => {
14
+ const body = {providerName: "stripe", data: {amount: "5.00", currency: "USD", transactionId: "123"}};
15
+ axiosMock.onPost("/stripe-payment-intent", body).reply(expectRequest({statusCode: 200, token, jwtToken}));
16
+ return api.btrzpay.stripe3ds.createPaymentIntent({token, jwtToken, providerName: "stripe", data: body.data});
17
+ });
18
+
19
+ it("should POST stripe-payment-intent with jwtToken and optional headers", () => {
20
+ const body = {providerName: "stripe", data: {}};
21
+ axiosMock.onPost("/stripe-payment-intent", body).reply(expectRequest({statusCode: 200, token, jwtToken}));
22
+ return api.btrzpay.stripe3ds.createPaymentIntent({
23
+ token,
24
+ jwtToken,
25
+ providerName: "stripe",
26
+ data: {},
27
+ headers: {"X-Custom": "v"}
28
+ });
29
+ });
30
+ });
31
+ });
@@ -12,18 +12,17 @@ describe("inventory/banks", () => {
12
12
  });
13
13
 
14
14
  it("should create a bank", () => {
15
- axiosMock.onPost("/banks").reply(expectRequest({statusCode: 200, token, jwtToken}));
15
+ const bank = {name: "My bank", accountNumbers: [{number: "123", currency: "USD", alias: "Main"}]};
16
+ axiosMock.onPost("/banks", {bank}).reply(expectRequest({statusCode: 200, token, jwtToken, body: {bank}}));
16
17
  return api.inventory.banks.create({
17
18
  jwtToken,
18
19
  token,
19
- banks: {
20
- name: "My bankl"
21
- }
20
+ bank
22
21
  });
23
22
  });
24
23
 
25
24
  it("should get all pieces of bank", () => {
26
- axiosMock.onGet("/banks").reply(expectRequest({statusCode: 200, token, jwtToken }));
25
+ axiosMock.onGet("/banks").reply(expectRequest({statusCode: 200, token, jwtToken}));
27
26
  return api.inventory.banks.all({
28
27
  jwtToken,
29
28
  token,
@@ -31,16 +30,15 @@ describe("inventory/banks", () => {
31
30
  });
32
31
  });
33
32
 
34
- it("should update a piece of bank", () => {
33
+ it("should update a bank", () => {
35
34
  const bankId = "1234";
36
- axiosMock.onPut(`/banks/${bankId}`).reply(expectRequest({ statusCode: 200, token, jwtToken }));
35
+ const bank = {name: "My Updated bank", accountNumbers: [{number: "123", currency: "USD", alias: "Main"}]};
36
+ axiosMock.onPut(`/banks/${bankId}`, {bank}).reply(expectRequest({statusCode: 200, token, jwtToken, body: {bank}}));
37
37
  return api.inventory.banks.update({
38
38
  jwtToken,
39
39
  token,
40
40
  bankId,
41
- banks: {
42
- name: "My Updated bank"
43
- }
41
+ bank
44
42
  });
45
43
  });
46
44
 
@@ -28,4 +28,10 @@ describe("inventory/filtered-trips", () => {
28
28
  axiosMock.onPost("/filtered-trips").reply(expectRequest({statusCode: 200, token, jwtToken}));
29
29
  return api.inventory.filteredTrips.create({token, jwtToken, tripSegmentsId: "myTripSegmentId"});
30
30
  });
31
+
32
+ it("should remove a filtered trip", () => {
33
+ const filteredTripId = "60c9200d17bda93f5c896bf3";
34
+ axiosMock.onDelete(`/filtered-trip/${filteredTripId}`).reply(expectRequest({statusCode: 204, token, jwtToken}));
35
+ return api.inventory.filteredTrips.remove({token, jwtToken, filteredTripId});
36
+ });
31
37
  });
@@ -0,0 +1,52 @@
1
+ describe("inventory/holidays", () => {
2
+ const {axiosMock, expectRequest} = require("./../../test-helpers.js");
3
+ const api = require("./../../../src/client.js").createApiClient({
4
+ baseURL: "http://test.com"
5
+ });
6
+
7
+ const token = "I owe you a token";
8
+ const jwtToken = "I owe you a JWT token";
9
+ const holidayId = "holiday-id-1";
10
+
11
+ afterEach(() => {
12
+ axiosMock.reset();
13
+ });
14
+
15
+ it("should list holidays", () => {
16
+ const query = {page: 1, providerId: "providerId1"};
17
+ axiosMock.onGet("/holidays").reply(expectRequest({statusCode: 200, token, query}));
18
+ return api.inventory.holidays.all({token, query});
19
+ });
20
+
21
+ it("should get a specific holiday by id", () => {
22
+ axiosMock.onGet(`/holidays/${holidayId}`).reply(expectRequest({
23
+ statusCode: 200, token, jwtToken
24
+ }));
25
+ return api.inventory.holidays.get({token, jwtToken, holidayId});
26
+ });
27
+
28
+ it("should create a new holiday", () => {
29
+ const holiday = {day: 25, month: 12, year: 2024, name: "Christmas"};
30
+ axiosMock.onPost("/holidays").reply(expectRequest({
31
+ statusCode: 200, token, jwtToken, body: {holiday}
32
+ }));
33
+ return api.inventory.holidays.create({jwtToken, token, holiday});
34
+ });
35
+
36
+ it("should update an existing holiday", () => {
37
+ const holiday = {day: 26, month: 12, year: 2024, name: "Boxing Day"};
38
+ axiosMock.onPut(`/holidays/${holidayId}`).reply(expectRequest({
39
+ statusCode: 200, token, jwtToken, body: {holiday}
40
+ }));
41
+ return api.inventory.holidays.update({
42
+ jwtToken, token, holiday, holidayId
43
+ });
44
+ });
45
+
46
+ it("should delete an existing holiday", () => {
47
+ axiosMock.onDelete(`/holidays/${holidayId}`).reply(expectRequest({
48
+ statusCode: 200, token, jwtToken
49
+ }));
50
+ return api.inventory.holidays.remove({jwtToken, token, holidayId});
51
+ });
52
+ });
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/extensions */
1
2
  const {axiosMock, expectRequest} = require("./../../test-helpers");
2
3
  const api = require("./../../../src/client").createApiClient({baseURL: "http://test.com"});
3
4
 
@@ -8,8 +9,8 @@ describe("inventory/traveller-card-providers-types", () => {
8
9
  axiosMock.reset();
9
10
  });
10
11
 
11
- it("should call the traveller card providers types endpoint", async () => {
12
+ it("should call the traveller card providers types endpoint", () => {
12
13
  axiosMock.onGet("/traveller-card-providers/types").reply(expectRequest({statusCode: 200, token}));
13
- api.inventory.travellerCardProvidersTypes.all({token});
14
+ return api.inventory.travellerCardProvidersTypes.all({token});
14
15
  });
15
16
  });
@@ -0,0 +1,27 @@
1
+ const {axiosMock, expectRequest} = require("./../../test-helpers.js");
2
+ const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("inventory/trip-ids", () => {
5
+ const token = "I owe you a token";
6
+ const jwtToken = "jwt-token";
7
+
8
+ afterEach(() => {
9
+ axiosMock.reset();
10
+ });
11
+
12
+ it("should create trip id (POST /direct-trip-ids)", () => {
13
+ const data = {
14
+ providerId: "5a9f2060d1aba834217f5b5e",
15
+ routeId: "5a9f2060d1aba834217f5b5f",
16
+ scheduleId: "schedule-1",
17
+ departureDate: "2025-03-06",
18
+ fareIds: "fare1:2",
19
+ channel: "backoffice",
20
+ productId: "5a9f2082d1aba6a732ae918a",
21
+ originId: "5a9f2082d1aba6a732ae918b",
22
+ destinationId: "5a9f2082d1aba6a732ae918c"
23
+ };
24
+ axiosMock.onPost("/direct-trip-ids", data).reply(expectRequest({statusCode: 200, token, jwtToken}));
25
+ return api.inventory.tripIds.create({token, jwtToken, data});
26
+ });
27
+ });
@@ -1,21 +1,26 @@
1
- const { axiosMock, expectRequest } = require("./../../test-helpers");
2
- const api = require("./../../../src/client").createApiClient({ baseURL: "http://test.com" });
1
+ const {axiosMock, expectRequest} = require("./../../test-helpers.js");
2
+ const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
3
 
4
- describe('inventory/trips', function() {
5
- const token = 'I owe you a token';
6
-
7
- afterEach(function() {
4
+ describe("inventory/trips", () => {
5
+ const token = "I owe you a token";
6
+
7
+ afterEach(() => {
8
8
  axiosMock.reset();
9
- })
9
+ });
10
10
 
11
- it("should list trips", function() {
12
- axiosMock.onGet(`/trips`).reply(expectRequest({ statusCode: 200, token }));
13
- return api.inventory.trips.all({ token });
11
+ it("should list trips", () => {
12
+ axiosMock.onGet("/trips").reply(expectRequest({statusCode: 200, token}));
13
+ return api.inventory.trips.all({token});
14
14
  });
15
15
 
16
- it("should get trip by id", function() {
17
- axiosMock.onGet(`/trip/1`).reply(expectRequest({ statusCode: 200, token }));
18
- return api.inventory.trips.get({ token, id: 1 });
16
+ it("should get trip by id", () => {
17
+ axiosMock.onGet("/trip/1").reply(expectRequest({statusCode: 200, token}));
18
+ return api.inventory.trips.get({token, id: 1});
19
19
  });
20
20
 
21
- });
21
+ it("should get pricing simulation", () => {
22
+ const query = {scheduleId: "5a9f2060d1aba834217f5b5e", productId: "5a9f2082d1aba6a732ae918a"};
23
+ axiosMock.onGet("/trips/pricing-simulation", {params: query}).reply(expectRequest({statusCode: 200, token}));
24
+ return api.inventory.trips.getPricingSimulation({token, query});
25
+ });
26
+ });
@@ -0,0 +1,30 @@
1
+ const {expect} = require("chai");
2
+ const {axiosMock} = require("./../../test-helpers.js");
3
+ const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
4
+
5
+ describe("notifications/external-customers", () => {
6
+ const jwtToken = "myJwtToken";
7
+ const token = "myApiKey";
8
+
9
+ afterEach(() => {
10
+ axiosMock.reset();
11
+ });
12
+
13
+ it("should POST to request Saldo Max verification code (ado/registration)", () => {
14
+ const data = {email: "user@example.com"};
15
+ axiosMock.onPost("/external-customers/ado/registration").reply((config) => {
16
+ expect(config.data).to.equal(JSON.stringify(data));
17
+ expect(config.headers["x-api-key"]).to.eql(token);
18
+ expect(config.headers.authorization).to.eql(`Bearer ${jwtToken}`);
19
+ return [200, {code: "success", message: "Registration successful"}];
20
+ });
21
+
22
+ return api.notifications.externalCustomers.requestSaldoMaxVerificationCode({
23
+ token,
24
+ jwtToken,
25
+ data
26
+ }).then((res) => {
27
+ expect(res.data).to.eql({code: "success", message: "Registration successful"});
28
+ });
29
+ });
30
+ });
@@ -0,0 +1,37 @@
1
+ const {axiosMock, expectRequest} = require("../../test-helpers.js");
2
+ const api = require("../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("operations/gift-certificates", () => {
5
+ const token = "test-api-key";
6
+ const jwtToken = "customer-jwt-token";
7
+
8
+ afterEach(() => {
9
+ axiosMock.reset();
10
+ });
11
+
12
+ it("should GET gift certificates for the given customer", () => {
13
+ const customer = "123-456-789";
14
+ axiosMock.onGet("/gift-certificates")
15
+ .reply(expectRequest({statusCode: 200, token, jwtToken, query: {customer}}));
16
+
17
+ return api.operations.giftCertificates.list({
18
+ jwtToken,
19
+ token,
20
+ customer
21
+ });
22
+ });
23
+
24
+ it("should GET gift certificates with optional page", () => {
25
+ const customer = "123-456-789";
26
+ const page = 2;
27
+ axiosMock.onGet("/gift-certificates")
28
+ .reply(expectRequest({statusCode: 200, token, jwtToken, query: {customer, page}}));
29
+
30
+ return api.operations.giftCertificates.list({
31
+ jwtToken,
32
+ token,
33
+ customer,
34
+ page
35
+ });
36
+ });
37
+ });
@@ -17,3 +17,33 @@ describe('operations/segments', function() {
17
17
  return api.operations.segments.all({ token, jwtToken, productId, ticketId });
18
18
  });
19
19
  });
20
+
21
+ describe("operations/pagoExpress", function() {
22
+ const token = "I owe you a token";
23
+ const jwtToken = "I owe you a JWT token";
24
+
25
+ afterEach(function() {
26
+ axiosMock.reset();
27
+ });
28
+
29
+ it("should post pago-express info", function() {
30
+ const payment = { folio: "10305108982123541235", id_terminal: 45875263254987452135, local_date: "18/06/1988 15:04:20", trx_no: 12345 };
31
+ axiosMock.onPost("/pago-express/info")
32
+ .reply(expectRequest({ statusCode: 200, token, jwtToken, body: { payment } }));
33
+ return api.operations.pagoExpress.info({ token, jwtToken, payment });
34
+ });
35
+
36
+ it("should post pago-express pay", function() {
37
+ const payment = { folio: "10305108982123541235", id_terminal: 45875263254987452135, local_date: "18/06/1988 15:04:20", trx_no: 12345, amount: "999.00" };
38
+ axiosMock.onPost("/pago-express/pay")
39
+ .reply(expectRequest({ statusCode: 200, token, jwtToken, body: { payment } }));
40
+ return api.operations.pagoExpress.pay({ token, jwtToken, payment });
41
+ });
42
+
43
+ it("should post pago-express reverse", function() {
44
+ const reversePayment = { folio: "10305108982123541235", id_terminal: 45875263254987452135, local_date: "18/06/1988 15:04:20", trx_no: 12345, amount: "999.00" };
45
+ axiosMock.onPost("/pago-express/reverse")
46
+ .reply(expectRequest({ statusCode: 200, token, jwtToken, body: { reversePayment } }));
47
+ return api.operations.pagoExpress.reverse({ token, jwtToken, reversePayment });
48
+ });
49
+ });
@@ -24,6 +24,12 @@ describe('sales/order', function() {
24
24
 
25
25
  it("should overwrite an order payment by id", function() {
26
26
  axiosMock.onPost(`/orders/${orderId}/payments`).reply(expectRequest({ statusCode: 200, token, jwtToken}));
27
- return api.sales.order.overwrite({ jwtToken, token, payments: [], orderId: "orderId1" });
27
+ return api.sales.order.overwrite({ jwtToken, token, payments: { payments: [] }, orderId: "orderId1" });
28
+ });
29
+
30
+ it("should patch an order (complete referenced payment)", function() {
31
+ const operation = { name: "completeReferencedPayment", data: { transactionId: "tx1", paymentResult: { status: "success" } } };
32
+ axiosMock.onPatch("/orders").reply(expectRequest({ statusCode: 200, token, jwtToken }));
33
+ return api.sales.order.patch({ jwtToken, token, operation });
28
34
  });
29
35
  });