craftcms/commerce-stripe

Modifying Invoice Text

cmartinespinosa opened this issue · 1 comments

Description

I need to inquire about an issue in the Craft Commerce Stripe regarding a text that appears on invoices, and I'm unsure how to modify it. When I check the database, specifically the 'stripe_invoices' table and the 'invoiceData' column, I find a JSON with a lot of information. Interestingly, within this JSON, under 'lines > data > 0 > description,' I see the exact message that later appears on the invoices. How can I modify this text? Do I need to send it to Stripe beforehand?

You would need to hook into the invoice create event and then modify it and then save it with stripe API

use craft\commerce\stripe\events\CreateInvoiceEvent;
use craft\commerce\stripe\base\SubscriptionGateway as StripeGateway;
use yii\base\Event;

Event::on(StripeGateway::class, StripeGateway::EVENT_CREATE_INVOICE, function(CreateInvoiceEvent $e) {

$stripeCient = $e->sender->getStripeClient();
$invoice = stripeCient->invoices->retrieve($e->invoiceData['id']);

// Update the invoice:
$stripeCient->invoices->update(
  $invoice->id,
  ['metadata' => ['order_id' => '6735']]
);

});

Stripe invoice API docs: https://docs.stripe.com/api/invoices