Providing Store Credit through Shopify Flow App on Order Paid Trigger

Providing Store Credit through Shopify Flow App on Order Paid Trigger

MsMinis
Excursionist
13 0 11

I've found a perfect usecase for the Shopify Flow App but I don't think it's possible to use it in this way. Can someone prove me wrong?

The idea is to create a Loyalty Programme using the Shopify Flow App and the new Shopify Store Credit functionality. So when an Order is Paid I want to trigger a Flow that calculates the 1% value of the Order value and then add that amount to the Customers Store Credit value.

Sounds like a reasonable usecase and great way to utilize the Shopify Flow App. Is this currently possible?

FYI, I'm not interested in Apps that provide this functionality, I want to know if it's possible using Shopify Flow App and if so, how.

Replies 12 (12)

RPiii
Shopify Staff
162 27 49

Hi MsMinis, this should be possible by using the Order paid trigger, then a Run code action that calculates the credit based on the order value, then a Send Admin API request that updates the storeCreditAccountCredit. However, that mutation may not be available until the 2024/07 API is released so you may have to wait on that or implement as a refund or other endpoint available in the 2024/01 API.

MsMinis
Excursionist
13 0 11

That's great to hear. I've set up the Flow as you've explained currently and it seems to work great beside the endpoint that is not yet available. I assumed because of the name it would have already been available but it's not. Is there an ETA for that version to be released?

Kalen_Jordan
Shopify Partner
803 39 147

You could also just use send http request action meanwhile.

pije
New Member
4 0 0

Hi, 
Did you find a solution to this? Does it work with Flow?

JeffN
Shopify Partner
7 0 2

I wanted to chime in on this thread with an update. The info posted was super helpful but at the time, wasn't 100% doable in Shopify Flow since the Admin API version running in flow was not the latest and did not include storeCreditAccountCredit. I can confirm that the latest version does now include this as well as other mutations that weren't available before. So it is now possible to this entirely within Flow using the included Admin API Request option. I just completed a fairly robust rewards flow that we had previously been doing with Growave. Doing it in Flow works way better, is more flexible, and in my experience, way more stable than using Growave which is pretty regularly breaking down and requiring support to step in.

 

So glad Shopify finally updated this. It will really open up a lot of possibilities.

FurtherRecords
Shopify Partner
40 1 19

Good to hear, I have mine working in Pipedream already so not mega keen to rebuild it but if it ever breaks I might give the Flow version a shot. If you want to share I'd love to see it.

JeffN
Shopify Partner
7 0 2

I'm using a Run Code action to calculate the credit to be applied. My application also applies a different percentage of the order to be credited based on what tier the customer is (3% - default, 4.5%, or 6% based on certain customer tags if present):

Input:

query {
  order {
    customer {
      tags
    }
    subtotalPriceSet {
      shopMoney {
        amount
      }
    }
  }
}

Output:

"Output object"
type Output {
  "Calculated Store Credit"
  storeCredit: Float!
}

Code:

/**
 * Calculate the store credit to be applied on purcahse
*/
export default function main({order}) {
  const subtotal = order.subtotalPriceSet.shopMoney.amount;
  var reward = 0.03;
  if(order.customer.tags.includes('elite-member')){
    reward = 0.045;
  } else if(order.customer.tags.includes('vip-member')){
    reward = 0.06;
  }
  return { storeCredit: (subtotal * reward).toFixed(2)};
}

 

Then I use the Send API request to send the storeCreditAccountCredit mutation to the GraphQL Admin API:

{
  "id": "{{order.customer.id}}",
  "creditInput": {
    "creditAmount": {
      "amount": "{{runCode.storeCredit}}",
      "currencyCode": "{{order.currentTotalPriceSet.presentmentMoney.currencyCode}}"
    },
    "expiresAt": "{{order.createdAt | date: "%s" | plus: 31536000 | date: "%Y-%m-%dT%H:%M:%S%z"}}"
  }
}

 

The real thing that took a some trial and error was, from that I could see, the expiresAt field appears to be required. I tried excluding it and setting that to false since I wanted my credits to not have an expiry date but none of those options seemed to work. So instead, I'm using a date that is 365 days after the order creation which should work. If anyone can suggest why I wasn't able to create a credit without an expiry date, I'd welcome the input.

 

I'm still testing things to make sure all my conditions work as expected but so far, things appear to be working well.

RayD
Visitor
3 0 0

I just tried this in my shop, and it's great! 

 

We do want to set an expiration date, but I'm not sure how to set up a flow to let people know that they have credit expiring. Do you know how I could go about setting up that flow?

FurtherRecords
Shopify Partner
40 1 19

There's an email template for expiring store credit.

RayD
Visitor
3 0 0

I searched but I didn't see one. Are you referring to the expiring gift card template? 

 

FurtherRecords
Shopify Partner
40 1 19

Apologies, its a segment template not an email template:

FROM customers
SHOW customer_name, note, subscription_status, location, orders, amount_spent
WHERE store_credit_accounts MATCHES (
next_expiry_date BETWEEN today AND +7d
)
ORDER BY updated_at

RayD
Visitor
3 0 0

I found that when I went digging around after my last reply, but when I tried to create the segment by applying some credit to a test account to expire in 6 days the information didn't populate. I'm not sure where I'm going wrong.