gnikyt / laravel-shopify

A full-featured Laravel package for aiding in Shopify App development
MIT License
1.24k stars 374 forks source link

Where to define usage charge? #1189

Closed talktohenryj closed 2 years ago

talktohenryj commented 2 years ago

I am looking to create usage charges based on order amounts.

I have read the Usage Charge information in the wiki but I am still a bit confused.

How do I set a variable for the usage charge amount?

Below is the code I use to define the variable in one of my countrollers but where would I put it so Shopify charges the merchants this on every order?

            $total_usage_charge = 0;

            foreach($gift_cards_in_order as $gift_card_product_id) {
                $usage_charge = 0;
                foreach($order->line_items as $line_item) {
                    if($line_item->product_id == $gift_card_product_id){
                        $gift_card_price = $line_item->price;
                        $usage_charge = ($gift_card_price * .01);
                    }

                }
                $total_usage_charge += $usage_charge;
Kyon147 commented 2 years ago

Hi @talktohenryj

This is not a app package issue, so I'm going to close this but please move this question over to the discussion tab.

If you wanted that code to run on every order, you'd need to hook into the order webhook, or create your own job that gets the orders every X mins/hours/days etc. There's a lot of ways to achieve it.