@dintero/checkout-web-sdk 0.11.5 → 0.12.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/README.md CHANGED
@@ -91,6 +91,13 @@ _The checkout sdk will add a polyfill for promises if the browser does not suppo
91
91
  event.payment_product_type,
92
92
  );
93
93
  },
94
+ onAddressCallback: function (event, checkout, callback) {
95
+ console.log("address callback to handle express session address updates", event.session);
96
+ callback({
97
+ success: true,
98
+ error: undefined,
99
+ });
100
+ },
94
101
  onValidateSession: function (event, checkout, callback) {
95
102
  console.log("validating session", event.session);
96
103
  callback({
@@ -161,6 +168,13 @@ const checkout = await embed({
161
168
  event.payment_product_type,
162
169
  );
163
170
  },
171
+ onAddressCallback: function (event: AddressCallback, checkout, callback) {
172
+ console.log("address callback to handle express session address updates", event.session);
173
+ callback({
174
+ success: true,
175
+ error: undefined,
176
+ });
177
+ },
164
178
  onValidateSession: function (event: ValidateSession, checkout, callback) {
165
179
  console.log("validating session", event.session);
166
180
  callback({
@@ -187,6 +201,53 @@ Resetting selection (so no option is selected in the checkout):
187
201
  checkout.setActivePaymentProductType();
188
202
  ```
189
203
 
204
+ ### Handling Checkout Express address updates using the onAddressCallback
205
+
206
+ If the `onAddressCallback` is provided the checkout **will not perform the machine to machine address update callback** defined in the payment session
207
+ object at `express.shipping_address_callback_url`. Instead the SDK runtime has to handle the address update flow.
208
+
209
+ The `onAddressCallback` function is invoked when an end user submits their address details (the shipping and billing addresses) in an embedded Checkout Express session. The callback function is invoked with an updated session that is not yet persisted in the Dintero backend. The checkout will be locked and payment will be paused until the provided callback function is called, or `checkout.submitAddressCallbackResult` is called with the result.
210
+
211
+ When `onAddressCallback` is invoked you will have to perform a [server-to-server session update](#perform-a-server-to-server-session-update) with shipping options or other details that have changed. Once the
212
+ session has been updated you need to call the provided callback function with a result.
213
+
214
+ When session has been updated successfully, return a successful result:
215
+
216
+ ```js
217
+ {
218
+ success: true;
219
+ }
220
+ ```
221
+
222
+ If the session update failed, return the result with an error message:
223
+
224
+ ```js
225
+ {
226
+ success: false,
227
+ error: "<reason for session update failure>"
228
+ }
229
+ ```
230
+
231
+ Example implementation:
232
+
233
+ ```
234
+ onAddressCallback: function(event, checkout, callback) {
235
+ // Perform a server-to-server session update
236
+ getShippingOptionsForAddressAndUpdateSession(event.session).then(() => {
237
+ callback({
238
+ success: true,
239
+ });
240
+ }).catch((err) => {
241
+ callback({
242
+ success: false,
243
+ error: toErrorMessage(err),
244
+ });
245
+ });
246
+ },
247
+ ```
248
+
249
+ > **Note:** When implementing the `onAddressCallback`, there is no need to manually lock the session and refresh it. The checkout will automatically lock the payment and refresh the session when the `callback` function is used to return a result.
250
+
190
251
  ### Updating an Checkout Express-session
191
252
 
192
253
  To update an existing Checkout Express-session, follow these steps:
@@ -10,7 +10,8 @@ export declare enum CheckoutEvents {
10
10
  SessionLocked = "SessionLocked",
11
11
  SessionLockFailed = "SessionLockFailed",
12
12
  ActivePaymentProductType = "ActivePaymentProductType",
13
- ValidateSession = "ValidateSession"
13
+ ValidateSession = "ValidateSession",
14
+ AddressCallback = "AddressCallback"
14
15
  }
15
16
  export declare enum InternalCheckoutEvents {
16
17
  HeightChanged = "HeightChanged",
@@ -103,7 +104,17 @@ export interface SessionValidationCallback {
103
104
  success: boolean;
104
105
  clientValidationError?: string;
105
106
  }
107
+ export type AddressCallback = {
108
+ type: CheckoutEvents.AddressCallback;
109
+ session: Session;
110
+ callback: (result: AddressCallbackResult) => void;
111
+ };
112
+ export interface AddressCallbackResult {
113
+ success: boolean;
114
+ error?: string;
115
+ }
106
116
  export type WrappedValidateSession = Pick<ValidateSession, "type" | "session">;
117
+ export type WrappedAddressCallback = Pick<AddressCallback, "type" | "session">;
107
118
  export type WrappedSessionLocked = Pick<SessionLocked, "type" | "pay_lock_id">;
108
119
  export type SessionPayment = SessionPaymentAuthorized | SessionPaymentOnHold;
109
120
  export type SessionPaymentError = {
@@ -111,4 +122,4 @@ export type SessionPaymentError = {
111
122
  error: string;
112
123
  href: string;
113
124
  };
114
- export type SessionEvent = SessionNotFound | SessionLoaded | SessionUpdated | SessionCancel | SessionPaymentOnHold | SessionPaymentAuthorized | SessionPaymentError | WrappedSessionLocked | SessionLockFailed | ActivePaymentProductType | WrappedValidateSession;
125
+ export type SessionEvent = SessionNotFound | SessionLoaded | SessionUpdated | SessionCancel | SessionPaymentOnHold | SessionPaymentAuthorized | SessionPaymentError | WrappedSessionLocked | SessionLockFailed | ActivePaymentProductType | WrappedValidateSession | WrappedAddressCallback;
@@ -1,5 +1,5 @@
1
1
  import "native-promise-only";
2
- import { type ActivePaymentProductType, CheckoutEvents, InternalCheckoutEvents, type SessionCancel, type SessionEvent, type SessionLoaded, type SessionLocked, type SessionLockFailed, type SessionNotFound, type SessionPaymentAuthorized, type SessionPaymentError, type SessionPaymentOnHold, type SessionUpdated, type SessionValidationCallback, type ValidateSession } from "./checkout.js";
2
+ import { type ActivePaymentProductType, type AddressCallback, type AddressCallbackResult, CheckoutEvents, InternalCheckoutEvents, type SessionCancel, type SessionEvent, type SessionLoaded, type SessionLocked, type SessionLockFailed, type SessionNotFound, type SessionPaymentAuthorized, type SessionPaymentError, type SessionPaymentOnHold, type SessionUpdated, type SessionValidationCallback, type ValidateSession } from "./checkout.js";
3
3
  import type { Session } from "./session.js";
4
4
  import { type SubscriptionHandler } from "./subscribe.js";
5
5
  export interface DinteroCheckoutInstance {
@@ -13,6 +13,7 @@ export interface DinteroCheckoutInstance {
13
13
  refreshSession: () => Promise<SessionEvent>;
14
14
  setActivePaymentProductType: (paymentProductType: string) => void;
15
15
  submitValidationResult: (result: SessionValidationCallback) => void;
16
+ submitAddressCallbackResult: (result: AddressCallbackResult) => void;
16
17
  options: InternalDinteroEmbedCheckoutOptions;
17
18
  handlers: ({
18
19
  handler: SubscriptionHandler;
@@ -46,6 +47,7 @@ export interface DinteroEmbedCheckoutOptions extends DinteroCheckoutOptions {
46
47
  onSessionLockFailed?: (event: SessionLockFailed, checkout: DinteroCheckoutInstance) => void;
47
48
  onActivePaymentType?: (event: ActivePaymentProductType, checkout: DinteroCheckoutInstance) => void;
48
49
  onValidateSession?: (event: ValidateSession, checkout: DinteroCheckoutInstance, callback: (result: SessionValidationCallback) => void) => void;
50
+ onAddressCallback?: (event: AddressCallback, checkout: DinteroCheckoutInstance, callback: (result: AddressCallbackResult) => void) => void;
49
51
  }
50
52
  interface InternalDinteroEmbedCheckoutOptions extends DinteroEmbedCheckoutOptions {
51
53
  innerContainer: HTMLDivElement;
@@ -1,5 +1,5 @@
1
1
  import type { DinteroCheckoutInstance } from "./index.js";
2
- import type { CheckoutEvents, InternalCheckoutEvents, SessionEvent, SessionValidationCallback } from "./checkout.js";
2
+ import type { AddressCallbackResult, CheckoutEvents, InternalCheckoutEvents, SessionEvent, SessionValidationCallback } from "./checkout.js";
3
3
  /**
4
4
  * Unsubscribe handler from event(s).
5
5
  */
@@ -26,6 +26,10 @@ export declare const postSessionLock: (iframe: HTMLIFrameElement, sid: string) =
26
26
  * Post the validation result to the checkout iframe
27
27
  */
28
28
  export declare const postValidationResult: (iframe: HTMLIFrameElement, sid: string, result: SessionValidationCallback) => void;
29
+ /**
30
+ * Post the address call back result to the checkout iframe
31
+ */
32
+ export declare const postAddressCallbackResult: (iframe: HTMLIFrameElement, sid: string, result: AddressCallbackResult) => void;
29
33
  /**
30
34
  * Post RefreshSession-event to the checkout iframe.
31
35
  */
@@ -6,7 +6,7 @@ require('native-promise-only');
6
6
 
7
7
  var pkg = {
8
8
  name: "@dintero/checkout-web-sdk",
9
- version: "0.11.5",
9
+ version: "0.12.0",
10
10
  description: "Dintero Checkout SDK for web frontends",
11
11
  main: "dist/dintero-checkout-web-sdk.cjs.js",
12
12
  module: "dist/dintero-checkout-web-sdk.esm.js",
@@ -68,6 +68,7 @@ let CheckoutEvents = /*#__PURE__*/function (CheckoutEvents) {
68
68
  CheckoutEvents["SessionLockFailed"] = "SessionLockFailed";
69
69
  CheckoutEvents["ActivePaymentProductType"] = "ActivePaymentProductType";
70
70
  CheckoutEvents["ValidateSession"] = "ValidateSession";
71
+ CheckoutEvents["AddressCallback"] = "AddressCallback";
71
72
  return CheckoutEvents;
72
73
  }({});
73
74
  let InternalCheckoutEvents = /*#__PURE__*/function (InternalCheckoutEvents) {
@@ -153,6 +154,7 @@ const getSessionUrl = options => {
153
154
  language,
154
155
  ui,
155
156
  shouldCallValidateSession,
157
+ shouldCallAddressCallback,
156
158
  popOut,
157
159
  redirect
158
160
  } = options;
@@ -170,6 +172,9 @@ const getSessionUrl = options => {
170
172
  if (shouldCallValidateSession) {
171
173
  params.append("client_side_validation", "true");
172
174
  }
175
+ if (shouldCallAddressCallback) {
176
+ params.append("client_side_address_callback", "true");
177
+ }
173
178
  if (popOut) {
174
179
  params.append("role", "pop_out_launcher");
175
180
  }
@@ -860,6 +865,19 @@ const postValidationResult = (iframe, sid, result) => {
860
865
  }
861
866
  };
862
867
 
868
+ /**
869
+ * Post the address call back result to the checkout iframe
870
+ */
871
+ const postAddressCallbackResult = (iframe, sid, result) => {
872
+ if (iframe.contentWindow) {
873
+ iframe.contentWindow.postMessage({
874
+ type: "AddressCallbackResult",
875
+ sid,
876
+ ...result
877
+ }, "*");
878
+ }
879
+ };
880
+
863
881
  /**
864
882
  * Post RefreshSession-event to the checkout iframe.
865
883
  */
@@ -1118,6 +1136,8 @@ const showPopOut = async (event, checkout) => {
1118
1136
  sid: checkout.options.sid,
1119
1137
  endpoint: checkout.options.endpoint,
1120
1138
  shouldCallValidateSession: Boolean(checkout.options.onValidateSession),
1139
+ shouldCallAddressCallback: false,
1140
+ // handled by embedded checkout not the pop out window
1121
1141
  language: event.language,
1122
1142
  onOpen: popOutWindow => createPopOutMessageHandler(popOutWindow, checkout),
1123
1143
  onClose: () => {
@@ -1159,6 +1179,7 @@ const createPopOutValidationCallback = (event, checkout) => {
1159
1179
  sid: checkout.options.sid,
1160
1180
  endpoint: checkout.options.endpoint,
1161
1181
  shouldCallValidateSession: false,
1182
+ shouldCallAddressCallback: false,
1162
1183
  language: event.language
1163
1184
  });
1164
1185
  } else {
@@ -1291,6 +1312,7 @@ const embed = async options => {
1291
1312
  onSessionLockFailed,
1292
1313
  onActivePaymentType,
1293
1314
  onValidateSession,
1315
+ onAddressCallback,
1294
1316
  popOut
1295
1317
  } = internalOptions;
1296
1318
  let checkout;
@@ -1308,6 +1330,7 @@ const embed = async options => {
1308
1330
  language,
1309
1331
  ui: options.ui || "inline",
1310
1332
  shouldCallValidateSession: onValidateSession !== undefined,
1333
+ shouldCallAddressCallback: onAddressCallback !== undefined,
1311
1334
  popOut,
1312
1335
  // biome-ignore lint/suspicious/noPrototypeBuiltins: test
1313
1336
  ...(options.hasOwnProperty("hideTestMessage") && {
@@ -1400,6 +1423,10 @@ const embed = async options => {
1400
1423
  postValidationResult(iframe, sid, result);
1401
1424
  // For pop out we do validation when opening the pop out
1402
1425
  };
1426
+ const submitAddressCallbackResult = result => {
1427
+ postAddressCallbackResult(iframe, sid, result);
1428
+ // For pop out we do validation when opening the pop out
1429
+ };
1403
1430
 
1404
1431
  /**
1405
1432
  * Internal result event message handler wrapper, to replace the content of the iframe with a success/or
@@ -1440,6 +1467,22 @@ const embed = async options => {
1440
1467
  }
1441
1468
  }
1442
1469
  };
1470
+ const wrappedOnAddressCallback = (event, checkout) => {
1471
+ if (onAddressCallback) {
1472
+ try {
1473
+ onAddressCallback({
1474
+ ...event,
1475
+ callback: submitAddressCallbackResult
1476
+ }, checkout, submitAddressCallbackResult);
1477
+ } catch (e) {
1478
+ console.error(e);
1479
+ submitAddressCallbackResult({
1480
+ success: false,
1481
+ error: "Address callback runtime error"
1482
+ });
1483
+ }
1484
+ }
1485
+ };
1443
1486
  const wrappedOnSessionLocked = (event, checkout) => {
1444
1487
  if (onSessionLocked) {
1445
1488
  onSessionLocked(event, checkout, refreshSession);
@@ -1496,6 +1539,9 @@ const embed = async options => {
1496
1539
  }, {
1497
1540
  handler: wrappedOnValidateSession,
1498
1541
  eventTypes: [CheckoutEvents.ValidateSession]
1542
+ }, {
1543
+ handler: wrappedOnAddressCallback,
1544
+ eventTypes: [CheckoutEvents.AddressCallback]
1499
1545
  }, {
1500
1546
  handler: handleShowButton,
1501
1547
  eventTypes: [InternalCheckoutEvents.ShowPopOutButton]
@@ -1512,6 +1558,7 @@ const embed = async options => {
1512
1558
  refreshSession,
1513
1559
  setActivePaymentProductType,
1514
1560
  submitValidationResult,
1561
+ submitAddressCallbackResult,
1515
1562
  options: internalOptions,
1516
1563
  handlers,
1517
1564
  session: undefined,
@@ -1554,6 +1601,7 @@ const redirect = options => {
1554
1601
  endpoint,
1555
1602
  language,
1556
1603
  shouldCallValidateSession: false,
1604
+ shouldCallAddressCallback: false,
1557
1605
  redirect: true
1558
1606
  }));
1559
1607
  };
@@ -6,7 +6,7 @@ require('native-promise-only');
6
6
 
7
7
  var pkg = {
8
8
  name: "@dintero/checkout-web-sdk",
9
- version: "0.11.5",
9
+ version: "0.12.0",
10
10
  description: "Dintero Checkout SDK for web frontends",
11
11
  main: "dist/dintero-checkout-web-sdk.cjs.js",
12
12
  module: "dist/dintero-checkout-web-sdk.esm.js",
@@ -68,6 +68,7 @@ let CheckoutEvents = /*#__PURE__*/function (CheckoutEvents) {
68
68
  CheckoutEvents["SessionLockFailed"] = "SessionLockFailed";
69
69
  CheckoutEvents["ActivePaymentProductType"] = "ActivePaymentProductType";
70
70
  CheckoutEvents["ValidateSession"] = "ValidateSession";
71
+ CheckoutEvents["AddressCallback"] = "AddressCallback";
71
72
  return CheckoutEvents;
72
73
  }({});
73
74
  let InternalCheckoutEvents = /*#__PURE__*/function (InternalCheckoutEvents) {
@@ -153,6 +154,7 @@ const getSessionUrl = options => {
153
154
  language,
154
155
  ui,
155
156
  shouldCallValidateSession,
157
+ shouldCallAddressCallback,
156
158
  popOut,
157
159
  redirect
158
160
  } = options;
@@ -170,6 +172,9 @@ const getSessionUrl = options => {
170
172
  if (shouldCallValidateSession) {
171
173
  params.append("client_side_validation", "true");
172
174
  }
175
+ if (shouldCallAddressCallback) {
176
+ params.append("client_side_address_callback", "true");
177
+ }
173
178
  if (popOut) {
174
179
  params.append("role", "pop_out_launcher");
175
180
  }
@@ -860,6 +865,19 @@ const postValidationResult = (iframe, sid, result) => {
860
865
  }
861
866
  };
862
867
 
868
+ /**
869
+ * Post the address call back result to the checkout iframe
870
+ */
871
+ const postAddressCallbackResult = (iframe, sid, result) => {
872
+ if (iframe.contentWindow) {
873
+ iframe.contentWindow.postMessage({
874
+ type: "AddressCallbackResult",
875
+ sid,
876
+ ...result
877
+ }, "*");
878
+ }
879
+ };
880
+
863
881
  /**
864
882
  * Post RefreshSession-event to the checkout iframe.
865
883
  */
@@ -1118,6 +1136,8 @@ const showPopOut = async (event, checkout) => {
1118
1136
  sid: checkout.options.sid,
1119
1137
  endpoint: checkout.options.endpoint,
1120
1138
  shouldCallValidateSession: Boolean(checkout.options.onValidateSession),
1139
+ shouldCallAddressCallback: false,
1140
+ // handled by embedded checkout not the pop out window
1121
1141
  language: event.language,
1122
1142
  onOpen: popOutWindow => createPopOutMessageHandler(popOutWindow, checkout),
1123
1143
  onClose: () => {
@@ -1159,6 +1179,7 @@ const createPopOutValidationCallback = (event, checkout) => {
1159
1179
  sid: checkout.options.sid,
1160
1180
  endpoint: checkout.options.endpoint,
1161
1181
  shouldCallValidateSession: false,
1182
+ shouldCallAddressCallback: false,
1162
1183
  language: event.language
1163
1184
  });
1164
1185
  } else {
@@ -1291,6 +1312,7 @@ const embed = async options => {
1291
1312
  onSessionLockFailed,
1292
1313
  onActivePaymentType,
1293
1314
  onValidateSession,
1315
+ onAddressCallback,
1294
1316
  popOut
1295
1317
  } = internalOptions;
1296
1318
  let checkout;
@@ -1308,6 +1330,7 @@ const embed = async options => {
1308
1330
  language,
1309
1331
  ui: options.ui || "inline",
1310
1332
  shouldCallValidateSession: onValidateSession !== undefined,
1333
+ shouldCallAddressCallback: onAddressCallback !== undefined,
1311
1334
  popOut,
1312
1335
  // biome-ignore lint/suspicious/noPrototypeBuiltins: test
1313
1336
  ...(options.hasOwnProperty("hideTestMessage") && {
@@ -1400,6 +1423,10 @@ const embed = async options => {
1400
1423
  postValidationResult(iframe, sid, result);
1401
1424
  // For pop out we do validation when opening the pop out
1402
1425
  };
1426
+ const submitAddressCallbackResult = result => {
1427
+ postAddressCallbackResult(iframe, sid, result);
1428
+ // For pop out we do validation when opening the pop out
1429
+ };
1403
1430
 
1404
1431
  /**
1405
1432
  * Internal result event message handler wrapper, to replace the content of the iframe with a success/or
@@ -1440,6 +1467,22 @@ const embed = async options => {
1440
1467
  }
1441
1468
  }
1442
1469
  };
1470
+ const wrappedOnAddressCallback = (event, checkout) => {
1471
+ if (onAddressCallback) {
1472
+ try {
1473
+ onAddressCallback({
1474
+ ...event,
1475
+ callback: submitAddressCallbackResult
1476
+ }, checkout, submitAddressCallbackResult);
1477
+ } catch (e) {
1478
+ console.error(e);
1479
+ submitAddressCallbackResult({
1480
+ success: false,
1481
+ error: "Address callback runtime error"
1482
+ });
1483
+ }
1484
+ }
1485
+ };
1443
1486
  const wrappedOnSessionLocked = (event, checkout) => {
1444
1487
  if (onSessionLocked) {
1445
1488
  onSessionLocked(event, checkout, refreshSession);
@@ -1496,6 +1539,9 @@ const embed = async options => {
1496
1539
  }, {
1497
1540
  handler: wrappedOnValidateSession,
1498
1541
  eventTypes: [CheckoutEvents.ValidateSession]
1542
+ }, {
1543
+ handler: wrappedOnAddressCallback,
1544
+ eventTypes: [CheckoutEvents.AddressCallback]
1499
1545
  }, {
1500
1546
  handler: handleShowButton,
1501
1547
  eventTypes: [InternalCheckoutEvents.ShowPopOutButton]
@@ -1512,6 +1558,7 @@ const embed = async options => {
1512
1558
  refreshSession,
1513
1559
  setActivePaymentProductType,
1514
1560
  submitValidationResult,
1561
+ submitAddressCallbackResult,
1515
1562
  options: internalOptions,
1516
1563
  handlers,
1517
1564
  session: undefined,
@@ -1554,6 +1601,7 @@ const redirect = options => {
1554
1601
  endpoint,
1555
1602
  language,
1556
1603
  shouldCallValidateSession: false,
1604
+ shouldCallAddressCallback: false,
1557
1605
  redirect: true
1558
1606
  }));
1559
1607
  };
@@ -2,7 +2,7 @@ import 'native-promise-only';
2
2
 
3
3
  var pkg = {
4
4
  name: "@dintero/checkout-web-sdk",
5
- version: "0.11.5",
5
+ version: "0.12.0",
6
6
  description: "Dintero Checkout SDK for web frontends",
7
7
  main: "dist/dintero-checkout-web-sdk.cjs.js",
8
8
  module: "dist/dintero-checkout-web-sdk.esm.js",
@@ -64,6 +64,7 @@ let CheckoutEvents = /*#__PURE__*/function (CheckoutEvents) {
64
64
  CheckoutEvents["SessionLockFailed"] = "SessionLockFailed";
65
65
  CheckoutEvents["ActivePaymentProductType"] = "ActivePaymentProductType";
66
66
  CheckoutEvents["ValidateSession"] = "ValidateSession";
67
+ CheckoutEvents["AddressCallback"] = "AddressCallback";
67
68
  return CheckoutEvents;
68
69
  }({});
69
70
  let InternalCheckoutEvents = /*#__PURE__*/function (InternalCheckoutEvents) {
@@ -149,6 +150,7 @@ const getSessionUrl = options => {
149
150
  language,
150
151
  ui,
151
152
  shouldCallValidateSession,
153
+ shouldCallAddressCallback,
152
154
  popOut,
153
155
  redirect
154
156
  } = options;
@@ -166,6 +168,9 @@ const getSessionUrl = options => {
166
168
  if (shouldCallValidateSession) {
167
169
  params.append("client_side_validation", "true");
168
170
  }
171
+ if (shouldCallAddressCallback) {
172
+ params.append("client_side_address_callback", "true");
173
+ }
169
174
  if (popOut) {
170
175
  params.append("role", "pop_out_launcher");
171
176
  }
@@ -856,6 +861,19 @@ const postValidationResult = (iframe, sid, result) => {
856
861
  }
857
862
  };
858
863
 
864
+ /**
865
+ * Post the address call back result to the checkout iframe
866
+ */
867
+ const postAddressCallbackResult = (iframe, sid, result) => {
868
+ if (iframe.contentWindow) {
869
+ iframe.contentWindow.postMessage({
870
+ type: "AddressCallbackResult",
871
+ sid,
872
+ ...result
873
+ }, "*");
874
+ }
875
+ };
876
+
859
877
  /**
860
878
  * Post RefreshSession-event to the checkout iframe.
861
879
  */
@@ -1114,6 +1132,8 @@ const showPopOut = async (event, checkout) => {
1114
1132
  sid: checkout.options.sid,
1115
1133
  endpoint: checkout.options.endpoint,
1116
1134
  shouldCallValidateSession: Boolean(checkout.options.onValidateSession),
1135
+ shouldCallAddressCallback: false,
1136
+ // handled by embedded checkout not the pop out window
1117
1137
  language: event.language,
1118
1138
  onOpen: popOutWindow => createPopOutMessageHandler(popOutWindow, checkout),
1119
1139
  onClose: () => {
@@ -1155,6 +1175,7 @@ const createPopOutValidationCallback = (event, checkout) => {
1155
1175
  sid: checkout.options.sid,
1156
1176
  endpoint: checkout.options.endpoint,
1157
1177
  shouldCallValidateSession: false,
1178
+ shouldCallAddressCallback: false,
1158
1179
  language: event.language
1159
1180
  });
1160
1181
  } else {
@@ -1287,6 +1308,7 @@ const embed = async options => {
1287
1308
  onSessionLockFailed,
1288
1309
  onActivePaymentType,
1289
1310
  onValidateSession,
1311
+ onAddressCallback,
1290
1312
  popOut
1291
1313
  } = internalOptions;
1292
1314
  let checkout;
@@ -1304,6 +1326,7 @@ const embed = async options => {
1304
1326
  language,
1305
1327
  ui: options.ui || "inline",
1306
1328
  shouldCallValidateSession: onValidateSession !== undefined,
1329
+ shouldCallAddressCallback: onAddressCallback !== undefined,
1307
1330
  popOut,
1308
1331
  // biome-ignore lint/suspicious/noPrototypeBuiltins: test
1309
1332
  ...(options.hasOwnProperty("hideTestMessage") && {
@@ -1396,6 +1419,10 @@ const embed = async options => {
1396
1419
  postValidationResult(iframe, sid, result);
1397
1420
  // For pop out we do validation when opening the pop out
1398
1421
  };
1422
+ const submitAddressCallbackResult = result => {
1423
+ postAddressCallbackResult(iframe, sid, result);
1424
+ // For pop out we do validation when opening the pop out
1425
+ };
1399
1426
 
1400
1427
  /**
1401
1428
  * Internal result event message handler wrapper, to replace the content of the iframe with a success/or
@@ -1436,6 +1463,22 @@ const embed = async options => {
1436
1463
  }
1437
1464
  }
1438
1465
  };
1466
+ const wrappedOnAddressCallback = (event, checkout) => {
1467
+ if (onAddressCallback) {
1468
+ try {
1469
+ onAddressCallback({
1470
+ ...event,
1471
+ callback: submitAddressCallbackResult
1472
+ }, checkout, submitAddressCallbackResult);
1473
+ } catch (e) {
1474
+ console.error(e);
1475
+ submitAddressCallbackResult({
1476
+ success: false,
1477
+ error: "Address callback runtime error"
1478
+ });
1479
+ }
1480
+ }
1481
+ };
1439
1482
  const wrappedOnSessionLocked = (event, checkout) => {
1440
1483
  if (onSessionLocked) {
1441
1484
  onSessionLocked(event, checkout, refreshSession);
@@ -1492,6 +1535,9 @@ const embed = async options => {
1492
1535
  }, {
1493
1536
  handler: wrappedOnValidateSession,
1494
1537
  eventTypes: [CheckoutEvents.ValidateSession]
1538
+ }, {
1539
+ handler: wrappedOnAddressCallback,
1540
+ eventTypes: [CheckoutEvents.AddressCallback]
1495
1541
  }, {
1496
1542
  handler: handleShowButton,
1497
1543
  eventTypes: [InternalCheckoutEvents.ShowPopOutButton]
@@ -1508,6 +1554,7 @@ const embed = async options => {
1508
1554
  refreshSession,
1509
1555
  setActivePaymentProductType,
1510
1556
  submitValidationResult,
1557
+ submitAddressCallbackResult,
1511
1558
  options: internalOptions,
1512
1559
  handlers,
1513
1560
  session: undefined,
@@ -1550,6 +1597,7 @@ const redirect = options => {
1550
1597
  endpoint,
1551
1598
  language,
1552
1599
  shouldCallValidateSession: false,
1600
+ shouldCallAddressCallback: false,
1553
1601
  redirect: true
1554
1602
  }));
1555
1603
  };