Last active
October 6, 2019 19:40
-
-
Save rmccullagh/1821351e1a4ca654bc1a8f51cce12435 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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