来自条纹文档:
取消订阅时,客户的卡不会 再次收费,但也没有钱退还。如果你愿意的话 退款,您可以通过Stripe的仪表板或通过 API。
我创建了每月订阅,我只想退还订阅月份内尚未过去的天数。如何使用Stripe API仅退还订阅中尚未完成的天数?
答案 0 :(得分:4)
您需要计算退款金额,然后对条纹进行refund API call。退款后,您必须为Subscription cancellation
再次拨打API答案 1 :(得分:3)
如果您想让Stripe处理退款计算,您可以将订阅数量更改为0,然后取消计划。
答案 2 :(得分:1)
经过一段时间的研究,我来到这个用JavaScript编写的Node.js流程:
refundAndUnsubscribe = async function () {
try {
// Set proration date to this moment:
const proration_date = Math.floor(Date.now() / 1000);
let sub = await stripe.subscriptions.retrieve("sub_CILnalN9HpvADj");
// See what the next invoice would look like with a plan switch
// and proration set:
let items = [{
quantity: 0,
id: sub.items.data[0].id,
plan: "your_plan" // Switch to new plan
}];
let invoices = await stripe.invoices.retrieveUpcoming('cus_CIP9dtlq143gq7', 'sub_CILnalN9HpvADj', {
subscription_items: items,
subscription_proration_date: proration_date
});
//List all invoices
let payedInvoicesList = await stripe.invoices.list({
customer: 'cus_CIP9dtlq143gq7'
});
// Calculate the proration cost:
let current_prorations = [];
let cost = 0;
for (var i = 0; i < invoices.lines.data.length; i++) {
let invoice_item = invoices.lines.data[i];
if (invoice_item.period.start == proration_date) {
current_prorations.push(invoice_item);
cost += invoice_item.amount;
}
}
//create a refund
if (cost !== 0) {
cost = (cost < 0) ? cost * -1 : cost //A positive integer in cents
let refund = await stripe.refunds.create({
charge: payedInvoicesList.data[0].charge,
amount: cost
});
}
// delete subscription
return stripe.subscriptions.del('sub_CILnalN9HpvADj');
} catch (e) {
console.log(e);
}
}
答案 3 :(得分:0)
条带现在将处理此问题。它可以立即取消订阅并创建发票,退还他们当月未使用的费用,也可以将其留在他们的帐户中,作为以后任何发票的抵免额。
https://stripe.com/docs/api/subscriptions/cancel
添加“按比例”标记以退还剩余的每月费用。
如果您想让客户退款而不是给他们帐户信用,请添加“ invoice_now”标签来创建具有该按比例退款金额的立即最终发票。
在PHP中:
$subscription = \Stripe\Subscription::retrieve(
'SUBSCRIPTION_ID'
);
$subscription->delete([
'prorate' => true,
'invoice_now' => true
]);