Dopo la ricerca per un po ', sono arrivato a questo flusso scritto in JavaScript per 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);
}
}
fonte
2018-02-14 04:16:26
E' la metà del 2016 e che è sorprendente banda ancora non ha attuato l'integrale sottoscrizione ciclo di vita (in particolare alla fine del ciclo di vita) – DeepSpace101