Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?
# MIT license, do whatever you want with it
#
# This is my invoice.php page which I use to make invoices that customers want,
# with their address on it and which are easily printable. I love Stripe but
# their invoices and receipts were too wild for my customers on Remote OK
#
require_once(__DIR__.'/../vendor/autoload.php');
\Stripe\Stripe::setApiKey(
$config['stripe']['general']['secret']
);
try {
$invoice=\Stripe\Invoice::retrieve($_GET['invoice_id']);
$invoice=json_decode(json_encode($invoice),true);
}
catch(\Stripe\Error\InvalidRequest $e) {
$body = $e->getJsonBody();
$err = $body['error'];
echo json_encode($err);
exit;
}
if(!$invoice['paid']) {
echo "Invoice wasn't paid";
exit;
}
if($invoice['dispute']) {
echo "Invoice was disputed";
exit;
}
if($invoice['refunded']) {
echo "Invoice was refunded";
exit;
}
?>
<!doctype html>
<title>
Invoice #<?=$invoice['id']?>
</title>
<style>
body {
font-family:sans-serif;
background:#555;
}
.page {
max-width:700px;
position:relative;
border:1px solid #efefef;
margin:14px auto;
background:#fff;
padding:56px;
margin-top:56px;
height:1000px;
box-shadow:0px 5px 5px rgba(0,0,0,0.5);
}
.right {
position:absolute;
right:56px;
top:56px;
text-align:right;
}
h1,strong {
font-weight:600;
}
p {
font-weight:400;
}
table {
width:100%;
border-collapse:collapse;
}
table thead th {
border-bottom:1px solid #000;
padding:14px;
text-align:left;
}
table td {
padding:14px;
}
@media print {
.page {
box-shadow:none;
border:none;
max-width:none;
height:auto;
padding:14px;
margin:14px;
}
.right {
top:14px;
right:14px;
}
body {
background:#fff;
padding:14px;
}
}
</style>
<div class="page">
<div class="right">
<h1>
Invoice
</h1>
<p>
<strong>Invoice number</strong>&nbsp;&nbsp;&nbsp;#<?if($invoice['receipt_number']){?><?=$invoice['receipt_number']?><?} else{?><?=$invoice['id']?><?}?><br/>
<strong>Date of issue</strong>&nbsp;&nbsp;&nbsp;&nbsp;<?=date('Y-m-d',$invoice['created']);?><br/>
<strong>Date paid</strong>&nbsp;&nbsp;&nbsp;&nbsp;<?=date('Y-m-d',$invoice['created']);?><br/>
<strong><?=$invoice['custom_fields'][0]['name']?></strong> <?=$invoice['custom_fields'][0]['value']?><br/>
</p>
</div>
<h1>
<?/*$config['brand']*/?>
<img title="Remote OK" style="width:250px;margin-left:-20px;margin-top:-17px;filter:invert(100%)" src="https://remoteok.io/assets/remoteok-logo.png?<?=filemtime(__DIR__.'/../assets/remoteok-logo.png');?>" />
</h1>
<p>
Acme Inc.<br/>
2400 5th Avenue<br/>
90210, Los Angeles, CA<br/>
Company Reg. No.: L0L0L0L<br/>
</p>
<p>
<strong>
Bill to
</strong><br/>
<?=$invoice['customer_name']?><br/>
<?=$invoice['customer_email']?><br/>
<?=$invoice['customer_address']['line1']?><br/>
<?=$invoice['customer_address']['line2']?><br/>
<?=$invoice['customer_address']['postal_code']?><br/>
<?=$invoice['customer_address']['state']?><br/>
<?=$invoice['customer_address']['city']?><br/>
<?=$invoice['customer_address']['country']?>
<p>
<h1>
US$<?=number_format($invoice['amount_paid']/100,2)?> paid <?=date('F j, Y',$invoice['created'])?>
</h1>
<?if($$invoice['source']['last4']){?>
<p>
Paid with <?=$invoice['source']['brand']?> *<?=$invoice['source']['last4']?>
</p>
<?}?>
<table>
<thead>
<tr>
<th>
Description
</th>
<th>
Qty
</th>
<th>
Unit price
</th>
<th>
Amount
</th>
</tr>
</thead>
<tbody>
<tr style="background:#efefef;border-bottom:1px solid #000">
<td>
<?=$invoice['lines']['data'][0]['description']?><br/>
</td>
<td>
1
</td>
<td>
$<?=number_format($invoice['amount_paid']/100,2)?>
</td>
<td>
$<?=number_format($invoice['amount_paid']/100,2)?>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
Subtotal
</td>
<td>
$<?=number_format($invoice['amount_paid']/100,2)?>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td style="background:#efefef;border-top:1px solid #000;border-bottom:1px solid #000">
<strong>
Amount paid
</strong>
</td>
<td style="background:#efefef;border-top:1px solid #000;border-bottom:1px solid #000">
<strong>
$<?=number_format($invoice['amount_paid']/100,2)?>
</strong>
</td>
</tr>
</tbody>
</table>
<br/>
<br/>
<br/>
<br/>
<p>
Questions? Contact Remote OK at <?=$config['fromEmail']?>
</p>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment