Home > Mobile >  Create a table of all invoices from Stripe API in PHP
Create a table of all invoices from Stripe API in PHP

Time:12-10

I am trying to create a table in PHP of all invoices in the table with the Stripe API.

This is my code so far:

$result = $stripe->invoices->all(['limit' => 100]);

echo $result;

I don't know how I can just display the invoice id, customer name and amount in a table. This is my first time working with Stripe and API's.

CodePudding user response:

I wasn't whether your question is more about the Stripe Invoice object, looping over all invoices (e.g. auto-pagination or a PHP question on how to display a table. I concocted a response with all 3 of these things. I took the liberty to add some other info to the table as well.

<?php
$invoices = $stripe->invoices->all([
    'limit' => 50,
]);
?>

<table>
    <tr>
        <th>Invoice Id</th>
        <th>Customer Id</th>
        <th>Customer Name</th>
        <th>Customer Email</th>
        <th>Amount Due</th>
        <th>Amount Paid</th>
        <th>Amount Remaining</th>
        <th>Status</th>
    </tr>
    <?php
    foreach ($invoices->autoPagingIterator() as $invoice) {
    ?>
        <tr>
            <td><?php echo $invoice['id']; ?></td>
            <td><?php echo $invoice['customer_id']; ?></td>
            <td><?php echo $invoice['customer_name']; ?></td>
            <td><?php echo $invoice['customer_email']; ?></td>
            <td><?php echo $invoice['amount_due'] . $invoice['currency']; ?></td>
            <td><?php echo $invoice['amount_paid'] . $invoice['currency']; ?></td>
            <td><?php echo $invoice['amount_remaining'] . $invoice['currency']; ?></td>
            <td><?php echo $invoice['status']; ?></td>
        </tr>
    <?php
    }
    ?>
</table> 
  • Related