我正在尝试从结账会话完成事件中检索促销代码。经过研究,我发现该活动不包含折扣,我需要对其进行扩展。
我尝试了curl并获得了折扣信息,其中包含促销代码。但是当我使用 SDK 时,我没有获得促销代码信息。知道为什么吗?
卷曲结果
"total_details": {
"amount_discount": 110,
"amount_shipping": 0,
"amount_tax": 0,
"breakdown": {
"discounts": [
{
"amount": 110,
"discount": {
"id": "di_1PgRsPDLL6mQEvFDqa26571I",
"object": "discount",
"checkout_session": "cs_test_b1e9u48OHdZ5F6ITVhgUOSG3aUw6ker5ykTGPxA1qJAALWQfIDUDdlsCpH",
"coupon": {
"id": "D3muUbBu",
"object": "coupon",
"amount_off": null,
"created": 1710630574,
"currency": null,
"duration": "once",
"duration_in_months": null,
"livemode": false,
"max_redemptions": null,
"metadata": {},
"name": "williamette",
"percent_off": 10.0,
"redeem_by": null,
"times_redeemed": 23,
"valid": true
},
"customer": null,
"end": null,
"invoice": null,
"invoice_item": null,
"promotion_code": "promo_1Ov6MmDLL6mQEvFDcPVK9bfM",
"start": 1721914717,
"subscription": null,
"subscription_item": null
}
}
],
卷曲命令
curl -G https://api.stripe.com/v1/checkout/sessions/cs_test_b1e9u48OHdZ5F6ITVhgUOSG3aUw6ker5yALWQfIDUDdlsCpH \\n -u "sk_tes7ozsXaS6ZzKNZOca00oQDQ6H2p:" \\n -d "expand[]"=total_details.breakdown
SDK结果
"total_details": {
"amount_discount": 500,
"amount_shipping": 0,
"amount_tax": 0,
"breakdown": {
"discounts": [
{
"amount": 500,
"discount": {
"amount": null,
"discount": null
}
}
],
"taxes": []
}
}
代码
Stripe.apiKey = apiKey;
SessionRetrieveParams params = SessionRetrieveParams.builder()
.addExpand("total_details.breakdown")
.build();
// Additional option for creating a coupon on a connected account
RequestOptions requestOptions =
RequestOptions.builder().setStripeAccount(accId).build();
try {
Session session2 = Session.retrieve(chId, params, requestOptions);
return session2;
} catch (Exception e) {
e.printStackTrace();
return null;
}
知道为什么 SDK 没有返回任何有关展开折扣的信息吗?
你能检查一下你使用的stripe-java SDK版本吗?对于上下文,stripe-java SDK v24.14.0
中进行了修复⚠️ 修复
中对com.stripe.model.Discount
的损坏引用(这代表一个错误修复,因为此类永远无法工作,但可能是一个破坏性的类型更改)checkout.Session.TotalDetails.Breakdown.Discount