@rebilly/instruments 3.9.4-beta.0 → 3.11.0-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebilly/instruments",
3
- "version": "3.9.4-beta.0",
3
+ "version": "3.11.0-beta.0",
4
4
  "author": "Rebilly",
5
5
  "main": "dist/index.js",
6
6
  "unpkg": "dist/index.min.js",
@@ -1,4 +1,4 @@
1
- import RebillyApi, {RebillyStorefrontAPI} from 'rebilly-js-sdk';
1
+ import RebillyApi, {RebillyStorefrontAPI, RebillyExperimentalAPI} from 'rebilly-js-sdk';
2
2
 
3
3
  export function validateStateForStorefront({state}) {
4
4
  if (!state.storefront) {
@@ -56,11 +56,15 @@ export class StorefrontInstance {
56
56
  // TODO: Check why Rollup is making the default as an named export
57
57
  const rebilly = typeof RebillyApi.default === 'function' ? RebillyApi.default(config) : RebillyApi(config);
58
58
 
59
+ const experimental = RebillyExperimentalAPI(config);
60
+
59
61
  api.setSessionToken(publishableKey || jwt);
60
62
  rebilly.setSessionToken(publishableKey || jwt);
63
+ experimental.setSessionToken(publishableKey || jwt);
61
64
 
62
65
  this.api = api;
63
66
  this.api.rebilly = rebilly;
67
+ this.api.rebilly.experimental = experimental;
64
68
 
65
69
  return this.api;
66
70
  }
@@ -33,6 +33,18 @@ export async function fetchReadyToPay({ state, riskMetadata = null }) {
33
33
  data.currency = money.currency;
34
34
  }
35
35
 
36
+ if (state.data?.account?.address) {
37
+ data.billingAddress = state.data.account.address;
38
+ } else {
39
+ const { fields } = await state.storefront.rebilly.experimental.location.query();
40
+ data.billingAddress = {
41
+ city: fields.city,
42
+ region: fields.region,
43
+ country: fields.country || state.options.countryCode,
44
+ postalCode: fields.zip
45
+ };
46
+ }
47
+
36
48
  const [
37
49
  { fields: readyToPayFields },
38
50
  { items: paymentMethodsMetadataItems }
@@ -41,11 +41,11 @@ describe('Storefront API Ready to Pay', () => {
41
41
 
42
42
  expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
43
43
  expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
44
- data: {
44
+ data: expect.objectContaining({
45
45
  items: options.items,
46
46
  websiteId: options.websiteId,
47
47
  riskMetadata: {}
48
- }
48
+ })
49
49
  });
50
50
  expect(response).toBeInstanceOf(Array);
51
51
  expect(response[0]).toBeInstanceOf(ReadyToPayModel);
@@ -63,6 +63,11 @@ export default function mountApplePay({
63
63
  updateBtnStyling();
64
64
  });
65
65
 
66
+ // HOTFIX: Hardcoded, use env variables in the future
67
+ const redirectUrl = state.options.apiMode === 'sandbox'
68
+ ? 'https://forms-sandbox.secure-payments.app/approval-url?close=true'
69
+ : 'https://forms.secure-payments.app/approval-url?close=true';
70
+
66
71
  Rebilly.on('token-ready', (token) => {
67
72
  const instrumentReadyPayload = {
68
73
  websiteId: state.options.websiteId,
@@ -71,6 +76,7 @@ export default function mountApplePay({
71
76
  token: token.id,
72
77
  },
73
78
  billingAddress: token.billingAddress,
79
+ redirectUrl,
74
80
  _raw: token
75
81
  }
76
82
  if (!token.shippingAddress) {