#Vishu

1 messages · Page 1 of 1 (latest)

quick zincBOT
brisk apex
#

That sounds totally fine. I can't imagine any blockers or weird behaviors to be conscious of, so that workflow should just work as expected. Do you have any implementation questions?

candid seal
#

Yes

#

Give me a sec

#

// Set your Stripe API key
\Stripe\Stripe::setApiKey("sk_test_your_api_key");

// Retrieve a list of uncollectible invoices from Stripe
$uncollectible_invoices = \Stripe\Invoice::all([
"status" => "uncollectible"
]);

// Iterate over the uncollectible invoices
foreach ($uncollectible_invoices->data as $invoice) {
// Add an additional penalty of AUD$10 to the invoice
$invoice->items->data[0]->price_override = [
"unit_amount" => $invoice->items->data[0]->price->unit_amount + 1000, // 1000 is equivalent to AUD$10
"currency" => "AUD"
];
$invoice->save();

// Send the updated invoice to the customer and get the hosted invoice URL
$invoice->sendInvoice();
$invoice_url = $invoice->hosted_invoice_url;

// Send an email to the customer with the hosted invoice URL
$customer = \Stripe\Customer::retrieve($invoice->customer);
$email = $customer->email;
$subject = "Invoice Payment Reminder";
$message = "Hello,\n\nAn additional penalty of AUD$10 has been added to your invoice. Please use the following link to make the payment:\n\n" . $invoice_url . "\n\nThank you for your business.\n\nBest regards,\nYour Company";
mail($email, $subject, $message);
}

#

Would you mind checking if the above code looks right as I have advised my developers to do this but they are saying that its not doable?

#

Also, I would appreciate if you can guide me to any documentation that can be used to implement this.

brisk apex
#

Did they say why it couldn't be done?

candid seal
#

Yes

#

Following was there reply

#

Sir I have checked that we cannot revise a subscription's invoice and if we create a new invoice, then we won't be able to attach that to the subscription. In such a scenario, we won't be able to manage the penalties or any changes.

brisk apex
#

So the workflow you mentioned at the beginning would be for a one-off invoice and you would have to track which Subscription it was related to on your end (e.g. put the Subscription ID in the metadata field on the Invoice to associate the new one-off invoice with the Subscription via your own database).

If you wanted the Invoice to be associated with the Invoice, you would just add new Invoice Items to the Invoice that gets created during the next billing cycle on the Subscription.

candid seal
#

Thanks for your help @brisk apex

brisk apex
#

Sure thing!

candid seal
#

So, you mean to say that we have to use metadata field to map invoices and there is no direct way to do this?
Also, I didn’t quite get the last paragraph :(. Would you mind elaborating that a bit? Please

brisk apex
#

You can create Invoice Items instead of a one-off Invoice if you want the new late-fee and old Invoice amount to be associated with the Subscription. These get added to the Invoice that is drafted during the Subscription's next billing cycle.

at a more granular level, you would create an Invoice Item for the fee, then a separate Invoice Item for the amount of the Invoice that was marked as uncollectible (see here: https://stripe.com/docs/api/invoiceitems/create). You pass the Subscription's ID when you create the Invoice Item (see this field: https://stripe.com/docs/api/invoiceitems/create#create_invoiceitem-subscription) to make sure the newly created Invoice Item is associated with the Subscription. That will also ensure that the new Invoice Items show up on the next Invoice that gets drafted for that Subscription.

candid seal
#

Ok, but the penalty will only be once off. The subscription payment will be normal price for next billing cycle. I hope this won’t make the penalty recurring on all the future billing cycles. We only want to charge penalty when the direct debit fails and we are sending a hosted invoice. I hope it makes sense.

brisk apex
#

Adding Invoice Items can be one-off or recurring. You choose that by setting (or not setting) recurring on the Price object.

candid seal
#

Thanks for bearing my questions @brisk apex. So, from above what I understand is that - we can make a new invoice with penalty following your above instructions and we can actually make that penalty a recurring one for next invoices that are automatically generated for next billing cycles.
So, we are talking about two scenarios here. First that for the uncollectible invoices we have to create new hosted invoice and use invoice items to specify the subscription payment that failed and another invoice item to add penalty. This can be sent to customer for payment and the subscription will continue as it. Am i right?

#

Second- we can also make that penalty recurring

#

I would like to mention that we are only looking for a solution to receive payment for failed subscription so that we don’t have to cancel the subscriptions and that they can continue as it for next billing cycles.

brisk apex
#

This can be sent to customer for payment and the subscription will continue as it. Am i right?
Correct. It would be sent via whatever method you had already configured for the Subscription.

#

I would like to mention that we are only looking for a solution to receive payment for failed subscription so that we don’t have to cancel the subscriptions and that they can continue as it for next billing cycles.
Yup! That's exactly what the above method does

candid seal
#

Thanks heaps @brisk apex , I will reach out if needed.

brisk apex
#

Sure thing!