Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
require_once 'vendor/autoload.php';
class Invoice
{
/**
* @var \Stripe\Invoice;
*/
private $invoice;
/**
* Represents a Stripe invoice. Pass in the result from `\Stripe\Invoice::retrieve`
*
* @param string $stripeObj stripe api Invoice
*
* @see https://stripe.com/docs/api/invoices/retrieve?lang=php
*/
public function __construct(Stripe\Invoice $invoice)
{
$this->invoice = $invoice;
}
/**
* Sum all line items in this invoice
*
* @return int
*/
public function getTotal()
{
$amount = 0;
foreach ($this->invoice->lines as $line) {
$amount += $line->amount;
}
return $amount;
}
/**
* Get the invoice amount
*
* @return string
*/
public function getPresentableAmount()
{
$formatter = new \NumberFormatter(
'en_US',
\NumberFormatter::CURRENCY
);
return $formatter->formatCurrency(
$this->getTotal() / 100,
$this->getCurrency()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.