@fat-zebra/sdk 1.5.7 → 1.5.8-beta.2

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.
@@ -17,6 +17,7 @@ export declare class ApplePay {
17
17
  private username;
18
18
  private environment;
19
19
  private paymentIntent;
20
+ private react_sdk?;
20
21
  constructor(config: {
21
22
  environment: Environment;
22
23
  paymentIntent: PaymentIntent;
@@ -24,9 +24,10 @@ export class ApplePay {
24
24
  this.username = config.username;
25
25
  }
26
26
  load(config) {
27
- var _a, _b;
27
+ var _a, _b, _c;
28
28
  this.domain_name = (_b = (_a = config === null || config === void 0 ? void 0 : config.options) === null || _a === void 0 ? void 0 : _a.domain_name) !== null && _b !== void 0 ? _b : window.location.hostname;
29
29
  this.iframe = document.createElement('iframe');
30
+ this.react_sdk = (_c = config.options.react_sdk) !== null && _c !== void 0 ? _c : false;
30
31
  document.getElementById(config.containerId).appendChild(this.iframe);
31
32
  const applePayUrl = this.getPayNowUrl(config.options);
32
33
  this.iframe.setAttribute("src", applePayUrl);
@@ -70,6 +71,9 @@ export class ApplePay {
70
71
  if (options === null || options === void 0 ? void 0 : options.apple_button_locale) {
71
72
  query.append('apple_button_locale', options.apple_button_locale.toString());
72
73
  }
74
+ if (options === null || options === void 0 ? void 0 : options.react_sdk) {
75
+ query.append('react_sdk', 'true');
76
+ }
73
77
  query.append('domain_name', this.domain_name);
74
78
  return `${base}?${query.toString()}`;
75
79
  }
@@ -127,13 +131,40 @@ export class ApplePay {
127
131
  });
128
132
  this.applePaySession.onpaymentauthorized = (event) => __awaiter(this, void 0, void 0, function* () {
129
133
  try {
130
- const result = yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, token: event.payment.token, domain_name: this.domain_name }), `${this.fzPayNowDomain}${purchaseTokenPath}`);
131
- this.applePaySession.completePayment(window.ApplePaySession.STATUS_SUCCESS);
132
- const payload = {
133
- message: 'Payment successful.',
134
- data: result,
135
- };
136
- emit(FatZebra.PublicEvent.PAYMENT_SUCCESS, payload);
134
+ const result = yield payNow.authorizePayment(Object.assign(Object.assign({}, payNowPaymentAttributes), { merchant: this.username, token: event.payment.token, domain_name: this.domain_name }), `${this.fzPayNowDomain}${purchaseTokenPath}?react_sdk=${this.react_sdk}`);
135
+ if (result.ok) {
136
+ this.applePaySession.completePayment(window.ApplePaySession.STATUS_SUCCESS);
137
+ const payload = {
138
+ message: 'Payment successful.',
139
+ data: result,
140
+ };
141
+ emit(FatZebra.PublicEvent.PAYMENT_SUCCESS, payload);
142
+ const message = {
143
+ channel,
144
+ subject: 'Payment successful.',
145
+ data: {
146
+ payload
147
+ }
148
+ };
149
+ this.postMessageClient.send(message);
150
+ }
151
+ else {
152
+ this.applePaySession.completePayment(window.ApplePaySession.STATUS_FAILURE);
153
+ const payload = {
154
+ data: 'Payment failed.',
155
+ errors: result.purchase.errors
156
+ };
157
+ console.log('its successful apple pay', result);
158
+ emit(FatZebra.PublicEvent.PAYMENT_ERROR, payload);
159
+ const message = {
160
+ channel,
161
+ subject: 'Payment unsuccessful.',
162
+ data: {
163
+ payload
164
+ }
165
+ };
166
+ this.postMessageClient.send(message);
167
+ }
137
168
  }
138
169
  catch (e) {
139
170
  this.applePaySession.completePayment(window.ApplePaySession.STATUS_FAILURE);
@@ -36,7 +36,7 @@ export const authorizePayment = (payload, url) => __awaiter(void 0, void 0, void
36
36
  const request = new XMLHttpRequest();
37
37
  request.onload = () => {
38
38
  if (request.status >= 200 && request.status < 300) {
39
- return resolve(true);
39
+ return resolve(JSON.parse(request.responseText));
40
40
  }
41
41
  else {
42
42
  return reject(new Error());