public class

StripeInvoiceClient

extends Object
java.lang.Object
   ↳ com.wsl.modules.stripe.client.StripeInvoiceClient

Class Overview

Encapsulates Invoice-related Stripe API calls.

Summary

Public Constructors
StripeInvoiceClient()
Public Methods
Invoice createInvoice(String customerId, int applicationFee, String description, Map<String, Object> metadata, String statementDescriptor, String subscription, double taxPercent)
Create an invoice Invoices are statements of what a customer owes for a particular billing period, including subscriptions, invoice items, and any automatic proration adjustments if necessary.
Invoice payInvoice(String id)
Pay an invoice
InvoiceCollection retrieveAllInvoices(String customerId, String dateTimestamp, TimeRange date, String endingBefore, int limit, String startingAfter)
List all Invoices
Invoice retrieveInvoice(String id)
Retrieve an Invoice
InvoiceLineItemCollection retrieveInvoiceLineItems(String id, String customer, String endingBefore, int limit, String startingAfter, String subscription)
Retrieve an invoice's line items When retrieving an invoice, you'll get a lines property containing the total count of line items and the first handful of those items.
Invoice retrieveUpcomingInvoice(String customerId, String subscription)
Retrieve an upcoming invoice At any time, you can preview the upcoming invoice for a customer.
Invoice updateInvoice(String invoiceId, int applicationFee, boolean closed, String description, boolean forgiven, Map<String, Object> metadata, String statementDescriptor, double taxPercent)
Update an invoice
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public StripeInvoiceClient ()

Public Methods

public Invoice createInvoice (String customerId, int applicationFee, String description, Map<String, Object> metadata, String statementDescriptor, String subscription, double taxPercent)

Create an invoice Invoices are statements of what a customer owes for a particular billing period, including subscriptions, invoice items, and any automatic proration adjustments if necessary. Once an invoice is created, payment is automatically attempted. Note that the payment, while automatic, does not happen exactly at the time of invoice creation. If you have configured webhooks, the invoice will wait until one hour after the last webhook is successfully sent (or the last webhook times out after failing). Any customer credit on the account is applied before determining how much is due for that invoice (the amount that will be actually charged). If the amount due for the invoice is less than 50 cents (the minimum for a charge), we add the amount to the customer's running account balance to be added to the next invoice. If this amount is negative, it will act as a credit to offset the next invoice. Note that the customer account balance does not include unpaid invoices; it only includes balances that need to be taken into account when calculating the amount due for the next invoice.

Parameters
customerId The customer to create the invoice for
applicationFee A fee in cents that will be applied to the invoice and transferred to the application owner’s Stripe account.
description The invoice description
metadata Arbitrary key-value pairs to attach to the invoice
statementDescriptor Extra information about a charge for the customer’s credit card statement.
subscription The ID of the subscription to invoice. If not set, the created invoice will include all pending invoice items for the customer. If set, the created invoice will exclude pending invoice items that pertain to other subscriptions.
taxPercent The percent tax rate applied to the invoice, represented as a decimal number.
Returns
  • Returns the invoice object if there are pending invoice items to invoice. Throws an error if there are no pending invoice items or if the customer ID provided is invalid.
Throws
StripeConnectorException when there is a problem with the Connector

public Invoice payInvoice (String id)

Pay an invoice

Parameters
id The invoice id
Returns
  • Returns the invoice object
Throws
StripeConnectorException when there is a problem with the Connector

public InvoiceCollection retrieveAllInvoices (String customerId, String dateTimestamp, TimeRange date, String endingBefore, int limit, String startingAfter)

List all Invoices

Parameters
customerId The id of the customer
dateTimestamp A filter on the list based on the object date field. The value can be a string with an integer Unix timestamp,...
date Or it can be a dictionary with the following options: gt, gte, lt, lte
endingBefore A cursor for use in pagination. ending_before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_bar, your subsequent call can include ending_before=obj_bar in order to fetch the previous page of the list.
limit A limit on the number of objects to be returned. Limit can range between 1 and 100 items.
startingAfter A cursor for use in pagination. starting_after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include starting_after=obj_foo in order to fetch the next page of the list.
Returns
  • Returns the collection of invoices
Throws
StripeConnectorException when there is a problem with the Connector

public Invoice retrieveInvoice (String id)

Retrieve an Invoice

Parameters
id The identifier of the desired invoice
Returns
  • Returns the invoice requested.
Throws
StripeConnectorException when there is a problem with the Connector

public InvoiceLineItemCollection retrieveInvoiceLineItems (String id, String customer, String endingBefore, int limit, String startingAfter, String subscription)

Retrieve an invoice's line items When retrieving an invoice, you'll get a lines property containing the total count of line items and the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items.

Parameters
id The id of the invoice containing the lines to be retrieved
customer In the case of upcoming invoices, the customer of the upcoming invoice is required. In other cases it is ignored.
endingBefore A cursor for use in pagination. ending_before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_bar, your subsequent call can include ending_before=obj_bar in order to fetch the previous page of the list.
limit A limit on the number of objects to be returned. Limit can range between 1 and 100 items.
startingAfter A cursor for use in pagination. starting_after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include starting_after=obj_foo in order to fetch the next page of the list.
subscription In the case of upcoming invoices, the subscription of the upcoming invoice is optional. In other cases it is ignored.
Returns
  • Returns the collection of invoice line items
Throws
StripeConnectorException when there is a problem with the Connector

public Invoice retrieveUpcomingInvoice (String customerId, String subscription)

Retrieve an upcoming invoice At any time, you can preview the upcoming invoice for a customer. This will show you all the charges that are pending, including subscription renewal charges, invoice item charges, etc. It will also show you any discount that is applicable to the customer. Note that when you are viewing an upcoming invoice, you are simply viewing a preview -- the invoice has not yet been created. As such, the upcoming invoice will not show up in invoice listing calls, and you cannot use the API to pay or edit the invoice. If you want to change the amount that your customer will be billed, you can add, remove, or update pending invoice items, or update the customer's discount.

Parameters
customerId The identifier of the customer whose upcoming invoice you'd like to retrieve.
subscription The identifier of the subscription for which you'd like to retrieve the upcoming invoice. If not provided, you will retrieve the next upcoming invoice from among the customer's subscriptions.
Returns
  • Returns an invoice if a valid customer ID was provided. Throws an error otherwise.
Throws
StripeConnectorException when there is a problem with the Connector

public Invoice updateInvoice (String invoiceId, int applicationFee, boolean closed, String description, boolean forgiven, Map<String, Object> metadata, String statementDescriptor, double taxPercent)

Update an invoice

Parameters
invoiceId The invoice to update
applicationFee A fee in cents that will be applied to the invoice and transferred to the application owner’s Stripe account.
closed Boolean representing whether an invoice is closed or not. To close an invoice, pass true.
description The invoice description
forgiven Boolean representing whether an invoice is forgiven or not. To forgive an invoice, pass true. Forgiving an invoice instructs us to update the subscription status as if the invoice were succcessfully paid. Once an invoice has been forgiven, it cannot be unforgiven or reopened.
metadata Arbitrary key-value pairs to attach to the invoice
statementDescriptor Extra information about a charge for the customer’s credit card statement.
taxPercent The percent tax rate applied to the invoice, represented as a decimal number.
Returns
  • Returns the invoice object
Throws
StripeConnectorException when there is a problem with the Connector