fontdue-js 1.12.2 → 1.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.12.3
2
+
3
+ - Fix Stripe integration for Apple Pay
4
+
1
5
  ## 1.12.2
2
6
 
3
7
  - Fixes an issue completing checkout with a 100% coupon
@@ -31,7 +31,7 @@ const FontdueProvider = _ref => {
31
31
  stripeIntegration
32
32
  }));
33
33
  const configValue = (0, _ConfigContext.makeConfig)(config);
34
- const store = (0, _redux.createStore)(_reducer.default, {
34
+ const store = (0, _react.useRef)((0, _redux.createStore)(_reducer.default, {
35
35
  selectedSkuIds: {},
36
36
  // { [skuId]: Boolean }
37
37
  licenseOptions: [],
@@ -49,11 +49,11 @@ const FontdueProvider = _ref => {
49
49
  }
50
50
  },
51
51
  storeModalHistory: []
52
- });
52
+ }));
53
53
  return /*#__PURE__*/_react.default.createElement(_reactRelay.RelayEnvironmentProvider, {
54
54
  environment: environment.current
55
55
  }, /*#__PURE__*/_react.default.createElement(_reactRedux.Provider, {
56
- store: store
56
+ store: store.current
57
57
  }, /*#__PURE__*/_react.default.createElement(_Stylesheet.StylesheetContainer, null), /*#__PURE__*/_react.default.createElement(_ThemeConfig.default, null), /*#__PURE__*/_react.default.createElement(_ConfigContext.default.Provider, {
58
58
  value: configValue
59
59
  }, /*#__PURE__*/_react.default.createElement(_ComponentsContext.default.Provider, {
@@ -35,7 +35,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
35
35
  const submitCompleteMutation = _StoreModalReviewCompleteOrderMutation !== void 0 ? _StoreModalReviewCompleteOrderMutation : (_StoreModalReviewCompleteOrderMutation = require("../../__generated__/StoreModalReviewCompleteOrderMutation.graphql"), _StoreModalReviewCompleteOrderMutation.hash && _StoreModalReviewCompleteOrderMutation.hash !== "de20197df49deb030c473adbd9560e03" && console.error("The definition of 'StoreModalReviewCompleteOrderMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _StoreModalReviewCompleteOrderMutation);
36
36
  const updateOrderMutation = _StoreModalReviewUpdateOrderMutation !== void 0 ? _StoreModalReviewUpdateOrderMutation : (_StoreModalReviewUpdateOrderMutation = require("../../__generated__/StoreModalReviewUpdateOrderMutation.graphql"), _StoreModalReviewUpdateOrderMutation.hash && _StoreModalReviewUpdateOrderMutation.hash !== "5ee297fdd5931c542d2f683651e54643" && console.error("The definition of 'StoreModalReviewUpdateOrderMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _StoreModalReviewUpdateOrderMutation);
37
37
  const StoreModalReview = _ref => {
38
- var _order$stripePaymentI, _order$total, _order$orderItems, _viewer$settings;
38
+ var _order$stripePaymentI, _order$orderItems, _viewer$settings;
39
39
  let {
40
40
  viewer: viewerKey,
41
41
  order: orderKey
@@ -63,8 +63,27 @@ const StoreModalReview = _ref => {
63
63
  stripe = (0, _reactStripeJs.useStripe)();
64
64
  elements = (0, _reactStripeJs.useElements)();
65
65
  }
66
- const lastShownTotal = (0, _react.useRef)(order === null || order === void 0 ? void 0 : (_order$total = order.total) === null || _order$total === void 0 ? void 0 : _order$total.amount);
66
+ (0, _react.useEffect)(() => {
67
+ // first do an `update` mutation without any inputs, which will make sure
68
+ // the total has been calculated from the latest coupon data. if the total
69
+ // doesn't change, submit the payment
70
+ (0, _relayRuntime.commitMutation)(environment, {
71
+ mutation: updateOrderMutation,
72
+ variables: {
73
+ input: {}
74
+ },
75
+ onCompleted: (response, errors) => {
76
+ if (errors && errors.length > 0) {
77
+ setCompleting(false);
78
+ setError(errors[0].message);
79
+ scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
80
+ return;
81
+ }
82
+ }
83
+ });
84
+ }, []);
67
85
  const handleSubmit = () => {
86
+ var _stripe, _billingIdentity$stre, _billingIdentity$stre2;
68
87
  if (!order) return;
69
88
  if (!billingIdentity) {
70
89
  console.error('No billing identity, required for payment');
@@ -87,63 +106,35 @@ const StoreModalReview = _ref => {
87
106
  });
88
107
  return;
89
108
  }
90
-
91
- // first do an `update` mutation without any inputs, which will make sure
92
- // the total has been calculated from the latest coupon data. if the total
93
- // doesn't change, submit the payment
94
- (0, _relayRuntime.commitMutation)(environment, {
95
- mutation: updateOrderMutation,
96
- variables: {
97
- input: {}
98
- },
99
- onCompleted: (response, errors) => {
100
- var _response$updateOrder, _response$updateOrder2, _response$updateOrder3, _stripe, _billingIdentity$stre, _billingIdentity$stre2;
101
- if (errors && errors.length > 0) {
102
- setCompleting(false);
103
- setError(errors[0].message);
104
- scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
105
- return;
106
- }
107
- const newTotal = (_response$updateOrder = response.updateOrder) === null || _response$updateOrder === void 0 ? void 0 : (_response$updateOrder2 = _response$updateOrder.order) === null || _response$updateOrder2 === void 0 ? void 0 : (_response$updateOrder3 = _response$updateOrder2.total) === null || _response$updateOrder3 === void 0 ? void 0 : _response$updateOrder3.amount;
108
- if (newTotal !== lastShownTotal.current) {
109
- var _response$updateOrder4, _response$updateOrder5, _response$updateOrder6;
110
- setCompleting(false);
111
- setError('Order total has updated. Please review and confirm again.');
112
- scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
113
- lastShownTotal.current = (_response$updateOrder4 = response.updateOrder) === null || _response$updateOrder4 === void 0 ? void 0 : (_response$updateOrder5 = _response$updateOrder4.order) === null || _response$updateOrder5 === void 0 ? void 0 : (_response$updateOrder6 = _response$updateOrder5.total) === null || _response$updateOrder6 === void 0 ? void 0 : _response$updateOrder6.amount;
114
- return;
115
- }
116
- if (!stripe || !elements) return;
117
- (_stripe = stripe) === null || _stripe === void 0 ? void 0 : _stripe.confirmPayment({
118
- elements,
119
- confirmParams: {
120
- return_url: order.completeUrl,
121
- payment_method_data: {
122
- billing_details: {
123
- email: billingIdentity.email,
124
- name: billingIdentity.name,
125
- address: {
126
- line1: (_billingIdentity$stre = billingIdentity.street) === null || _billingIdentity$stre === void 0 ? void 0 : _billingIdentity$stre.split(/\n/)[0],
127
- line2: ((_billingIdentity$stre2 = billingIdentity.street) === null || _billingIdentity$stre2 === void 0 ? void 0 : _billingIdentity$stre2.split(/\n/)[1]) ?? '',
128
- city: billingIdentity.locality ?? '',
129
- state: billingIdentity.administrativeArea ?? '',
130
- country: billingIdentity.country,
131
- postal_code: billingIdentity.zip ?? undefined
132
- }
133
- }
109
+ if (!stripe || !elements) return;
110
+ (_stripe = stripe) === null || _stripe === void 0 ? void 0 : _stripe.confirmPayment({
111
+ elements,
112
+ confirmParams: {
113
+ return_url: order.completeUrl,
114
+ payment_method_data: {
115
+ billing_details: {
116
+ email: billingIdentity.email,
117
+ name: billingIdentity.name,
118
+ address: {
119
+ line1: (_billingIdentity$stre = billingIdentity.street) === null || _billingIdentity$stre === void 0 ? void 0 : _billingIdentity$stre.split(/\n/)[0],
120
+ line2: ((_billingIdentity$stre2 = billingIdentity.street) === null || _billingIdentity$stre2 === void 0 ? void 0 : _billingIdentity$stre2.split(/\n/)[1]) ?? '',
121
+ city: billingIdentity.locality ?? '',
122
+ state: billingIdentity.administrativeArea ?? '',
123
+ country: billingIdentity.country,
124
+ postal_code: billingIdentity.zip ?? undefined
134
125
  }
135
126
  }
136
- }).then(result => {
137
- if ('error' in result) {
138
- setCompleting(false);
139
- setError(result.error.message ?? 'Payment failed. Please try another payment method.');
140
- scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
141
- }
142
- }).catch(error => {
143
- console.log(error);
144
- setCompleting(false);
145
- });
127
+ }
128
+ }
129
+ }).then(result => {
130
+ if ('error' in result) {
131
+ setCompleting(false);
132
+ setError(result.error.message ?? 'Payment failed. Please try another payment method.');
133
+ scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
146
134
  }
135
+ }).catch(error => {
136
+ console.log(error);
137
+ setCompleting(false);
147
138
  });
148
139
  };
149
140
  const handleClickSection = step => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fontdue-js",
3
- "version": "1.12.2",
3
+ "version": "1.12.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "build": "npm run relay && run-p build-js build-css build-ts-declarations",