我的总体目标是使用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 :(得分:1)
可以使用coupon
中的order creation requests参数对订单应用折扣。
在PHP中,它看起来像这样:
[INFO] mei 20, 2016 12:01:11 AM org.apache.jasper.compiler.JspRuntimeContext initClassPath
[INFO] FINE: Compilation classpath initialized:
/C:/work/Bitbucket/MessageApp3/target/MessageApp3-1.0-SNAPSHOT/WEB-INF/classes/;
/C:/work/Bitbucket/MessageApp3/target/MessageApp3-1.0-SNAPSHOT/WEB-INF/lib/appengine-api-1.0-sdk-1.9.37.jar;
/C:/Users/ABB/.m2/repository/com/google/appengine/appengine-java-sdk/1.9.37/appengine-java-sdk/appengine-java-sdk-1.9.37/lib/impl/agent/appengine-agentruntime.jar;
/C:/work/Bitbucket/MessageApp3/target/MessageApp3-1.0-SNAPSHOT/WEB-INF/lib/guava-18.0.jar;
/C:/work/Bitbucket/MessageApp3/target/MessageApp3-1.0-SNAPSHOT/WEB-INF/lib/jstl-1.2.jar;
/C:/work/Bitbucket/MessageApp3/target/MessageApp3-1.0-SNAPSHOT/WEB-INF/lib/objectify-5.1.5.jar;
/C:/Users/ABB/.m2/repository/com/google/appengine/appengine-java-sdk/1.9.37/appengine-java-sdk/appengine-java-sdk-1.9.37/lib/tools/jsp/repackaged-appengine-jakarta-jstl-1.1.2.jar;
/C:/Users/ABB/.m2/repository/com/google/appengine/appengine-java-sdk/1.9.37/appengine-java-sdk/appengine-java-sdk-1.9.37/lib/tools/jsp/repackaged-appengine-jakarta-standard-1.1.2.jar;
/C:/Users/ABB/.m2/repository/com/google/appengine/appengine-java-sdk/1.9.37/appengine-java-sdk/appengine-java-sdk-1.9.37/lib/tools/jsp/repackaged-appengine-jasper-jdt-6.0.29.jar;
/C:/Users/ABB/.m2/repository/com/google/appengine/appengine-java-sdk/1.9.37/appengine-java-sdk/appengine-java-sdk-1.9.37/lib/opt/tools/appengine-local-endpoints/v1/appengine-local-endpoints.jar;
C:\Users\ABB\AppData\Local\Temp\Jetty_127_0_0_1_8080_MessageApp3.1.0.SNAPSHOT____1qwjqs\jsp;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\appengine-local-runtime-shared.jar;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\el-api.jar;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\jsp\repackaged-appengine-ant-1.7.1.jar;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\jsp\repackaged-appengine-ant-launcher-1.7.1.jar;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\jsp\repackaged-appengine-jasper-6.0.29.jar;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\jsp\repackaged-appengine-jasper-el-6.0.29.jar;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\jsp\repackaged-appengine-tomcat-juli-6.0.29.jar;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\jsp-api.jar;
C:\Users\ABB\.m2\repository\com\google\appengine\appengine-java-sdk\1.9.37\appengine-java-sdk\appengine-java-sdk-1.9.37\lib\shared\servlet-api.jar;
C:\work\Bitbucket\MessageApp3\target\MessageApp3-1.0-SNAPSHOT\classes;
[INFO] mei 20, 2016 12:01:11 AM org.apache.jasper.servlet.JspServlet init
[INFO] FINE: Scratch dir for the JSP engine is: C:\Users\ABB\AppData\Local\Temp\Jetty_127_0_0_1_8080_MessageApp3.1.0.SNAPSHOT____1qwjqs\jsp