I am creating a draft order on Shopify with discount, Its return error like 'must correspond to that calculated from the value'.
I am calculating discount as following:
$amount is the total amount (78.99) of order and $rate (30) is a value of discount percentage.
$discount = $amount * ( $rate / 100);
$discount = $discount * pow(10, 2);
$discount = floatval($discount);
$discount = $discount / pow(10, 2);
$new_discount_amt = round($discount, 2);
Here, my total is 78.99 and I want to apply a 30% discount on that. so the final discount amount is 23.7
$applied_discount = array(
"title" => "RCT Reorder Discount",
"description" => "Description",
"value" => "30",
"value_type" => "percentage",
"amount" => $new_discount_amt
);
Shopify return
{"errors":{"applied_discount.amount":["must correspond to that calculated from the value"]}}
What's wrong with this calculation? What is the right method to calculate discount in Shopify?