Shipping CODE Discount Function - Checkout Error

topshop
Shopify Partner
56 5 7

I'm working on creating a Shopify function for creating custom shipping discount codes (Not automatic discounts).

  • The function gets invoked at checkout correctly when the code is applied
  • I'm able to see the expected input and output for the function in Shopify Partner's "Run Detail" section for the function. There are no errors there

But I get the following error on the checkout screen as soon as the code is applied:

There was a problem with our checkout

Refresh this page or try again in a few minutes

 

I followed the standard tutorial to build the discount function but modified it for creating a shipping discount instead: https://shopify.dev/docs/apps/selling-strategies/discounts/experience

 

Here's the mutation I used to create the discount without any error:

mutation {
  discountCodeAppCreate(codeAppDiscount: {
    code: "SHIPTEST",
    title: "Shipping Test",
    functionId: "01H4XPYSZTB3ANV48G0ZEH760M",
    startsAt: "2022-06-22T00:00:00"
  }) {
     codeAppDiscount {
      discountId
     }
     userErrors {
      field
      message
     }
  }
}

Here is the input for the function that gets invoked successfully at checkout:

{
  "cart": {
    "lines": [
      {
        "quantity": 3,
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid://shopify/ProductVariant/45565892690203"
        }
      }
    ]
  }
}

 

Here is the output for the function that gets invoked successfully at checkout

{
  "discountApplicationStrategy": "FIRST",
  "discounts": [
    {
      "value": {
        "percentage": {
          "value": 100.0
        }
      },
      "targets": [
        {
          "deliveryGroup": {
            "id": "gid://shopify/CartDeliveryGroup/0"
          }
        }
      ],
      "message": "100% off"
    }
  ]
}

 

Now because I see no errors in my dev console, partner's dashboard etc., I have no way to figure out where/what the issue is. Can someone please look into this?

Founder, Discount Bot: Sitewide Sales
- Instantly create discounts for your entire product catalog with a single discount
- Exclude any products / collections / already on sale items for which the discounts should NOT apply
- Built using Shopify Functions for native performance and feel
Replies 8 (8)

topshop
Shopify Partner
56 5 7

Also including the graphql error as seen in the browser:

 

[
{
"message": "Internal error. Looks like something went wrong on our end.\nRequest ID: dab38efe-0531-4b2b-8378-6a88b63db1da (include this in support requests).",
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"requestId": "dab38efe-0531-4b2b-8378-6a88b63db1da"
}
}
]

Founder, Discount Bot: Sitewide Sales
- Instantly create discounts for your entire product catalog with a single discount
- Exclude any products / collections / already on sale items for which the discounts should NOT apply
- Built using Shopify Functions for native performance and feel

topshop
Shopify Partner
56 5 7

I've also created a Github discussion here if it makes it easier: https://github.com/Shopify/function-examples/discussions/280

Founder, Discount Bot: Sitewide Sales
- Instantly create discounts for your entire product catalog with a single discount
- Exclude any products / collections / already on sale items for which the discounts should NOT apply
- Built using Shopify Functions for native performance and feel

Liam
Shopify Staff
2731 302 783

Hi Topshop,

 

It's possible this issue is being caused by an internal server error occurring on Shopify's end when applying the discount code at checkout, which I'm looking into.

 

In the meantime, there's a couple things you could do to troubleshoot this:

  1. Confirm Functionality: Create a different function that performs a simpler task, such as a simple discount on a product, and apply it to a discount code. If this works, it points towards a specific issue with applying this shipping discount via a Shopify function.

  2. Test the Checkout Flow: Perform tests on your checkout flow. Create different types of discounts, apply them, and proceed to checkout. See if the issue arises with any other discounts or only with the shipping discount.

  3. Validate the Function: Double-check the function and ensure that it's correctly written and follows all necessary guidelines. This includes the structure of the function and its syntax.

If you check these, I'll also look into things on our side so see what might be causing this. Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

topshop
Shopify Partner
56 5 7

@Liam , I checked the things you'd asked. The function works with the checkout flow without a server error in all other cases. It only seems to have the server error with the shipping function with a CODE (even shipping function with automatic discount works without error).

Founder, Discount Bot: Sitewide Sales
- Instantly create discounts for your entire product catalog with a single discount
- Exclude any products / collections / already on sale items for which the discounts should NOT apply
- Built using Shopify Functions for native performance and feel
Liam
Shopify Staff
2731 302 783

Hi Topshop - so I've checked this with our product teams and it appears that shipping discount functions aren't currently supported, (although we are working on supporting these). 

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

topshop
Shopify Partner
56 5 7

@Liam , it shows as being in Developer Preview. Should I wait to develop against it until it's out of preview? Just trying to understand the process. Also, any timelines for when it would be ready to be used would help us plan better.

Screen Shot 2023-07-12 at 12_37_30 PM.png

Founder, Discount Bot: Sitewide Sales
- Instantly create discounts for your entire product catalog with a single discount
- Exclude any products / collections / already on sale items for which the discounts should NOT apply
- Built using Shopify Functions for native performance and feel
Liam
Shopify Staff
2731 302 783

Hi again Topshop - no timelines to share right now, but keep an eye on the developer changelog here: https://shopify.dev/changelog

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

tobebuilds
Shopify Partner
300 14 80

Hey Liam, does the Shopify Functions team have an email list I can subscribe to for updates, or is the RSS feed the best way?

 

Thanks in advance.