btrz-api-client 8.33.0 → 8.34.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 (65) hide show
  1. package/lib/client-standalone-min.js +3 -3
  2. package/lib/client.js +6 -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/segments-information-tables.js +13 -7
  17. package/lib/endpoints/inventory/trip-ids.js +67 -0
  18. package/lib/endpoints/inventory/trips.js +60 -13
  19. package/lib/endpoints/invoices/emails.js +15 -5
  20. package/lib/endpoints/invoices/invoices.js +46 -25
  21. package/lib/endpoints/invoices/pdfs.js +15 -8
  22. package/lib/endpoints/invoices/providers.js +42 -25
  23. package/lib/endpoints/invoices/tax-ids.js +11 -7
  24. package/lib/endpoints/sales/cancellations.js +43 -31
  25. package/lib/endpoints/sales/cart.js +21 -18
  26. package/lib/endpoints/sales/flexpasses.js +2 -5
  27. package/lib/endpoints/sales/order.js +41 -7
  28. package/lib/endpoints/sales/parcel-quotes.js +2 -2
  29. package/package.json +1 -1
  30. package/src/client.js +6 -2
  31. package/src/endpoints/btrzpay/adyen.js +44 -0
  32. package/src/endpoints/btrzpay/cardpointe.js +6 -4
  33. package/src/endpoints/btrzpay/customerCards.js +19 -19
  34. package/src/endpoints/btrzpay/customers.js +13 -13
  35. package/src/endpoints/btrzpay/cybersource3ds.js +114 -0
  36. package/src/endpoints/btrzpay/datalogic.js +63 -28
  37. package/src/endpoints/btrzpay/oxxo.js +53 -26
  38. package/src/endpoints/btrzpay/prismaTerminals.js +24 -15
  39. package/src/endpoints/btrzpay/referenced-payments.js +4 -4
  40. package/src/endpoints/btrzpay/square.js +8 -8
  41. package/src/endpoints/btrzpay/stripe-terminals.js +17 -10
  42. package/src/endpoints/btrzpay/stripe3ds.js +40 -0
  43. package/src/endpoints/btrzpay/terminalPayments.js +19 -19
  44. package/src/endpoints/inventory/segments-information-tables.js +13 -7
  45. package/src/endpoints/inventory/trip-ids.js +54 -0
  46. package/src/endpoints/inventory/trips.js +52 -14
  47. package/src/endpoints/invoices/emails.js +15 -5
  48. package/src/endpoints/invoices/invoices.js +46 -25
  49. package/src/endpoints/invoices/pdfs.js +15 -8
  50. package/src/endpoints/invoices/providers.js +42 -25
  51. package/src/endpoints/invoices/tax-ids.js +11 -7
  52. package/src/endpoints/sales/cancellations.js +43 -31
  53. package/src/endpoints/sales/cart.js +20 -18
  54. package/src/endpoints/sales/flexpasses.js +3 -4
  55. package/src/endpoints/sales/order.js +34 -7
  56. package/src/endpoints/sales/parcel-quotes.js +2 -2
  57. package/test/endpoints/btrzpay/adyen.tests.js +27 -0
  58. package/test/endpoints/btrzpay/carpointe.tests.js +14 -0
  59. package/test/endpoints/btrzpay/customerCards.test.js +9 -6
  60. package/test/endpoints/btrzpay/cybersource3ds.tests.js +55 -0
  61. package/test/endpoints/btrzpay/stripe-terminals.tests.js +5 -6
  62. package/test/endpoints/btrzpay/stripe3ds.tests.js +31 -0
  63. package/test/endpoints/inventory/trip-ids.test.js +27 -0
  64. package/test/endpoints/inventory/trips.test.js +19 -14
  65. package/test/endpoints/sales/order.test.js +7 -1
@@ -1,22 +1,34 @@
1
1
  const {authorizationHeaders} = require("./../endpoints_helpers.js");
2
2
 
3
3
  /**
4
+ * Request body for POST /cancellations (btrz-api-sales). CancelPostData. Item IDs grouped by family; trxId required.
4
5
  * @typedef {{
5
- * fees: string[],
6
+ * trxId: string,
7
+ * fees: number[],
6
8
  * flexPasses: string[],
7
9
  * parcels: string[],
8
10
  * redeemableItems: string[],
9
11
  * soldItems: string[],
10
12
  * tickets: string[],
11
13
  * giftCertificates: string[],
14
+ * reservations: string[],
12
15
  * insurances: string[],
13
- * trxId: string,
14
- * penalty?: {
15
- * amount: number,
16
- * reason: string
17
- * }
18
- * }} CancelSetData
19
- *
16
+ * channel: string,
17
+ * penalty?: { amount: number, reason: string },
18
+ * overrideCancelFees?: Array<{ _id: string, reason: string }>,
19
+ * currency?: string,
20
+ * terminalPayload?: { status: string, provider: string, auth?: string },
21
+ * paymentDetails?: Array<{ _id: string, authorization: string }>
22
+ * }} CancelPostData
23
+ */
24
+
25
+ /**
26
+ * Request body for PUT /cancellations (btrz-api-sales). CancelPutData. Unmodified cancel set from POST response (must include _id and signature).
27
+ * @typedef {{ _id: string, cancellation: Object, signature: string }} CancelPutData
28
+ */
29
+
30
+ /**
31
+ * Request body for PUT /cancellations/:pendingTransactionId (btrz-api-sales). CompletePaymentCancellationData.
20
32
  * @typedef {{
21
33
  * provider: string,
22
34
  * type: string,
@@ -28,17 +40,17 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
28
40
  * referenceNumber: string,
29
41
  * authCode?: string
30
42
  * }} CompletePaymentCancellationData
31
- */
43
+ */
32
44
 
33
45
  function cancellationEndpointsFactory({client, internalAuthTokenProvider}) {
34
46
  /**
35
- * Creates a set of refundable items and payments to be refunded. API does not accept query params.
36
- * @param {Object} params
37
- * @param {string} params.token Public key
38
- * @param {string} params.jwtToken Auth token
39
- * @param {CancelSetData} params.cancelData List of item ids grouped by family
40
- * @param {Object} params.headers HTTP Headers
41
- * @returns {Promise} A cancel set object
47
+ * POST /cancellations - creates a cancel set (preview) with calculated refunds and signature. Does not execute refunds. API does not accept query params.
48
+ * @param {Object} opts
49
+ * @param {string} [opts.token] - API key
50
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
51
+ * @param {CancelPostData} opts.cancelData - Refundable item IDs by family, trxId, channel, penalty (optional), etc.
52
+ * @param {Object} [opts.headers] - Optional headers
53
+ * @returns {Promise<import("axios").AxiosResponse<{ _id: string, cancellation: Object, signature: string }>>} Cancel set (signed). Rejects with 400 (e.g. MISSING_CANCELLABLE_IDS, INVALID_CANCEL_SET, [itemType]_NOT_REFUNDABLE), 401, 403 (NOT_ALLOWED_FOR_ONLINE, FEE_OVERRIDE_NOT_ALLOWED), 404 ([itemType]_NOT_FOUND), 409 (CURRENCY_EXCHANGE_MISMATCH, AGENCY_CURRENCY_MISMATCH), 500.
42
54
  */
43
55
  function createCancelSet({token, jwtToken, cancelData, headers}) {
44
56
  return client({
@@ -52,13 +64,13 @@ function cancellationEndpointsFactory({client, internalAuthTokenProvider}) {
52
64
  }
53
65
 
54
66
  /**
55
- * Creates and runs payment refunds
56
- * @param {Object} params
57
- * @param {string} params.token Public key
58
- * @param {string} params.jwtToken Auth token
59
- * @param {Object} params.cancelSet An unmodified cancel set object generated by the cancellations endpoint
60
- * @param {Object} params.headers HTTP Headers
61
- * @returns {Promise} Refund result
67
+ * PUT /cancellations - executes the refund using the signed cancel set from POST. Body is cancelSet (or object with cancelSet key). API does not accept query params. Duplicate submission (same dupKey within 30s) returns 409.
68
+ * @param {Object} opts
69
+ * @param {string} [opts.token] - API key
70
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
71
+ * @param {CancelPutData} opts.cancelSet - Unmodified cancel set from createCancelSet response
72
+ * @param {Object} [opts.headers] - Optional headers
73
+ * @returns {Promise<import("axios").AxiosResponse<{ transaction: Object }>>} RefundResponse. Rejects with 400 (e.g. INVALID_SIGNATURE, MISSING_TERMINAL_PAYLOAD, REFUNDED_ITEM), 401, 409 (NOT_FOUND_FOR_REFUND, REFUND_EXECUTION_ERROR, PAYMENT_ROLLBACK_FAILED, CONFLICT duplicate), 500.
62
74
  */
63
75
  function createRefund({token, jwtToken, cancelSet, headers}) {
64
76
  return client({
@@ -70,14 +82,14 @@ function cancellationEndpointsFactory({client, internalAuthTokenProvider}) {
70
82
  }
71
83
 
72
84
  /**
73
- * Completes a pending payment for a cancellation transaction (e.g. one terminal refund). API does not accept query params.
74
- * @param {Object} params
75
- * @param {string} params.token Public key
76
- * @param {string} params.jwtToken Auth token
77
- * @param {string} params.pendingTransactionId Negative transaction id (ObjectId)
78
- * @param {CompletePaymentCancellationData} params.paymentResult Payment result for one completed terminal refund
79
- * @param {Object} params.headers HTTP Headers
80
- * @returns {Promise} Updated negative transaction (with remaining pending payments if any)
85
+ * PUT /cancellations/:pendingTransactionId - completes a pending payment for a cancellation transaction (e.g. terminal refund). API does not accept query params.
86
+ * @param {Object} opts
87
+ * @param {string} [opts.token] - API key
88
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
89
+ * @param {string} opts.pendingTransactionId - Negative (pending) transaction ID (ObjectId)
90
+ * @param {CompletePaymentCancellationData} opts.paymentResult - Payment result from terminal/provider
91
+ * @param {Object} [opts.headers] - Optional headers
92
+ * @returns {Promise<import("axios").AxiosResponse<{ transaction?: Object, paymentResult?: Object }>>} GetCompletePaymentCancellationResponse. Rejects with 400 (INVALID_PENDING_TRANSACTION_ID, INVALID_TRANSACTION_STATUS, PAYMENT_NOT_PENDING, etc.), 401, 404 (TRANSACTION_NOT_FOUND, PAYMENT_NOT_FOUND, etc.), 500.
81
93
  */
82
94
  function updateCompletePayment({token, jwtToken, pendingTransactionId, paymentResult, headers}) {
83
95
  return client({
@@ -20,6 +20,13 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
20
20
  * @property {string} [internalId] - Internal id or code of the financing cost to match
21
21
  */
22
22
 
23
+ /**
24
+ * Query params for DELETE /carts/:cartId/paid-in-items (btrz-api-sales delete-cart-paid-in-items-handler getSpec).
25
+ * @typedef {Object} CartDeletePaidInItemsQuery
26
+ * @property {string} [operationId] - Optional operation id to filter which paid-in items to remove
27
+ * @property {string} [productId] - Optional product id to filter which paid-in items to remove
28
+ */
29
+
23
30
  /**
24
31
  * Factory for cart API (btrz-api-sales).
25
32
  * @param {Object} deps
@@ -29,23 +36,18 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
29
36
  */
30
37
  function cartFactory({client, internalAuthTokenProvider}) {
31
38
  /**
32
- * GET /cart/:id - get cart by id. Query: providerId, transactionStatus (per get-cart getSpec).
39
+ * GET /cart/:id - get cart by id.
33
40
  * @param {Object} opts
34
41
  * @param {string} [opts.token] - API key
35
42
  * @param {string} opts.id - Cart id
36
- * @param {string} [opts.providerId] - Provider id (sent as query)
43
+ * @param {CartGetQuery} [opts.query] - Query params (providerId, transactionStatus)
37
44
  * @param {Object} [opts.headers] - Optional headers
38
45
  * @returns {Promise<import("axios").AxiosResponse>}
39
46
  */
40
- function get({token, id, providerId, headers}) {
41
- let url = `/cart/${id}`;
42
-
43
- if (providerId) {
44
- url = `${url}?providerId=${providerId}`;
45
- }
46
-
47
+ function get({token, id, query = {}, headers}) {
47
48
  return client({
48
- url,
49
+ url: `/cart/${id}`,
50
+ params: query,
49
51
  headers: authorizationHeaders({token, internalAuthTokenProvider, headers})
50
52
  });
51
53
  }
@@ -125,11 +127,11 @@ function cartFactory({client, internalAuthTokenProvider}) {
125
127
  }
126
128
 
127
129
  /**
128
- * DELETE /carts/:cartId/paid-in-items - delete paid-in items. Query forwarded via opts.params if provided.
130
+ * DELETE /carts/:cartId/paid-in-items - delete paid-in items.
129
131
  * @param {Object} opts
130
132
  * @param {string} [opts.token] - API key
131
133
  * @param {string} opts.cartId - Cart id
132
- * @param {Object} opts.params - Query params (forwarded to API)
134
+ * @param {CartDeletePaidInItemsQuery} [opts.params] - Query params (operationId, productId)
133
135
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
134
136
  * @param {Object} [opts.headers] - Optional headers
135
137
  * @returns {Promise<import("axios").AxiosResponse>}
@@ -139,7 +141,7 @@ function cartFactory({client, internalAuthTokenProvider}) {
139
141
  url: `/carts/${cartId}/paid-in-items`,
140
142
  method: "delete",
141
143
  headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
142
- params
144
+ params: params || {}
143
145
  });
144
146
  }
145
147
 
@@ -184,13 +186,13 @@ function cartFactory({client, internalAuthTokenProvider}) {
184
186
 
185
187
  const partialDepositStatus = {
186
188
  /**
187
- * GET /cart/:shiftId/partial-deposit-status - get partial deposit status. API does not accept query params.
189
+ * GET /cart/:shiftId/partial-deposit-status - get shift partial deposit status. API does not accept query params. Response: partialDeposit.
188
190
  * @param {Object} opts
189
191
  * @param {string} [opts.token] - API key
190
192
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
191
- * @param {string} opts.shiftId - Shift id
193
+ * @param {string} opts.shiftId - Shift id (24 hex characters)
192
194
  * @param {Object} [opts.headers] - Optional headers
193
- * @returns {Promise<import("axios").AxiosResponse>}
195
+ * @returns {Promise<import("axios").AxiosResponse<{ partialDeposit: * }>>}
194
196
  */
195
197
  get({token, jwtToken, shiftId, headers}) {
196
198
  return client.get(`/cart/${shiftId}/partial-deposit-status`, {
@@ -238,13 +240,13 @@ function cartFactory({client, internalAuthTokenProvider}) {
238
240
 
239
241
  const taxExemptPaymentMethod = {
240
242
  /**
241
- * POST /carts/:cartId/tax-exempt-payment-method - set tax exempt payment method. API does not accept query params.
243
+ * POST /carts/:cartId/tax-exempt-payment-method - recalculate taxes for a tax exempt payment method. Body: amountExempt (number).
242
244
  * @param {Object} opts
243
245
  * @param {string} [opts.token] - API key
244
246
  * @param {string} opts.cartId - Cart id
245
247
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
246
248
  * @param {Object} [opts.headers] - Optional headers
247
- * @param {Object} [opts.data] - Request body
249
+ * @param {Object} opts.data - Request body; must include amountExempt (number, amount exempted of taxes)
248
250
  * @returns {Promise<import("axios").AxiosResponse>}
249
251
  */
250
252
  post({token, cartId, jwtToken, headers, data = {}}) {
@@ -10,18 +10,17 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
10
10
  */
11
11
  function flexpassesEndpointsFactory({client, internalAuthTokenProvider}) {
12
12
  /**
13
- * GET /flexpasses/:flexpassId - get flexpass by id. API does not accept query params (btrz-api-sales).
13
+ * GET /flexpasses/:flexpassId - get flexpass by id. API does not accept query params.
14
14
  * @param {Object} opts
15
15
  * @param {string} [opts.token] - API key
16
16
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
17
- * @param {string} opts.flexpassId - Flexpass id
17
+ * @param {string} opts.flexpassId - Flexpass id (24 hex characters)
18
18
  * @param {Object} [opts.headers] - Optional headers
19
19
  * @returns {Promise<import("axios").AxiosResponse>}
20
20
  */
21
- function get({token, jwtToken, flexpassId, query = {}, headers}) {
21
+ function get({token, jwtToken, flexpassId, headers}) {
22
22
  return client({
23
23
  url: `/flexpasses/${flexpassId}`,
24
- params: query,
25
24
  headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
26
25
  });
27
26
  }
@@ -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
+ });
@@ -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
+ });
@@ -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
  });