imsujan276 / shopify_flutter

A flutter package that works as a bridge between your Shopify Store and Flutter Application
https://pub.dev/packages/shopify_flutter
MIT License
26 stars 27 forks source link

Shipping line can't be blank #17

Closed afetter closed 1 year ago

afetter commented 1 year ago

I only got this error at the final stage of the test, which means I made the payment and I try to complete the checkout.

I didn't find a way to define the shipping rate.

onPaymentResult(Map<String, dynamic> result) async {
    debugPrint('Payment Result $result');

    final shopifyCheckout = ShopifyCheckout.instance;

    var items = List<LineItem>.empty(growable: true);
    items.add(LineItem(
        quantity: 1,
        variantId: products[0].productVariants[0].id,
        title: products[0].title,
        id: products[0].id));

    var address = Address(
        address1: '11 Hinkler Avenue',
        city: 'Sydney',
        country: 'Australia',
        countryCode: 'AU',
        firstName: 'Anderson',
        lastName: 'Fetter',
        phone: '046444444',
        zip: '2229');

    final checkout = await shopifyCheckout.createCheckout(
      lineItems: items,
      shippingAddress: address,
      email: 'anderson.fetter@gmail.com',
    );

    await shopifyCheckout.shippingAddressUpdate(checkout.id, address);

    String token = result['token'][0] as String;

    final idempotencyKey = UniqueKey().toString();

    await shopifyCheckout.checkoutCompleteWithTokenizedPaymentV3(
        checkout.id,
        checkout: checkout,
        token: token,
        paymentTokenType: PaymentTokenType.APPLE_PAY,
        idempotencyKey: idempotencyKey,
        amount: '1.00',
        currencyCode: 'AUD');
  }
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: checkoutUserErrors during checkoutCompleteWithTokenizedPaymentV3: [{__typename: CheckoutUserError, code: BLANK, field: null, message: Billing address can't be blank}, {__typename: CheckoutUserError, code: BLANK, field: null, message: Shipping rate can't be blank}, {__typename: CheckoutUserError, code: BLANK, field: null, message: Shipping line can't be blank}]
#0      ShopifyError.checkForError (package:shopify_flutter/mixins/src/shopfiy_error.dart:14:9)
#1      ShopifyCheckout.checkoutCompleteWithTokenizedPaymentV3 (package:shopify_flutter/shopify/src/shopify_checkout.dart:607:5)
<asynchronous suspension>
#2      TestTabState.onPaymentResult (package:fighter_comics/screens/test_tab.dart:95:5)
<asynchronous suspension>
imsujan276 commented 1 year ago

According to Shopify documentation, you won't be able to checkout the products that require shipping. So you either have to set a free shipping line, or mark these products/variants to not require shipping.

Shopify Reference

afetter commented 1 year ago

Hey mate, I think there is a missing field, on create checkout mutation checkoutCreate requiresShipping.

Also, I think AvailableShippingRates or getCheckoutInfoWithAvailableShippingRatesQuery is not available anywhere in this API.

Am I correct?

imsujan276 commented 1 year ago

requiresShipping field is not present in the checkoutCreate mutation itself.

And yes, AvailableShippingRates or getCheckoutInfoWithAvailableShippingRatesQuery is not available anywhere in this API.

afetter commented 1 year ago

I found [here] (https://github.com/imsujan276/shopify_flutter/blob/abb95a35cdd8e85569beb98f4b8af33c1740b4cd/lib/graphql_operations/storefront/mutations/create_checkout.dart#L25) and here

imsujan276 commented 1 year ago

That is an attribute your get in checkout response. But as per my knowledge, there's no method to update it for now

afetter commented 1 year ago

Thank you so much mate, it was an error in my code.

the process requires:


 var checkout = await shopifyCheckout.createCheckout(
      lineItems: items,
      shippingAddress: address,
      email: 'anderson',
    );
//missed part to get available Shipping Rates
checkout = await shopifyCheckout.getCheckoutInfoQuery(checkout.id);
    var shippingRates = checkout.availableShippingRates?.shippingRates;

//missed part, set shipping rate
    await shopifyCheckout.checkoutShippingLineUpdate(
        checkout.id, shippingRates?[0].handle ?? '');
imsujan276 commented 1 year ago

Glad to hear you found the fix to the issue