@rebilly/instruments 3.0.0-beta.0 → 3.1.2-beta.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 (169) hide show
  1. package/dist/index.js +88 -107
  2. package/dist/index.min.js +88 -0
  3. package/package.json +17 -6
  4. package/rollup.config.js +84 -0
  5. package/src/functions/mount/fetch-data.js +13 -1
  6. package/src/functions/mount/index.js +6 -42
  7. package/src/functions/mount/setup-framepay-theme.js +2 -2
  8. package/src/functions/mount/setup-options.js +3 -0
  9. package/src/functions/mount/setup-user-flow.js +49 -0
  10. package/src/functions/purchase.js +1 -1
  11. package/src/functions/setup.js +1 -1
  12. package/src/functions/show.spec.js +1 -1
  13. package/src/i18n/en.json +3 -0
  14. package/src/i18n/index.js +1 -1
  15. package/src/index.js +1 -61
  16. package/src/instance.js +65 -0
  17. package/src/{index.spec.js → instance.spec.js} +2 -1
  18. package/src/loader/index.js +21 -1
  19. package/src/storefront/models/ready-to-pay-model.js +13 -2
  20. package/src/storefront/plans.js +8 -4
  21. package/src/storefront/plans.spec.js +8 -2
  22. package/src/storefront/products.js +8 -4
  23. package/src/storefront/products.spec.js +8 -2
  24. package/src/storefront/ready-to-pay.js +5 -4
  25. package/src/style/base/__snapshots__/theme.spec.js.snap +34 -2
  26. package/src/style/base/default-theme.js +106 -3
  27. package/src/style/components/button.js +17 -1
  28. package/src/style/components/forms/label.js +0 -5
  29. package/src/style/components/loader.js +2 -1
  30. package/src/style/payment-instruments/payment-card.js +2 -1
  31. package/src/style/utils/remove-empty-null.js +9 -9
  32. package/src/style/vendor/postmate.js +13 -0
  33. package/src/style/views/confirmation.js +2 -1
  34. package/src/views/common/iframe/base-iframe.js +2 -0
  35. package/src/views/common/iframe/event-listeners.js +10 -0
  36. package/src/views/common/iframe/method-iframe.js +3 -1
  37. package/src/views/confirmation.js +1 -0
  38. package/src/views/method-selector/express-methods/{google-pay.js → index.js} +3 -2
  39. package/src/views/method-selector/mount-express-methods.js +6 -18
  40. package/src/views/result.js +1 -0
  41. package/tests/mocks/rebilly-instruments-mock.js +2 -2
  42. package/dist/events/base-event.js +0 -66
  43. package/dist/events/events.spec.js +0 -18
  44. package/dist/events/index.js +0 -22
  45. package/dist/functions/destroy.js +0 -34
  46. package/dist/functions/destroy.spec.js +0 -69
  47. package/dist/functions/mount/fetch-data.js +0 -187
  48. package/dist/functions/mount/fetch-data.spec.js +0 -189
  49. package/dist/functions/mount/index.js +0 -218
  50. package/dist/functions/mount/mount.spec.js +0 -64
  51. package/dist/functions/mount/setup-element.js +0 -40
  52. package/dist/functions/mount/setup-framepay-theme.js +0 -95
  53. package/dist/functions/mount/setup-framepay.js +0 -46
  54. package/dist/functions/mount/setup-i18n.js +0 -33
  55. package/dist/functions/mount/setup-options.js +0 -99
  56. package/dist/functions/mount/setup-options.spec.js +0 -66
  57. package/dist/functions/mount/setup-storefront.js +0 -34
  58. package/dist/functions/mount/setup-styles.js +0 -43
  59. package/dist/functions/on.js +0 -40
  60. package/dist/functions/on.spec.js +0 -55
  61. package/dist/functions/purchase.js +0 -158
  62. package/dist/functions/purchase.spec.js +0 -74
  63. package/dist/functions/setup.js +0 -85
  64. package/dist/functions/setup.spec.js +0 -87
  65. package/dist/functions/show.js +0 -55
  66. package/dist/functions/show.spec.js +0 -61
  67. package/dist/functions/update.js +0 -74
  68. package/dist/functions/update.spec.js +0 -86
  69. package/dist/i18n/en.json +0 -22
  70. package/dist/i18n/es.json +0 -22
  71. package/dist/i18n/i18n.spec.js +0 -22
  72. package/dist/i18n/index.js +0 -72
  73. package/dist/index.spec.js +0 -35
  74. package/dist/loader/index.js +0 -94
  75. package/dist/loader/loader.spec.js +0 -69
  76. package/dist/storefront/index.js +0 -73
  77. package/dist/storefront/invoices.js +0 -27
  78. package/dist/storefront/models/base-model.js +0 -18
  79. package/dist/storefront/models/invoice-model.js +0 -14
  80. package/dist/storefront/models/plan-model.js +0 -14
  81. package/dist/storefront/models/product-model.js +0 -14
  82. package/dist/storefront/models/ready-to-pay-model.js +0 -46
  83. package/dist/storefront/models/summary-model.js +0 -79
  84. package/dist/storefront/models/transaction-model.js +0 -31
  85. package/dist/storefront/payment-instruments.js +0 -47
  86. package/dist/storefront/payment-instruments.spec.js +0 -55
  87. package/dist/storefront/plans.js +0 -37
  88. package/dist/storefront/plans.spec.js +0 -64
  89. package/dist/storefront/products.js +0 -40
  90. package/dist/storefront/products.spec.js +0 -65
  91. package/dist/storefront/purchase.js +0 -43
  92. package/dist/storefront/purchase.spec.js +0 -48
  93. package/dist/storefront/ready-to-pay.js +0 -58
  94. package/dist/storefront/ready-to-pay.spec.js +0 -69
  95. package/dist/storefront/storefront.spec.js +0 -15
  96. package/dist/storefront/summary.js +0 -55
  97. package/dist/storefront/summary.spec.js +0 -124
  98. package/dist/storefront/transactions.js +0 -27
  99. package/dist/style/base/__snapshots__/theme.spec.js.snap +0 -195
  100. package/dist/style/base/default-theme.js +0 -699
  101. package/dist/style/base/index.js +0 -104
  102. package/dist/style/base/theme.js +0 -41
  103. package/dist/style/base/theme.spec.js +0 -19
  104. package/dist/style/browserslist.js +0 -8
  105. package/dist/style/components/address.js +0 -64
  106. package/dist/style/components/button.js +0 -71
  107. package/dist/style/components/divider.js +0 -48
  108. package/dist/style/components/forms/checkbox.js +0 -86
  109. package/dist/style/components/forms/field.js +0 -65
  110. package/dist/style/components/forms/form.js +0 -28
  111. package/dist/style/components/forms/input.js +0 -86
  112. package/dist/style/components/forms/label.js +0 -69
  113. package/dist/style/components/forms/select.js +0 -95
  114. package/dist/style/components/forms/validation.js +0 -81
  115. package/dist/style/components/icons.js +0 -22
  116. package/dist/style/components/index.js +0 -57
  117. package/dist/style/components/loader.js +0 -50
  118. package/dist/style/components/methods.js +0 -108
  119. package/dist/style/components/overlay.js +0 -33
  120. package/dist/style/helpers/index.js +0 -59
  121. package/dist/style/index.js +0 -50
  122. package/dist/style/payment-instruments/content.js +0 -17
  123. package/dist/style/payment-instruments/index.js +0 -20
  124. package/dist/style/payment-instruments/payment-card.js +0 -35
  125. package/dist/style/utils/border.js +0 -47
  126. package/dist/style/utils/color-values.js +0 -58
  127. package/dist/style/utils/remove-empty-null.js +0 -20
  128. package/dist/style/vendor/framepay.js +0 -37
  129. package/dist/style/vendor/postmate.js +0 -17
  130. package/dist/style/views/confirmation.js +0 -85
  131. package/dist/style/views/index.js +0 -29
  132. package/dist/style/views/method-selector.js +0 -20
  133. package/dist/style/views/modal.js +0 -93
  134. package/dist/style/views/result.js +0 -61
  135. package/dist/style/views/summary.js +0 -127
  136. package/dist/utils/add-dom-element.js +0 -26
  137. package/dist/utils/format-currency.js +0 -15
  138. package/dist/utils/has-valid-css-selector.js +0 -11
  139. package/dist/utils/index.js +0 -55
  140. package/dist/utils/is-dom-element.js +0 -10
  141. package/dist/utils/process-property-as-dom-element.js +0 -38
  142. package/dist/utils/sleep.js +0 -10
  143. package/dist/views/__snapshots__/summary.spec.js.snap +0 -246
  144. package/dist/views/common/iframe/base-iframe.js +0 -59
  145. package/dist/views/common/iframe/event-listeners.js +0 -50
  146. package/dist/views/common/iframe/index.js +0 -19
  147. package/dist/views/common/iframe/method-iframe.js +0 -33
  148. package/dist/views/common/iframe/modal-iframe.js +0 -84
  149. package/dist/views/common/iframe/view-iframe.js +0 -31
  150. package/dist/views/common/render-utilities.js +0 -11
  151. package/dist/views/confirmation.js +0 -92
  152. package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -3
  153. package/dist/views/method-selector/express-methods/apple-pay.js +0 -92
  154. package/dist/views/method-selector/express-methods/google-pay.js +0 -31
  155. package/dist/views/method-selector/express-methods/paypal.js +0 -19
  156. package/dist/views/method-selector/generate-digital-wallet.js +0 -68
  157. package/dist/views/method-selector/generate-digital-wallet.spec.js +0 -135
  158. package/dist/views/method-selector/get-method-data.js +0 -25
  159. package/dist/views/method-selector/get-payment-methods.js +0 -66
  160. package/dist/views/method-selector/get-payment-methods.spec.js +0 -46
  161. package/dist/views/method-selector/index.js +0 -122
  162. package/dist/views/method-selector/method-selector.spec.js +0 -124
  163. package/dist/views/method-selector/mount-express-methods.js +0 -69
  164. package/dist/views/method-selector/mount-methods.js +0 -74
  165. package/dist/views/modal.js +0 -88
  166. package/dist/views/result.js +0 -40
  167. package/dist/views/summary.js +0 -215
  168. package/dist/views/summary.spec.js +0 -134
  169. package/src/views/method-selector/express-methods/paypal.js +0 -7
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setupPaymentInstrument = setupPaymentInstrument;
7
-
8
- var _index = require("./index");
9
-
10
- async function setupPaymentInstrument({
11
- data,
12
- state
13
- }) {
14
- return (0, _index.Endpoint)({
15
- state
16
- }, async () => {
17
- // Create payment instrument
18
- const {
19
- fields: instrument
20
- } = await state.storefront.paymentInstruments.create({
21
- data
22
- }); // Setup the payment instrument
23
-
24
- state.storefront.setSessionToken(instrument.token);
25
- const setupPayload = {
26
- id: instrument.id,
27
- data: {
28
- websiteId: state.options.websiteId,
29
- ...data
30
- }
31
- };
32
-
33
- if (state.data.getAmountAndCurrency) {
34
- setupPayload.data = { ...setupPayload.data,
35
- ...state.data.getAmountAndCurrency
36
- };
37
- }
38
-
39
- const {
40
- fields: transaction
41
- } = await state.storefront.paymentInstruments.setup(setupPayload);
42
- return {
43
- instrument,
44
- transaction
45
- };
46
- });
47
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- describe('Storefront API Setup', () => {
12
- it('can make purchase', async () => {
13
- const instance = new _storefrontMock.StorefontTestingInstance();
14
- const paymentInstrumentFields = {
15
- id: 'payment-instrument-id'
16
- };
17
- const paymentInstrumentSetupFields = {
18
- id: 'payment-instrument-id',
19
- approvalUrl: null
20
- };
21
- const paymentInstrumentPayload = {
22
- data: {
23
- token: 'test-token'
24
- }
25
- };
26
- const paymentInstrumentSetupPayload = {
27
- id: paymentInstrumentFields.id,
28
- data: {
29
- websiteId: 'website-id',
30
- currency: 'USD',
31
- amount: 30
32
- }
33
- };
34
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/payment-instruments`)).thenReturn((0, _mswWhenThen.ok)(paymentInstrumentFields));
35
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/payment-instruments/*/setup`)).thenReturn((0, _mswWhenThen.ok)(paymentInstrumentSetupFields));
36
- jest.spyOn(instance.storefront.paymentInstruments, 'create');
37
- jest.spyOn(instance.storefront.paymentInstruments, 'setup');
38
- const paymentInstrumentResponse = await instance.storefront.paymentInstruments.create(paymentInstrumentPayload);
39
- const paymentInstrumentSetupResponse = await instance.storefront.paymentInstruments.setup(paymentInstrumentSetupPayload);
40
- expect(instance.storefront.paymentInstruments.create).toBeCalledTimes(1);
41
- expect(instance.storefront.paymentInstruments.create).toBeCalledWith(paymentInstrumentPayload);
42
- expect(instance.storefront.paymentInstruments.setup).toBeCalledTimes(1);
43
- expect(instance.storefront.paymentInstruments.setup).toBeCalledWith(paymentInstrumentSetupPayload);
44
- expect(paymentInstrumentResponse.config).toBeInstanceOf(Object);
45
- expect(paymentInstrumentResponse.fields).toBeInstanceOf(Object);
46
- expect(paymentInstrumentResponse.response).toBeInstanceOf(Object);
47
- expect(paymentInstrumentResponse.fields).toEqual(paymentInstrumentFields);
48
- expect(paymentInstrumentResponse.fields).toMatchObject(paymentInstrumentFields);
49
- expect(paymentInstrumentSetupResponse.config).toBeInstanceOf(Object);
50
- expect(paymentInstrumentSetupResponse.fields).toBeInstanceOf(Object);
51
- expect(paymentInstrumentSetupResponse.response).toBeInstanceOf(Object);
52
- expect(paymentInstrumentSetupResponse.fields).toEqual(paymentInstrumentSetupFields);
53
- expect(paymentInstrumentSetupResponse.fields).toMatchObject(paymentInstrumentSetupFields);
54
- });
55
- });
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchPlans = fetchPlans;
7
-
8
- var _planModel = _interopRequireDefault(require("./models/plan-model"));
9
-
10
- var _index = require("./index");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- async function fetchPlans({
15
- state = {},
16
- data = {}
17
- }) {
18
- return (0, _index.Endpoint)({
19
- state
20
- }, async () => {
21
- const lineItems = data.lineItems || state.data.summaryLineItems;
22
- const filterByPlanId = {
23
- filter: ''
24
- };
25
-
26
- if (lineItems.length) {
27
- filterByPlanId.filter = `id:${lineItems.map(item => item.planId).join(',')}`;
28
- }
29
-
30
- const {
31
- items: planItems
32
- } = await state.storefront.plans.getAll(filterByPlanId);
33
- return planItems.map(({
34
- fields
35
- }) => new _planModel.default(fields));
36
- });
37
- }
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- var _plans = require("./plans");
12
-
13
- var _planModel = _interopRequireDefault(require("./models/plan-model"));
14
-
15
- var _asyncUtilities = require("../../tests/async-utilities");
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- describe('Storefront API Plan', () => {
20
- it('can fetch plans', async () => {
21
- const testPlan = {
22
- name: 'Test Plan',
23
- id: 'test-plan-id-1'
24
- };
25
- (0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((0, _mswWhenThen.ok)([testPlan]));
26
- const instance = new _storefrontMock.StorefontTestingInstance();
27
- jest.spyOn(instance.storefront.plans, 'getAll');
28
- const response = await (0, _plans.fetchPlans)({
29
- state: instance
30
- });
31
- expect(instance.storefront.plans.getAll).toBeCalledTimes(1);
32
- expect(instance.storefront.plans.getAll).toBeCalledWith({
33
- filter: ''
34
- });
35
- expect(response).toBeInstanceOf(Array);
36
- expect(response[0]).toBeInstanceOf(_planModel.default);
37
- expect(response).toEqual([new _planModel.default(testPlan)]);
38
- });
39
- it('can fetch plans with filter', async () => {
40
- const instance = new _storefrontMock.StorefontTestingInstance();
41
- jest.spyOn(instance.storefront.plans, 'getAll');
42
- await (0, _plans.fetchPlans)({
43
- state: instance,
44
- data: {
45
- lineItems: [{
46
- planId: 'test-plan-id-1'
47
- }, {
48
- planId: 'test-plan-id-2'
49
- }]
50
- }
51
- });
52
- expect(instance.storefront.plans.getAll).toBeCalledWith({
53
- filter: 'id:test-plan-id-1,test-plan-id-2'
54
- });
55
- });
56
- it('should throw errors with no options', async () => {
57
- const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
58
- options: null
59
- });
60
- await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
61
- state: noConfigOrOptionsInstance
62
- }));
63
- });
64
- });
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchProducts = fetchProducts;
7
-
8
- var _productModel = _interopRequireDefault(require("./models/product-model"));
9
-
10
- var _index = require("./index");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- async function fetchProducts({
15
- state
16
- }) {
17
- return (0, _index.Endpoint)({
18
- state
19
- }, async () => {
20
- if (state.data.plans === null) {
21
- return null;
22
- }
23
-
24
- const plansData = state.data.plans || [];
25
- const filterByProductId = {
26
- filter: ''
27
- };
28
-
29
- if (plansData.length) {
30
- filterByProductId.filter = `id:${plansData.map(item => item.productId).join(',')}`;
31
- }
32
-
33
- const {
34
- items: productItems
35
- } = await state.storefront.products.getAll(filterByProductId);
36
- return productItems.map(({
37
- fields
38
- }) => new _productModel.default(fields));
39
- });
40
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- var _products = require("./products");
12
-
13
- var _productModel = _interopRequireDefault(require("./models/product-model"));
14
-
15
- var _asyncUtilities = require("../../tests/async-utilities");
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- describe('Storefront API Plan', () => {
20
- it('can fetch products', async () => {
21
- const testProduct = {
22
- name: 'Test Product',
23
- id: 'test-product-id-1'
24
- };
25
- (0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((0, _mswWhenThen.ok)([testProduct]));
26
- const instance = new _storefrontMock.StorefontTestingInstance();
27
- jest.spyOn(instance.storefront.products, 'getAll');
28
- const response = await (0, _products.fetchProducts)({
29
- state: instance
30
- });
31
- expect(instance.storefront.products.getAll).toBeCalledTimes(1);
32
- expect(instance.storefront.products.getAll).toBeCalledWith({
33
- filter: ''
34
- });
35
- expect(response).toBeInstanceOf(Array);
36
- expect(response[0]).toBeInstanceOf(_productModel.default);
37
- expect(response).toEqual([new _productModel.default(testProduct)]);
38
- });
39
- it('can fetch products with filter', async () => {
40
- const instance = new _storefrontMock.StorefontTestingInstance({
41
- data: {
42
- plans: [{
43
- productId: 'test-product-1'
44
- }, {
45
- productId: 'test-product-2'
46
- }]
47
- }
48
- });
49
- jest.spyOn(instance.storefront.products, 'getAll');
50
- await (0, _products.fetchProducts)({
51
- state: instance
52
- });
53
- expect(instance.storefront.products.getAll).toBeCalledWith({
54
- filter: 'id:test-product-1,test-product-2'
55
- });
56
- });
57
- it('should throw errors with no options', async () => {
58
- const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
59
- options: null
60
- });
61
- await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
62
- state: noConfigOrOptionsInstance
63
- }));
64
- });
65
- });
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.postPurchase = postPurchase;
7
- exports.postPayment = postPayment;
8
-
9
- var _index = require("./index");
10
-
11
- async function postPurchase({
12
- data,
13
- state
14
- }) {
15
- return (0, _index.Endpoint)({
16
- state
17
- }, async () => {
18
- if (data._raw) {
19
- delete data._raw;
20
- }
21
-
22
- return state.storefront.purchase.purchase({
23
- data
24
- });
25
- });
26
- }
27
-
28
- async function postPayment({
29
- data,
30
- state
31
- }) {
32
- return (0, _index.Endpoint)({
33
- state
34
- }, async () => {
35
- if (data._raw) {
36
- delete data._raw;
37
- }
38
-
39
- return state.storefront.purchase.payment({
40
- data
41
- });
42
- });
43
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- describe('Storefront API Purchase', () => {
12
- it('can make purchase', async () => {
13
- const instance = (0, _storefrontMock.StorefontTestingInstance)();
14
- const payload = {
15
- websiteId: 'test-website-id',
16
- items: [{
17
- planId: 'test-plan-id-1',
18
- quantity: 1
19
- }],
20
- billingAddress: {
21
- firstName: 'Test',
22
- lastName: 'Customer'
23
- },
24
- paymentInstruction: {
25
- token: 'test-token'
26
- }
27
- };
28
- const fields = {
29
- orderId: 'test-order-id',
30
- invoice: {
31
- id: 'test-invoice-id'
32
- },
33
- transaction: {
34
- id: 'test-transaction-id'
35
- }
36
- };
37
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/purchase`)).thenReturn((0, _mswWhenThen.ok)(fields));
38
- jest.spyOn(instance.storefront.purchase, 'purchase');
39
- const requestResponse = await instance.storefront.purchase.purchase(payload);
40
- expect(instance.storefront.purchase.purchase).toBeCalledTimes(1);
41
- expect(instance.storefront.purchase.purchase).toBeCalledWith(payload);
42
- expect(requestResponse.config).toBeInstanceOf(Object);
43
- expect(requestResponse.fields).toBeInstanceOf(Object);
44
- expect(requestResponse.response).toBeInstanceOf(Object);
45
- expect(requestResponse.fields).toEqual(fields);
46
- expect(requestResponse.fields).toMatchObject(fields);
47
- });
48
- });
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchReadyToPay = fetchReadyToPay;
7
-
8
- var _riskDataCollector = require("@rebilly/risk-data-collector");
9
-
10
- var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
11
-
12
- var _index = require("./index");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- async function fetchReadyToPay({
17
- state,
18
- riskMetadata = null
19
- }) {
20
- return (0, _index.Endpoint)({
21
- state
22
- }, async () => {
23
- var _state$options, _state$options2, _state$data;
24
-
25
- if (!riskMetadata) {
26
- const {
27
- riskMetadata: data
28
- } = await (0, _riskDataCollector.collectData)();
29
- riskMetadata = data;
30
- }
31
-
32
- const websiteId = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.websiteId) || null;
33
- const data = {
34
- websiteId,
35
- riskMetadata
36
- };
37
-
38
- if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.items) {
39
- data.items = state.options.items;
40
- }
41
-
42
- if ((_state$data = state.data) !== null && _state$data !== void 0 && _state$data.amountAndCurrency) {
43
- const money = state.data.amountAndCurrency;
44
- data.amount = money.amount;
45
- data.currency = money.currency;
46
- }
47
-
48
- const {
49
- fields: readyToPayFields
50
- } = await state.storefront.purchase.readyToPay({
51
- data
52
- });
53
- return Object.values(readyToPayFields).map((fields, index) => new _readyToPayModel.default({
54
- index,
55
- ...fields
56
- }));
57
- });
58
- }
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- var _mswWhenThen = require("msw-when-then");
6
-
7
- var _server = require("../../tests/msw/server");
8
-
9
- var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
10
-
11
- var _readyToPay = require("./ready-to-pay");
12
-
13
- var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
14
-
15
- var _asyncUtilities = require("../../tests/async-utilities");
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- describe('Storefront API Ready to Pay', () => {
20
- it('can fetch ready to pay', async () => {
21
- const readyToPayPayload = [{
22
- method: 'payment-card',
23
- feature: null,
24
- brands: ['Visa'],
25
- filters: []
26
- }];
27
- const options = {
28
- websiteId: 'test-website-id',
29
- items: [{
30
- planId: 'test-plan-id',
31
- quantity: 1
32
- }]
33
- };
34
- (0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/ready-to-pay`)).thenReturn((0, _mswWhenThen.ok)(readyToPayPayload));
35
- const instance = (0, _storefrontMock.StorefontTestingInstance)({
36
- options
37
- });
38
- jest.spyOn(instance.storefront.purchase, 'readyToPay');
39
- const riskMetadata = null;
40
- const response = await (0, _readyToPay.fetchReadyToPay)({
41
- state: instance,
42
- riskMetadata
43
- });
44
- expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
45
- expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
46
- data: {
47
- items: options.items,
48
- websiteId: options.websiteId,
49
- riskMetadata: {}
50
- }
51
- });
52
- expect(response).toBeInstanceOf(Array);
53
- expect(response[0]).toBeInstanceOf(_readyToPayModel.default);
54
- expect(response).toEqual([new _readyToPayModel.default({
55
- index: 0,
56
- ...readyToPayPayload[0]
57
- })]);
58
- });
59
- it('should throw errors with no options', async () => {
60
- const riskMetadata = null;
61
- const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
62
- options: null
63
- });
64
- await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
65
- riskMetadata,
66
- state: noConfigOrOptionsInstance
67
- }));
68
- });
69
- });
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- var _storefrontMock = require("../../tests/mocks/storefront-mock");
4
-
5
- describe('Storefront application programming interface', () => {
6
- it('can create rebilly-js-sdk instance', () => {
7
- const storefront = (0, _storefrontMock.MockStorefront)();
8
- expect(storefront).toHaveProperty('setPublishableKey');
9
- });
10
- it('has required endpoints', () => {
11
- const storefront = (0, _storefrontMock.MockStorefront)();
12
- expect(storefront).toHaveProperty('purchase');
13
- expect(storefront.purchase).toHaveProperty('readyToPay');
14
- });
15
- });
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fetchSummary = fetchSummary;
7
-
8
- var _summaryModel = _interopRequireDefault(require("./models/summary-model"));
9
-
10
- var _index = require("./index");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- async function fetchSummary({
15
- data = null,
16
- state = null
17
- } = {}) {
18
- return (0, _index.Endpoint)({
19
- state
20
- }, async () => {
21
- var _state$options, _state$options2, _state$data;
22
-
23
- const websiteId = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.websiteId) || null;
24
- const payload = {
25
- data: {
26
- websiteId
27
- }
28
- };
29
-
30
- if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.items) {
31
- payload.data.items = state.options.items;
32
- }
33
-
34
- if ((_state$data = state.data) !== null && _state$data !== void 0 && _state$data.amountAndCurrency) {
35
- payload.data = { ...payload.data,
36
- ...state.data.amountAndCurrency
37
- };
38
- }
39
-
40
- if (data !== null && data !== void 0 && data.billingAddress) {
41
- payload.data.billingAddress = data.billingAddress;
42
- }
43
-
44
- if (data !== null && data !== void 0 && data.deliveryAddress) {
45
- payload.data.deliveryAddress = data.deliveryAddress;
46
- }
47
-
48
- const {
49
- fields: summaryFields
50
- } = await state.storefront.purchase.preview(payload); // In case of preview purchase gets call again for updating the values
51
-
52
- state.data.previewPurchase = summaryFields;
53
- return new _summaryModel.default(summaryFields);
54
- });
55
- }