Skip to content

Commit 6c2bffb

Browse files
Merge branch 'main' into kieran-osgood/refactor/cart-manager-error-messaging
2 parents f0140d8 + 98f9bb4 commit 6c2bffb

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

Samples/MobileBuyIntegration/MobileBuyIntegration/ApplePay/ApplePayHandler.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,8 @@ extension ApplePayHandler: PKPaymentAuthorizationControllerDelegate {
151151
partial: true
152152
)
153153

154-
guard let firstDeliveryGroup = CartManager.shared.cart?.deliveryGroups.nodes.first
155-
else {
156-
throw CartManager.Errors.invariant(message: "deliveryGroups empty")
157-
}
158-
159154
let shippingMethods = PassKitFactory.shared.createShippingMethods(
160-
firstDeliveryGroup: firstDeliveryGroup
155+
firstDeliveryGroup: CartManager.shared.cart?.deliveryGroups.nodes.first
161156
)
162157

163158
_ = try await CartManager.shared.performCartPrepareForCompletion()

Samples/MobileBuyIntegration/MobileBuyIntegration/ApplePay/PassKitFactory.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ class PassKitFactory {
108108
}
109109

110110
public func createShippingMethods(
111-
firstDeliveryGroup: Storefront.CartDeliveryGroup
111+
/**
112+
* Default to first delivery group when user changes their delivery contact
113+
* `nil` for digital products
114+
*/
115+
firstDeliveryGroup: Storefront.CartDeliveryGroup?
112116
) -> [PKShippingMethod] {
117+
guard let firstDeliveryGroup else { return [] }
113118
return firstDeliveryGroup.deliveryOptions.compactMap {
114119
guard let title = $0.title, let description = $0.description else {
115120
print("Invalid deliveryOption to map shipping method")

Samples/MobileBuyIntegration/MobileBuyIntegration/CartManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class CartManager: ObservableObject {
178178

179179
let buyerIdentityInput = StorefrontInputFactory.shared.createCartBuyerIdentityInput(
180180
// During ApplePay `contact.emailAddress` is nil until `didAuthorizePayment`
181-
email: contact.emailAddress ?? "",
181+
email: contact.emailAddress,
182182
deliveryAddressPreferencesInput: deliveryAddressPreferencesInput
183183
)
184184

Samples/MobileBuyIntegration/MobileBuyIntegration/StorefrontClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class StorefrontInputFactory {
192192
}
193193

194194
public func createCartBuyerIdentityInput(
195-
email: String,
195+
email: String?,
196196
deliveryAddressPreferencesInput: Input<[Storefront.DeliveryAddressInput]>
197197
) -> Storefront.CartBuyerIdentityInput {
198198
if appConfiguration.useVaultedState {

0 commit comments

Comments
 (0)