2

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
        )

)
2
  • Is this not a direct question to Stripe support?
    – Peon
    Commented May 19, 2016 at 15:38
  • 1
    If I'm seeing this correctly, you can not delete an order, you can only cancel it by adding status = canceled to your request: stripe.com/docs/api#update_order
    – Peon
    Commented May 19, 2016 at 15:41

1 Answer 1

1

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
));

Not the answer you're looking for? Browse other questions tagged or ask your own question.