Unicode C++ Requires Chilkat v11.7.0+
Unicode C++
Stripe: Draft an invoice and attach line items
See more Stripe Examples
Create a draft for a customer and attach a priced line item to that specific invoice.
Stripe documentation and cURL example
Chilkat Unicode C++ Downloads
#include <CkHttpCurlW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// Requires an unlocked Chilkat bundle. See Global Unlock Sample.
// Supply a restricted sandbox key from merchant-controlled configuration.
const wchar_t *apiKey = L"YOUR_STRIPE_TEST_KEY";
// Load the saved UUID for this operation. Reuse it only for a retry with identical inputs.
const wchar_t *operationId = L"YOUR_SAVED_OPERATION_UUID";
CkHttpCurlW curl;
CkStringBuilderW cmd;
CkJsonObjectW json;
int replaced;
const wchar_t *customerId = L"cus_FROM_BILLING_ACCOUNT";
const wchar_t *priceId = L"price_FROM_CATALOG";
// curl -X POST "https://api.stripe.com/v1/invoices" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive" \
// -H "Idempotency-Key: {operationId}-draft" \
// -d "customer={customerId}" \
// -d "collection_method=send_invoice" \
// -d "days_until_due=30" \
// -d "auto_advance=false" \
// -d "pending_invoice_items_behavior=exclude"
cmd.SetString(L"curl -X POST \"https://api.stripe.com/v1/invoices\"");
cmd.Append(L" -u \"@KEY@:\"");
cmd.Append(L" -H \"Stripe-Version: 2026-10-28.endive\"");
cmd.Append(L" -H \"Idempotency-Key: @OP@-draft\"");
cmd.Append(L" -d \"customer=@CUSTOMER@\"");
cmd.Append(L" -d \"collection_method=send_invoice\"");
cmd.Append(L" -d \"days_until_due=30\"");
cmd.Append(L" -d \"auto_advance=false\"");
cmd.Append(L" -d \"pending_invoice_items_behavior=exclude\"");
replaced = cmd.Replace(L"@CUSTOMER@",customerId);
replaced = cmd.Replace(L"@OP@",operationId);
replaced = cmd.Replace(L"@KEY@",apiKey);
success = curl.DoYourThing(cmd.getAsString());
if (success != true) {
wprintf(L"No HTTP response. Chilkat failure code: %d\n",curl.get_FailReason());
return;
}
success = curl.GetResponseJson(json);
if ((curl.get_StatusCode() != 200) || (success != true)) {
wprintf(L"Stripe HTTP %d Request-Id: %s\n",curl.get_StatusCode(),curl.getResponseHeaderField(L"Request-Id"));
if (success == true) {
wprintf(L"%s\n",json.stringOf(L"error.message"));
}
return;
}
const wchar_t *invoiceId = json.stringOf(L"id");
wprintf(L"Save draft invoice ID: %s\n",invoiceId);
// Attach this line to the draft. Use a distinct stable key per local line on retries.
// curl -X POST "https://api.stripe.com/v1/invoiceitems" \
// -u "$STRIPE_API_KEY:" \
// -H "Stripe-Version: 2026-10-28.endive" \
// -H "Idempotency-Key: {operationId}-line-1" \
// -d "invoice={invoiceId}" \
// -d "customer={customerId}" \
// -d "pricing[price]={priceId}" \
// -d "quantity=2"
cmd.SetString(L"curl -X POST \"https://api.stripe.com/v1/invoiceitems\"");
cmd.Append(L" -u \"@KEY@:\"");
cmd.Append(L" -H \"Stripe-Version: 2026-10-28.endive\"");
cmd.Append(L" -H \"Idempotency-Key: @OP@-line-1\"");
cmd.Append(L" -d \"invoice=@INVOICE@\"");
cmd.Append(L" -d \"customer=@CUSTOMER@\"");
cmd.Append(L" -d \"pricing[price]=@PRICE@\"");
cmd.Append(L" -d \"quantity=2\"");
replaced = cmd.Replace(L"@INVOICE@",invoiceId);
replaced = cmd.Replace(L"@CUSTOMER@",customerId);
replaced = cmd.Replace(L"@PRICE@",priceId);
replaced = cmd.Replace(L"@OP@",operationId);
replaced = cmd.Replace(L"@KEY@",apiKey);
success = curl.DoYourThing(cmd.getAsString());
if (success != true) {
wprintf(L"No HTTP response. Chilkat failure code: %d\n",curl.get_FailReason());
return;
}
success = curl.GetResponseJson(json);
if ((curl.get_StatusCode() != 200) || (success != true)) {
wprintf(L"Stripe HTTP %d Request-Id: %s\n",curl.get_StatusCode(),curl.getResponseHeaderField(L"Request-Id"));
if (success == true) {
wprintf(L"%s\n",json.stringOf(L"error.message"));
}
return;
}
wprintf(L"invoice = %s\n",json.stringOf(L"invoice"));
wprintf(L"id = %s\n",json.stringOf(L"id"));
wprintf(L"amount = %s\n",json.stringOf(L"amount"));
wprintf(L"currency = %s\n",json.stringOf(L"currency"));
}