2016-05-19 112 views
0

我的總體目標是使用Stripe API創建一次性購物折扣。我注意到,通過API的折扣只適用於發票,我並不是用於一次性付款。條紋訂單更改金額

我目前正在嘗試更改訂單金額。我在API中讀到,您無法更新訂單金額,因此我需要刪除通過我的代碼創建的現有訂單,然後創建一個新訂單,但金額不是原始SKU商品的價格。這似乎不起作用。

請求看起來像這樣(通過條紋儀表盤日誌):

{ 
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" 
} 

但反應似乎忽略我的更新數量:

items: { 
    object: "order_item" 
    amount: 8500 
    currency: "sek" 
    description: "Specialpåse" 
    parent: "sku_8E8ZS8KYaJbUkK" 
    quantity: 1 
    type: "sku" 
} 

PHP代碼:

$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; 
    } 

$ items看起來像這樣:

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 
     ) 

) 
+0

這是不是一個直接的問題支持條鏽? – Peon

+1

如果我看到這個正確的,你不能*刪除*訂單,你可以**取消**它通過添加'status = cancelled'到您的請求:https://stripe.com/docs/api# update_order – Peon

回答

1

可以通過使用order creation requests中的coupon參數對訂單應用折扣。

在PHP中,它應該是這樣的:

$newOrder = \Stripe\Order::create(array(
    "items" => generateItems($items), 
    "customer" => $customer, 
    "currency" => "sek", 
    "metadata" => array("delivery_date" => $delivery_date), 
    "coupon" => $couponId 
));