---
title: Create and Charge
slug: payments/d4gydd7dorll77xu2kvhw
description: Learn how to create invoices using Apex by following this example code. The code includes creating a map of invoice data, adding items to the invoice, and serializing the request and response as JSON. Find out how to retrieve essential information about t
docTags: 
createdAt: 2023-11-08T12:13:56.160Z
---

To Create and Charge an Invoice in Stripe, use the action "CreateInvoice," collectionMethod as "charge\_automatically," invoiceStatus as "CHARGE\_CUSTOMER" and pass the Invoice data in the RequestJSON under "invoices."

:::hint{type="info"}
Note: You can only create one record at a time.
:::

The following is an example of Create and Charge an Invoice, where we are setting every possible field (See [﻿](https://app.archbee.io/docs/-LIHUUnv_7XNQrtzHsKkC/hnjmkN99QxWdEafyYIFSq)[Invoice - Stripe](docId\:JG10UgmTnBrsw2A0WbE1K) for the available fields). The response will return the response from Stripe, which includes the new Stripe Invoice ID (*internalId*), plus the newly created Salesforce ﻿Invoice ID (*salesforceId*).

:::CodeblockTabs
```apex
Map<String, Object> invoiceData = new Map<String, Object>();
invoiceData.put('processorCustomerId', 'processorCustomerId');
invoiceData.put('collectionMethod', 'charge_automatically');
invoiceData.put('invoiceStatus', 'CHARGE_CUSTOMER'); 
invoiceData.put('processorPaymentMethodId', 'processorPaymentMethodId');

List<object> items = new List<object>();
Map<String, Object> itemData = new Map<String, Object>();
itemData.put('processorPriceId', 'processorPriceId'); 
itemData.put('quantity', 2); 
items.add(itemData);
invoiceData.put('items', items); 

//  Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('invoices', new List<Object>{invoiceData});
String reqJSON = JSON.serialize(requestJSONMap);

Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version','1.0');
reqObj.put('action','CreateInvoice');
reqObj.put('processorId', 'processorId');
reqObj.put('requestJSON',reqJSON);

//  Placing a request to Breadwinner Global API
Map<String,Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
System.debug(resp);
```

```json
{
  Action=CreateInvoice,
  Version=1.0,
  responseJSON={
    "invoices": [
      {
        "status": "Paid",
        "salesforceId": "salesforceInvoiceId",
        "salesforceContact": null,
        "salesforceAccount": null,
        "processorPaymentMethodId": null,
        "processorOrgId": "processorOrgId",
        "processorInvoiceId": "processorInvoiceId",
        "processorCustomerId": null,
        "items": [
          {
            "unitAmountDecimal": 100.00,
            "unitAmount": 100.00,
            "salesforceSubscriptionId": null,
            "salesforcePriceId": "salesforcePriceId",
            "salesforceInvoiceId": null,
            "salesforceId": "salesforceLineItemId",
            "quantity": 2,
            "processorSubscriptionId": null,
            "processorPriceId": null,
            "processorInvoiceId": "processorInvoiceId",
            "processorId": "processorId",
            "name": null,
            "metadataAsString": null,
            "errorMessage": null,
            "description": "Test Product 123",
            "deleted": null,
            "chargeCurrency": "USD",
            "amount": 200.00
          }
        ],
        "errorMessage": null,
        "dueDate": null,
        "description": null,
        "createdVia": "Breadwinner",
        "createdDateInProcessor": "2023-09-27T09:29:04.000Z",
        "collectionMethod": "Charge Automatically"
      }
    ]
  },
  statusCode=null,
  timestamp=1695806947688,
  validRequest=true
}
```
:::

