Skip to content

Commit 8e816a6

Browse files
committed
fix(payment): PAYMENTS-8239 addresses feedback
1 parent 814564b commit 8e816a6

File tree

4 files changed

+24
-56
lines changed

4 files changed

+24
-56
lines changed

packages/apple-pay-integration/src/apple-pay-button-strategy.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -267,27 +267,19 @@ export default class ApplePayButtonStrategy implements CheckoutButtonStrategy {
267267
]
268268
: [];
269269

270-
unselectedOptions
271-
?.filter((option) => option.isRecommended)
272-
?.forEach((option) =>
273-
shippingOptions.push({
274-
label: option.description,
275-
amount: `${option.cost.toFixed(decimalPlaces)}`,
276-
detail: option.additionalDescription,
277-
identifier: option.id,
278-
}),
279-
);
280-
281-
unselectedOptions
282-
?.filter((option) => !option.isRecommended)
283-
?.forEach((option) =>
270+
if (unselectedOptions) {
271+
[
272+
...unselectedOptions.filter((option) => option.isRecommended),
273+
...unselectedOptions.filter((option) => !option.isRecommended),
274+
].forEach((option) =>
284275
shippingOptions.push({
285276
label: option.description,
286277
amount: `${option.cost.toFixed(decimalPlaces)}`,
287278
detail: option.additionalDescription,
288279
identifier: option.id,
289280
}),
290281
);
282+
}
291283

292284
if (!isShippingOptions(availableOptions)) {
293285
throw new Error('Shipping options not available.');

packages/apple-pay-integration/src/apple-pay-customer-strategy.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -297,27 +297,19 @@ export default class ApplePayCustomerStrategy implements CustomerStrategy {
297297
]
298298
: [];
299299

300-
unselectedOptions
301-
?.filter((option) => option.isRecommended)
302-
?.forEach((option) =>
303-
shippingOptions.push({
304-
label: option.description,
305-
amount: `${option.cost.toFixed(decimalPlaces)}`,
306-
detail: option.additionalDescription,
307-
identifier: option.id,
308-
}),
309-
);
310-
311-
unselectedOptions
312-
?.filter((option) => !option.isRecommended)
313-
?.forEach((option) =>
300+
if (unselectedOptions) {
301+
[
302+
...unselectedOptions.filter((option) => option.isRecommended),
303+
...unselectedOptions.filter((option) => !option.isRecommended),
304+
].forEach((option) =>
314305
shippingOptions.push({
315306
label: option.description,
316307
amount: `${option.cost.toFixed(decimalPlaces)}`,
317308
detail: option.additionalDescription,
318309
identifier: option.id,
319310
}),
320311
);
312+
}
321313

322314
if (!isShippingOptions(availableOptions)) {
323315
throw new Error('Shipping options not available.');

packages/core/src/checkout-buttons/strategies/apple-pay/apple-pay-button-strategy.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -282,27 +282,19 @@ export default class ApplePayButtonStrategy implements CheckoutButtonStrategy {
282282
]
283283
: [];
284284

285-
unselectedOptions
286-
?.filter((option) => option.isRecommended)
287-
?.forEach((option) =>
288-
shippingOptions.push({
289-
label: option.description,
290-
amount: `${option.cost.toFixed(decimalPlaces)}`,
291-
detail: option.additionalDescription,
292-
identifier: option.id,
293-
}),
294-
);
295-
296-
unselectedOptions
297-
?.filter((option) => !option.isRecommended)
298-
?.forEach((option) =>
285+
if (unselectedOptions) {
286+
[
287+
...unselectedOptions.filter((option) => option.isRecommended),
288+
...unselectedOptions.filter((option) => !option.isRecommended),
289+
].forEach((option) =>
299290
shippingOptions.push({
300291
label: option.description,
301292
amount: `${option.cost.toFixed(decimalPlaces)}`,
302293
detail: option.additionalDescription,
303294
identifier: option.id,
304295
}),
305296
);
297+
}
306298

307299
if (!isShippingOptions(availableOptions)) {
308300
throw new Error('Shipping options not available.');

packages/core/src/customer/strategies/apple-pay/apple-pay-customer-strategy.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -323,27 +323,19 @@ export default class ApplePayCustomerStrategy implements CustomerStrategy {
323323
]
324324
: [];
325325

326-
unselectedOptions
327-
?.filter((option) => option.isRecommended)
328-
?.forEach((option) =>
329-
shippingOptions.push({
330-
label: option.description,
331-
amount: `${option.cost.toFixed(decimalPlaces)}`,
332-
detail: option.additionalDescription,
333-
identifier: option.id,
334-
}),
335-
);
336-
337-
unselectedOptions
338-
?.filter((option) => !option.isRecommended)
339-
?.forEach((option) =>
326+
if (unselectedOptions) {
327+
[
328+
...unselectedOptions.filter((option) => option.isRecommended),
329+
...unselectedOptions.filter((option) => !option.isRecommended),
330+
].forEach((option) =>
340331
shippingOptions.push({
341332
label: option.description,
342333
amount: `${option.cost.toFixed(decimalPlaces)}`,
343334
detail: option.additionalDescription,
344335
identifier: option.id,
345336
}),
346337
);
338+
}
347339

348340
if (!isShippingOptions(availableOptions)) {
349341
throw new Error('Shipping options not available.');

0 commit comments

Comments
 (0)