Reputation: 33
The overall goal for me is to create discounts for one-time purchases, using the Stripe API. I noticed that discounts through the API is only for invoices, which i am not using for one-time payments.
What I am currently trying is to change the order amount. I read in the API that you cannot update the order amount, therefore I need to remove the existing order that is created through my code, and create a new one but with another amount than the original SKU item's price. This does not appear to work.
The request looks like this (through stripe dashboard log):
{
items:
0:
type: "sku"
parent: "sku_8E8ZS8KYaJbUkK"
quantity: "1"
amount: "6800"
1:
type: "sku"
parent: "sku_8E8I4F1FcseFQz"
quantity: "2"
amount: "6800"
customer: cus_8TV6gRP0hrxmEy
currency: "sek"
metadata:
delivery_date: "1463814000"
}
But the response seems to ignore my updated amount:
items: {
object: "order_item"
amount: 8500
currency: "sek"
description: "Specialpåse"
parent: "sku_8E8ZS8KYaJbUkK"
quantity: 1
type: "sku"
}
PHP code:
$newOrder = \Stripe\Order::create(array(
"items" => generateItems($items),
"customer" => $customer,
"currency" => "sek",
"metadata" => array("delivery_date" => $delivery_date)
));
function generateItems($items) {
$newArray = array();
$x = 0;
foreach ($items as $i) {
$newArray[$x] = array("type" => $i['type'], "parent" => $i['parent'], "quantity" => $i['quantity'], "amount" => $i['product_price']*100);
$x++;
}
return $newArray;
}
Where $items looks something like this:
Array
(
[0] => Array
(
[type] => sku
[parent] => sku_8E8ZS8KYaJbUkK
[quantity] => 2
[name] => Specialpåse
[product_price] => 68
[subscription_price] => 60
[purchase_type] => single_purchase
)
[1] => Array
(
[type] => sku
[parent] => sku_8E8I4F1FcseFQz
[quantity] => 3
[name] => Familjepåse
[product_price] => 68
[subscription_price] => 60
[purchase_type] => single_purchase
)
)
Upvotes: 2
Views: 974
Reputation: 17505
It is possible to apply discounts to orders, by using the coupon
parameter in order creation requests.
In PHP, it would look like this:
$newOrder = \Stripe\Order::create(array(
"items" => generateItems($items),
"customer" => $customer,
"currency" => "sek",
"metadata" => array("delivery_date" => $delivery_date),
"coupon" => $couponId
));
Upvotes: 1