noobie-php
noobie-php

Reputation: 7233

Stripe create invoice/invoices for charges

I am using one time payment, and i am trying to generate invoice for the charges, i can list all the charges, but there i dont see a way to generate invoices for the charges.

Following is how i am getting my charges.

\Stripe\InvoiceItem::create(array(
                    "customer" => $customer_id,
                    "amount" => $price,
                    "currency" => "aud",
                    "description" => $courseTitle)
            );// creating invoice items here


$charges = \Stripe\InvoiceItem::all(array("customer" => $customer_id));

Upvotes: 4

Views: 3124

Answers (1)

duck
duck

Reputation: 5470

It's a bit unusual to use Invoices in this way, in most cases they are used with Stripe's Subscriptions. If you wanted to make a one off charge for a series of items you'd simply create a charge for the total amount and sum the items on your side/in your logic.

https://stripe.com/docs/api/php#create_charge

\Stripe\Charge::create(array(
  "amount" => 2000,
  "currency" => "usd",
  "customer" => "cus_xxxyyyzz", // charge my existing customer
  "description" => "Charge items"
));

If you are intent on using Invoices, you'd create the Customer, add the invoice items, and then create an Invoice.

https://stripe.com/docs/api/php#create_invoice

// create customer
$customer = \Stripe\Customer::create(array(
  "description" => "Jamie Smith",
  "source" => "tok_mastercard" // normally obtained with Stripe.js
));

// create invoice items
\Stripe\InvoiceItem::create(array(
    "customer" => $customer->id,
    "amount" => 2500,
    "currency" => "usd",
    "description" => "One-time fee")
);

// pulls in invoice items
\Stripe\Invoice::create(array(
    "customer" => $customer->id
));

Upvotes: 1

Related Questions