Shopify / mobile-buy-sdk-ios

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using Apple Pay or their credit card.
MIT License
452 stars 199 forks source link

Apple Pay: Partial shipping address update failing #950

Closed moesalih closed 5 years ago

moesalih commented 5 years ago

Part of the Apple Pay flow is to get a partial shipping address from Apple Pay and then update the checkout with that partial address to get available shipping rates.

I'm updating the checkout just like in the sample app, but I'm getting a couple of user errors: Last name can't be blank. Address1 can't be blank, but there's no address1 and lastname at this point in the flow.

What am I missing?

Here's the address update function, which is similar to the sample app:

    func updateCheckout(_ id: String, updatingPartialShippingAddress address: PayPostalAddress, handler: @escaping ((Storefront.Checkout?)->())) {
        let checkoutID   = GraphQL.ID(rawValue: id)
        let addressInput = Storefront.MailingAddressInput.create(
            city:      address.city.orNull,
            country:   address.country.orNull,
            province:  address.province.orNull,
            zip:       address.zip.orNull
        )
        let mutation = Storefront.buildMutation { $0
            .checkoutShippingAddressUpdateV2(shippingAddress: addressInput, checkoutId: checkoutID) { $0
                .checkout { $0.standardData() }
                .userErrors { $0.message() }
            }
        }
        Config.shopifyClient.mutateGraph(mutation) { result, error in
            let checkout = result?.checkoutShippingAddressUpdateV2?.checkout
            let error = error ?? result?.checkoutShippingAddressUpdateV2?.userErrors.readable
            print(#function, checkout as Any, error as Any)
            handler(checkout)
        }
    }
moesalih commented 5 years ago

Nevermind. I saw a response in an older issue: https://github.com/Shopify/mobile-buy-sdk-ios/issues/670#issuecomment-311730007

You have to allow partial addresses when creating the checkout:

let input = Storefront.CheckoutCreateInput.create(lineItems: .value(items), allowPartialAddresses: .value(true))