Appearance
Record Maytes payments in Stripe
When your customer pays with Maytes, the payment doesn't go through Stripe, so the order's invoice stays unpaid in your Stripe Dashboard. After you capture, mark that invoice as paid outside Stripe. It then shows as paid, and your customer can get a Stripe receipt.
No money moves through Stripe
You're still paid through Maytes settlements.
What you'll see in Stripe
- Invoices: the order's invoice, shown as Paid.
- Payments: a payment shown as Paid out of band, plus a canceled Payment for Invoice.
- Receipt: Paid with: Split with Maytes in its header.
Stripe creates the Payment for Invoice when you finalize the invoice, then cancels it when you mark the invoice paid. It moves no money, and you can't avoid it.
Each customer also gets a Maytes receipt for their own share.
What you need
Do this from your server, right after capture returns status: "captured". The examples use these values:
| In the examples | Where it comes from |
|---|---|
invoiceId | Your Stripe invoice for the order |
orderId | The capture response's merchant_order_id, or your own order number if you didn't send one |
checkoutUuid | The capture response's checkout_uuid, so you can match the invoice to the Maytes checkout |
Python and Ruby use invoice_id, order_id and checkout_uuid. Your Stripe secret key is read from STRIPE_SECRET_KEY.
Don't have an invoice for the order yet?
Create one with your customer and the order's line items, then use its ID as invoiceId. These examples also use:
| In the examples | Where it comes from |
|---|---|
lineItems | Your order's line items, each with a description and an amount in minor units (4500 is AUD 45.00). They must add up to the capture response's amount |
currency | The capture response's currency, in lowercase: AUD becomes aud |
Python and Ruby use line_items. A receipt needs the customer's email address.
ts
// Who the receipt is billed to
const customer = await stripe.customers.create({
name: 'Customer Name',
email: 'customer@example.com',
});
// An invoice for the order. Stripe won't send or charge it
const invoice = await stripe.invoices.create({
customer: customer.id,
currency,
collection_method: 'send_invoice',
days_until_due: 0,
auto_advance: false,
description: `Order ${orderId}`,
});
// One invoice item per line of your order
for (const item of lineItems) {
await stripe.invoiceItems.create({
customer: customer.id,
invoice: invoice.id,
amount: item.amount,
currency,
description: item.description,
});
}
const invoiceId = invoice.id;python
# Who the receipt is billed to
customer = stripe.v1.customers.create({
"name": "Customer Name",
"email": "customer@example.com",
})
# An invoice for the order. Stripe won't send or charge it
invoice = stripe.v1.invoices.create({
"customer": customer.id,
"currency": currency,
"collection_method": "send_invoice",
"days_until_due": 0,
"auto_advance": False,
"description": f"Order {order_id}",
})
# One invoice item per line of your order
for item in line_items:
stripe.v1.invoice_items.create({
"customer": customer.id,
"invoice": invoice.id,
"amount": item["amount"],
"currency": currency,
"description": item["description"],
})
invoice_id = invoice.idphp
// Who the receipt is billed to
$customer = $stripe->customers->create([
'name' => 'Customer Name',
'email' => 'customer@example.com',
]);
// An invoice for the order. Stripe won't send or charge it
$invoice = $stripe->invoices->create([
'customer' => $customer->id,
'currency' => $currency,
'collection_method' => 'send_invoice',
'days_until_due' => 0,
'auto_advance' => false,
'description' => "Order {$orderId}",
]);
// One invoice item per line of your order
foreach ($lineItems as $item) {
$stripe->invoiceItems->create([
'customer' => $customer->id,
'invoice' => $invoice->id,
'amount' => $item['amount'],
'currency' => $currency,
'description' => $item['description'],
]);
}
$invoiceId = $invoice->id;go
// Who the receipt is billed to
customer, err := sc.V1Customers.Create(ctx, &stripe.CustomerCreateParams{
Name: stripe.String("Customer Name"),
Email: stripe.String("customer@example.com"),
})
if err != nil { /* handle */ }
// An invoice for the order. Stripe won't send or charge it
invoice, err := sc.V1Invoices.Create(ctx, &stripe.InvoiceCreateParams{
Customer: stripe.String(customer.ID),
Currency: stripe.String(currency),
CollectionMethod: stripe.String("send_invoice"),
DaysUntilDue: stripe.Int64(0),
AutoAdvance: stripe.Bool(false),
Description: stripe.String("Order " + orderId),
})
if err != nil { /* handle */ }
// One invoice item per line of your order
for _, item := range lineItems {
_, err = sc.V1InvoiceItems.Create(ctx, &stripe.InvoiceItemCreateParams{
Customer: stripe.String(customer.ID),
Invoice: stripe.String(invoice.ID),
Amount: stripe.Int64(item.Amount),
Currency: stripe.String(currency),
Description: stripe.String(item.Description),
})
if err != nil { /* handle */ }
}
invoiceId := invoice.IDjava
// Who the receipt is billed to
Customer customer = stripe.v1().customers().create(
CustomerCreateParams.builder()
.setName("Customer Name")
.setEmail("customer@example.com")
.build());
// An invoice for the order. Stripe won't send or charge it
Invoice invoice = stripe.v1().invoices().create(
InvoiceCreateParams.builder()
.setCustomer(customer.getId())
.setCurrency(currency)
.setCollectionMethod(InvoiceCreateParams.CollectionMethod.SEND_INVOICE)
.setDaysUntilDue(0L)
.setAutoAdvance(false)
.setDescription("Order " + orderId)
.build());
// One invoice item per line of your order
for (LineItem item : lineItems) {
stripe.v1().invoiceItems().create(
InvoiceItemCreateParams.builder()
.setCustomer(customer.getId())
.setInvoice(invoice.getId())
.setAmount(item.amount())
.setCurrency(currency)
.setDescription(item.description())
.build());
}
String invoiceId = invoice.getId();ruby
# Who the receipt is billed to
customer = stripe.v1.customers.create({
name: 'Customer Name',
email: 'customer@example.com',
})
# An invoice for the order. Stripe won't send or charge it
invoice = stripe.v1.invoices.create({
customer: customer.id,
currency: currency,
collection_method: 'send_invoice',
days_until_due: 0,
auto_advance: false,
description: "Order #{order_id}",
})
# One invoice item per line of your order
line_items.each do |item|
stripe.v1.invoice_items.create({
customer: customer.id,
invoice: invoice.id,
amount: item[:amount],
currency: currency,
description: item[:description],
})
end
invoice_id = invoice.idcsharp
// Who the receipt is billed to
var customer = await stripe.V1.Customers.CreateAsync(new CustomerCreateOptions
{
Name = "Customer Name",
Email = "customer@example.com",
});
// An invoice for the order. Stripe won't send or charge it
var invoice = await stripe.V1.Invoices.CreateAsync(new InvoiceCreateOptions
{
Customer = customer.Id,
Currency = currency,
CollectionMethod = "send_invoice",
DaysUntilDue = 0,
AutoAdvance = false,
Description = $"Order {orderId}",
});
// One invoice item per line of your order
foreach (var item in lineItems)
{
await stripe.V1.InvoiceItems.CreateAsync(new InvoiceItemCreateOptions
{
Customer = customer.Id,
Invoice = invoice.Id,
Amount = item.Amount,
Currency = currency,
Description = item.Description,
});
}
var invoiceId = invoice.Id;1. Mark the invoice paid
Add the Maytes details to the invoice while it's still a draft, finalize it, then mark it paid outside Stripe. Stripe records that payment itself, so add your order's details to it too. They show in your Stripe Dashboard and help you match the payment to the Maytes checkout.
ts
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
// Add the Maytes details while it's still a draft
await stripe.invoices.update(invoiceId, {
custom_fields: [{ name: 'Paid with', value: 'Split with Maytes' }],
metadata: { maytes_checkout_uuid: checkoutUuid, order_id: orderId },
});
// Finalize it without letting Stripe send or charge it
await stripe.invoices.finalizeInvoice(invoiceId, { auto_advance: false });
// Mark it paid outside Stripe. Stripe records the payment
const paid = await stripe.invoices.pay(invoiceId, { paid_out_of_band: true, expand: ['payments'] });
// Find that payment record
const paymentRecordId = paid.payments!.data
.find((p) => p.payment.type === 'payment_record')!.payment.payment_record as string;
// Add your order's details to it
await stripe.paymentRecords.reportPaymentAttemptInformational(paymentRecordId, {
description: `Split with Maytes payment for ${orderId}`,
metadata: { maytes_checkout_uuid: checkoutUuid, order_id: orderId },
});python
import os
from stripe import StripeClient
stripe = StripeClient(os.environ["STRIPE_SECRET_KEY"])
# Add the Maytes details while it's still a draft
stripe.v1.invoices.update(invoice_id, {
"custom_fields": [{"name": "Paid with", "value": "Split with Maytes"}],
"metadata": {"maytes_checkout_uuid": checkout_uuid, "order_id": order_id},
})
# Finalize it without letting Stripe send or charge it
stripe.v1.invoices.finalize_invoice(invoice_id, {"auto_advance": False})
# Mark it paid outside Stripe. Stripe records the payment
paid = stripe.v1.invoices.pay(invoice_id, {"paid_out_of_band": True, "expand": ["payments"]})
# Find that payment record
payment_record_id = next(
p.payment.payment_record for p in paid.payments.data if p.payment.type == "payment_record"
)
# Add your order's details to it
stripe.v1.payment_records.report_payment_attempt_informational(payment_record_id, {
"description": f"Split with Maytes payment for {order_id}",
"metadata": {"maytes_checkout_uuid": checkout_uuid, "order_id": order_id},
})php
$stripe = new \Stripe\StripeClient(getenv('STRIPE_SECRET_KEY'));
// Add the Maytes details while it's still a draft
$stripe->invoices->update($invoiceId, [
'custom_fields' => [['name' => 'Paid with', 'value' => 'Split with Maytes']],
'metadata' => ['maytes_checkout_uuid' => $checkoutUuid, 'order_id' => $orderId],
]);
// Finalize it without letting Stripe send or charge it
$stripe->invoices->finalizeInvoice($invoiceId, ['auto_advance' => false]);
// Mark it paid outside Stripe. Stripe records the payment
$paid = $stripe->invoices->pay($invoiceId, ['paid_out_of_band' => true, 'expand' => ['payments']]);
// Find that payment record
foreach ($paid->payments->data as $p) {
if ($p->payment->type === 'payment_record') $paymentRecordId = $p->payment->payment_record;
}
// Add your order's details to it
$stripe->paymentRecords->reportPaymentAttemptInformational($paymentRecordId, [
'description' => "Split with Maytes payment for {$orderId}",
'metadata' => ['maytes_checkout_uuid' => $checkoutUuid, 'order_id' => $orderId],
]);go
sc := stripe.NewClient(os.Getenv("STRIPE_SECRET_KEY"))
// Add the Maytes details while it's still a draft
_, err := sc.V1Invoices.Update(ctx, invoiceId, &stripe.InvoiceUpdateParams{
CustomFields: []*stripe.InvoiceUpdateCustomFieldParams{
{Name: stripe.String("Paid with"), Value: stripe.String("Split with Maytes")},
},
Metadata: map[string]string{"maytes_checkout_uuid": checkoutUuid, "order_id": orderId},
})
if err != nil { /* handle */ }
// Finalize it without letting Stripe send or charge it
_, err = sc.V1Invoices.FinalizeInvoice(ctx, invoiceId, &stripe.InvoiceFinalizeInvoiceParams{
AutoAdvance: stripe.Bool(false),
})
if err != nil { /* handle */ }
// Mark it paid outside Stripe. Stripe records the payment
payParams := &stripe.InvoicePayParams{PaidOutOfBand: stripe.Bool(true)}
payParams.AddExpand("payments")
paid, err := sc.V1Invoices.Pay(ctx, invoiceId, payParams)
if err != nil { /* handle */ }
// Find that payment record
var paymentRecordID string
for _, p := range paid.Payments.Data {
if p.Payment.Type == "payment_record" {
paymentRecordID = p.Payment.PaymentRecord.ID
}
}
// Add your order's details to it
_, err = sc.V1PaymentRecords.ReportPaymentAttemptInformational(ctx, paymentRecordID,
&stripe.PaymentRecordReportPaymentAttemptInformationalParams{
Description: stripe.String("Split with Maytes payment for " + orderId),
Metadata: map[string]string{"maytes_checkout_uuid": checkoutUuid, "order_id": orderId},
})
if err != nil { /* handle */ }java
StripeClient stripe = new StripeClient(System.getenv("STRIPE_SECRET_KEY"));
// Add the Maytes details while it's still a draft
stripe.v1().invoices().update(invoiceId,
InvoiceUpdateParams.builder()
.addCustomField(InvoiceUpdateParams.CustomField.builder()
.setName("Paid with")
.setValue("Split with Maytes")
.build())
.putMetadata("maytes_checkout_uuid", checkoutUuid)
.putMetadata("order_id", orderId)
.build());
// Finalize it without letting Stripe send or charge it
stripe.v1().invoices().finalizeInvoice(invoiceId,
InvoiceFinalizeInvoiceParams.builder().setAutoAdvance(false).build());
// Mark it paid outside Stripe. Stripe records the payment
Invoice paid = stripe.v1().invoices().pay(invoiceId,
InvoicePayParams.builder().setPaidOutOfBand(true).addExpand("payments").build());
// Find that payment record
String paymentRecordId = paid.getPayments().getData().stream()
.filter(p -> "payment_record".equals(p.getPayment().getType()))
.findFirst().orElseThrow()
.getPayment().getPaymentRecord();
// Add your order's details to it
stripe.v1().paymentRecords().reportPaymentAttemptInformational(
paymentRecordId,
PaymentRecordReportPaymentAttemptInformationalParams.builder()
.setDescription("Split with Maytes payment for " + orderId)
.putMetadata("maytes_checkout_uuid", checkoutUuid)
.putMetadata("order_id", orderId)
.build());ruby
stripe = Stripe::StripeClient.new(ENV.fetch('STRIPE_SECRET_KEY'))
# Add the Maytes details while it's still a draft
stripe.v1.invoices.update(invoice_id, {
custom_fields: [{ name: 'Paid with', value: 'Split with Maytes' }],
metadata: { maytes_checkout_uuid: checkout_uuid, order_id: order_id },
})
# Finalize it without letting Stripe send or charge it
stripe.v1.invoices.finalize_invoice(invoice_id, { auto_advance: false })
# Mark it paid outside Stripe. Stripe records the payment
paid = stripe.v1.invoices.pay(invoice_id, { paid_out_of_band: true, expand: ['payments'] })
# Find that payment record
payment_record_id = paid.payments.data.find { |p| p.payment.type == 'payment_record' }.payment.payment_record
# Add your order's details to it
stripe.v1.payment_records.report_payment_attempt_informational(payment_record_id, {
description: "Split with Maytes payment for #{order_id}",
metadata: { maytes_checkout_uuid: checkout_uuid, order_id: order_id },
})csharp
var stripe = new StripeClient(Environment.GetEnvironmentVariable("STRIPE_SECRET_KEY"));
// Add the Maytes details while it's still a draft
await stripe.V1.Invoices.UpdateAsync(invoiceId, new InvoiceUpdateOptions
{
CustomFields = new List<InvoiceCustomFieldOptions>
{
new InvoiceCustomFieldOptions { Name = "Paid with", Value = "Split with Maytes" },
},
Metadata = new Dictionary<string, string>
{
["maytes_checkout_uuid"] = checkoutUuid,
["order_id"] = orderId,
},
});
// Finalize it without letting Stripe send or charge it
await stripe.V1.Invoices.FinalizeInvoiceAsync(invoiceId, new InvoiceFinalizeOptions
{
AutoAdvance = false,
});
// Mark it paid outside Stripe. Stripe records the payment
var paid = await stripe.V1.Invoices.PayAsync(invoiceId, new InvoicePayOptions
{
PaidOutOfBand = true,
Expand = new List<string> { "payments" },
});
// Find that payment record
var paymentRecordId = paid.Payments.Data.First(p => p.Payment.Type == "payment_record").Payment.PaymentRecordId;
// Add your order's details to it
await stripe.V1.PaymentRecords.ReportPaymentAttemptInformationalAsync(
paymentRecordId,
new PaymentRecordReportPaymentAttemptInformationalOptions
{
Description = $"Split with Maytes payment for {orderId}",
Metadata = new Dictionary<string, string>
{
["maytes_checkout_uuid"] = checkoutUuid,
["order_id"] = orderId,
},
});auto_advance: false keeps Stripe from sending or charging the invoice, even one set to charge your customer automatically. The invoice's total should match the captured amount, so the receipt matches what your customer paid.
Already finalized the invoice?
Skip the finalize call, and send only metadata in the update. Stripe doesn't let you add Paid with to a finalized invoice.
2. Show the receipt
When your customer views their order, link to the invoice's Stripe receipt page. It shows the receipt number, the amount paid and any refunds.
Get the link from the invoice's hosted_invoice_url, then ask Stripe for the receipt behind it.
ts
async function receiptUrl(invoiceId: string): Promise<string> {
const { hosted_invoice_url } = await stripe.invoices.retrieve(invoiceId);
// The hosted invoice URL ends in /{account_id}/{token}
const [, , accountId, token] = new URL(hosted_invoice_url!).pathname.split('/');
try {
// Swap the token for the receipt link, or fall back to the hosted page
const res = await fetch(`https://invoicedata.stripe.com/invoice_receipt_file_url/${accountId}/${token}`);
const { file_url } = await res.json();
return file_url.replace(/\/pdf$/, '');
} catch {
return hosted_invoice_url!;
}
}python
import json
import urllib.request
from urllib.parse import urlparse
def receipt_url(invoice_id):
hosted_invoice_url = stripe.v1.invoices.retrieve(invoice_id).hosted_invoice_url
# The hosted invoice URL ends in /{account_id}/{token}
_, _, account_id, token = urlparse(hosted_invoice_url).path.split("/")
try:
# Swap the token for the receipt link, or fall back to the hosted page
with urllib.request.urlopen(
f"https://invoicedata.stripe.com/invoice_receipt_file_url/{account_id}/{token}"
) as res:
return json.load(res)["file_url"].removesuffix("/pdf")
except Exception:
return hosted_invoice_urlphp
function receiptUrl(\Stripe\StripeClient $stripe, string $invoiceId): string
{
$hostedInvoiceUrl = $stripe->invoices->retrieve($invoiceId)->hosted_invoice_url;
// The hosted invoice URL ends in /{account_id}/{token}
[, , $accountId, $token] = explode('/', parse_url($hostedInvoiceUrl, PHP_URL_PATH));
// Swap the token for the receipt link, or fall back to the hosted page
$body = @file_get_contents("https://invoicedata.stripe.com/invoice_receipt_file_url/{$accountId}/{$token}");
$fileUrl = $body === false ? null : (json_decode($body, true)['file_url'] ?? null);
return $fileUrl === null ? $hostedInvoiceUrl : preg_replace('#/pdf$#', '', $fileUrl);
}go
func receiptURL(ctx context.Context, sc *stripe.Client, invoiceID string) (string, error) {
inv, err := sc.V1Invoices.Retrieve(ctx, invoiceID, nil)
if err != nil {
return "", err
}
u, err := url.Parse(inv.HostedInvoiceURL)
if err != nil {
return "", err
}
// The hosted invoice URL ends in /{account_id}/{token}
parts := strings.Split(u.Path, "/")
// Swap the token for the receipt link, or fall back to the hosted page
res, err := http.Get("https://invoicedata.stripe.com/invoice_receipt_file_url/" + parts[2] + "/" + parts[3])
if err != nil {
return inv.HostedInvoiceURL, nil
}
defer res.Body.Close()
var body struct {
FileURL string `json:"file_url"`
}
if json.NewDecoder(res.Body).Decode(&body) != nil || body.FileURL == "" {
return inv.HostedInvoiceURL, nil
}
return strings.TrimSuffix(body.FileURL, "/pdf"), nil
}java
static String receiptUrl(StripeClient stripe, String invoiceId) throws StripeException {
String hostedInvoiceUrl = stripe.v1().invoices().retrieve(invoiceId).getHostedInvoiceUrl();
// The hosted invoice URL ends in /{account_id}/{token}
String[] parts = URI.create(hostedInvoiceUrl).getPath().split("/");
try {
// Swap the token for the receipt link, or fall back to the hosted page
HttpResponse<String> res = HttpClient.newHttpClient().send(
HttpRequest.newBuilder(URI.create(
"https://invoicedata.stripe.com/invoice_receipt_file_url/" + parts[2] + "/" + parts[3])).build(),
HttpResponse.BodyHandlers.ofString());
Matcher m = Pattern.compile("\"file_url\"\\s*:\\s*\"([^\"]+)\"").matcher(res.body());
return m.find() ? m.group(1).replaceFirst("/pdf$", "") : hostedInvoiceUrl;
} catch (Exception e) {
return hostedInvoiceUrl;
}
}ruby
require 'json'
require 'net/http'
def receipt_url(stripe, invoice_id)
hosted_invoice_url = stripe.v1.invoices.retrieve(invoice_id).hosted_invoice_url
# The hosted invoice URL ends in /{account_id}/{token}
_, _, account_id, token = URI(hosted_invoice_url).path.split('/')
begin
# Swap the token for the receipt link, or fall back to the hosted page
body = Net::HTTP.get(URI("https://invoicedata.stripe.com/invoice_receipt_file_url/#{account_id}/#{token}"))
JSON.parse(body).fetch('file_url').delete_suffix('/pdf')
rescue StandardError
hosted_invoice_url
end
endcsharp
async Task<string> ReceiptUrlAsync(StripeClient stripe, string invoiceId)
{
var invoice = await stripe.V1.Invoices.GetAsync(invoiceId);
// The hosted invoice URL ends in /{account_id}/{token}
var parts = new Uri(invoice.HostedInvoiceUrl).AbsolutePath.Split('/');
try
{
// Swap the token for the receipt link, or fall back to the hosted page
using var http = new HttpClient();
var json = await http.GetStringAsync(
$"https://invoicedata.stripe.com/invoice_receipt_file_url/{parts[2]}/{parts[3]}");
var fileUrl = JsonDocument.Parse(json).RootElement.GetProperty("file_url").GetString()!;
return fileUrl.EndsWith("/pdf") ? fileUrl[..^4] : fileUrl;
}
catch (Exception)
{
return invoice.HostedInvoiceUrl;
}
}The link opens the receipt as a web page. Add /pdf to the end for a PDF.
Get the link each time your customer views their order rather than saving it. Stripe signs each link it returns, and hosted_invoice_url itself expires about 30 days after the invoice is finalized.
The receipt address isn't in Stripe's published API
invoicedata.stripe.com is what Stripe's own hosted invoice page uses for its Download receipt button. If the call fails, the code falls back to hosted_invoice_url, where your customer can still download the receipt.
Link the receipt, not the invoice PDF
invoice_pdf still shows the amount as due, with a Pay online link.
If you refund an order
Only needed when you refund an order. Stripe can't refund this invoice, so refund the order through Maytes refunds first. Once the refund is complete, record it on the invoice. The receipt then shows the refund.
| In the examples | Where it comes from |
|---|---|
invoiceId | Your Stripe invoice for the order |
refundAmount | The amount you refunded, in minor units. For a full refund, the order's full amount |
refundRef | A reference unique to this refund, such as your own refund ID. Use a new one for each refund |
currency | The same lowercase currency as the invoice |
Python and Ruby use invoice_id, refund_amount and refund_ref.
Find the payment Stripe recorded when you marked the invoice paid, report the refund on it, then add a credit note to the invoice.
ts
// Find the payment Stripe recorded for the invoice
const payments = await stripe.invoicePayments.list({
invoice: invoiceId,
payment: { type: 'payment_record' },
});
const paymentRecordId = payments.data[0].payment.payment_record as string;
// Report the refund on it
await stripe.paymentRecords.reportRefund(paymentRecordId, {
outcome: 'refunded',
amount: { value: refundAmount, currency },
refunded: { refunded_at: Math.floor(Date.now() / 1000) },
processor_details: { type: 'custom', custom: { refund_reference: refundRef } },
});
// Add a credit note so the receipt shows the refund
await stripe.creditNotes.create({
invoice: invoiceId,
amount: refundAmount,
refunds: [{
type: 'payment_record_refund',
amount_refunded: refundAmount,
payment_record_refund: { payment_record: paymentRecordId, refund_group: refundRef },
}],
});python
import time
# Find the payment Stripe recorded for the invoice
payments = stripe.v1.invoice_payments.list({
"invoice": invoice_id,
"payment": {"type": "payment_record"},
})
payment_record_id = payments.data[0].payment.payment_record
# Report the refund on it
stripe.v1.payment_records.report_refund(payment_record_id, {
"outcome": "refunded",
"amount": {"value": refund_amount, "currency": currency},
"refunded": {"refunded_at": int(time.time())},
"processor_details": {"type": "custom", "custom": {"refund_reference": refund_ref}},
})
# Add a credit note so the receipt shows the refund
stripe.v1.credit_notes.create({
"invoice": invoice_id,
"amount": refund_amount,
"refunds": [{
"type": "payment_record_refund",
"amount_refunded": refund_amount,
"payment_record_refund": {"payment_record": payment_record_id, "refund_group": refund_ref},
}],
})php
// Find the payment Stripe recorded for the invoice
$payments = $stripe->invoicePayments->all([
'invoice' => $invoiceId,
'payment' => ['type' => 'payment_record'],
]);
$paymentRecordId = $payments->data[0]->payment->payment_record;
// Report the refund on it
$stripe->paymentRecords->reportRefund($paymentRecordId, [
'outcome' => 'refunded',
'amount' => ['value' => $refundAmount, 'currency' => $currency],
'refunded' => ['refunded_at' => time()],
'processor_details' => ['type' => 'custom', 'custom' => ['refund_reference' => $refundRef]],
]);
// Add a credit note so the receipt shows the refund
$stripe->creditNotes->create([
'invoice' => $invoiceId,
'amount' => $refundAmount,
'refunds' => [[
'type' => 'payment_record_refund',
'amount_refunded' => $refundAmount,
'payment_record_refund' => ['payment_record' => $paymentRecordId, 'refund_group' => $refundRef],
]],
]);go
// Find the payment Stripe recorded for the invoice
var paymentRecordID string
for p, err := range sc.V1InvoicePayments.List(ctx, &stripe.InvoicePaymentListParams{
Invoice: stripe.String(invoiceId),
Payment: &stripe.InvoicePaymentListPaymentParams{Type: stripe.String("payment_record")},
}).All(ctx) {
if err != nil { /* handle */ }
paymentRecordID = p.Payment.PaymentRecord.ID
break
}
// Report the refund on it
_, err = sc.V1PaymentRecords.ReportRefund(ctx, paymentRecordID, &stripe.PaymentRecordReportRefundParams{
Outcome: stripe.String("refunded"),
Amount: &stripe.PaymentRecordReportRefundAmountParams{
Value: stripe.Int64(refundAmount),
Currency: stripe.String(currency),
},
Refunded: &stripe.PaymentRecordReportRefundRefundedParams{
RefundedAt: stripe.Int64(time.Now().Unix()),
},
ProcessorDetails: &stripe.PaymentRecordReportRefundProcessorDetailsParams{
Type: stripe.String("custom"),
Custom: &stripe.PaymentRecordReportRefundProcessorDetailsCustomParams{
RefundReference: stripe.String(refundRef),
},
},
})
if err != nil { /* handle */ }
// Add a credit note so the receipt shows the refund
_, err = sc.V1CreditNotes.Create(ctx, &stripe.CreditNoteCreateParams{
Invoice: stripe.String(invoiceId),
Amount: stripe.Int64(refundAmount),
Refunds: []*stripe.CreditNoteCreateRefundParams{{
Type: stripe.String("payment_record_refund"),
AmountRefunded: stripe.Int64(refundAmount),
PaymentRecordRefund: &stripe.CreditNoteCreateRefundPaymentRecordRefundParams{
PaymentRecord: stripe.String(paymentRecordID),
RefundGroup: stripe.String(refundRef),
},
}},
})
if err != nil { /* handle */ }java
// Find the payment Stripe recorded for the invoice
StripeCollection<InvoicePayment> payments = stripe.v1().invoicePayments().list(
InvoicePaymentListParams.builder()
.setInvoice(invoiceId)
.setPayment(InvoicePaymentListParams.Payment.builder()
.setType(InvoicePaymentListParams.Payment.Type.PAYMENT_RECORD)
.build())
.build());
String paymentRecordId = payments.getData().get(0).getPayment().getPaymentRecord();
// Report the refund on it
stripe.v1().paymentRecords().reportRefund(paymentRecordId,
PaymentRecordReportRefundParams.builder()
.setOutcome(PaymentRecordReportRefundParams.Outcome.REFUNDED)
.setAmount(PaymentRecordReportRefundParams.Amount.builder()
.setValue(refundAmount)
.setCurrency(currency)
.build())
.setRefunded(PaymentRecordReportRefundParams.Refunded.builder()
.setRefundedAt(Instant.now().getEpochSecond())
.build())
.setProcessorDetails(PaymentRecordReportRefundParams.ProcessorDetails.builder()
.setType(PaymentRecordReportRefundParams.ProcessorDetails.Type.CUSTOM)
.setCustom(PaymentRecordReportRefundParams.ProcessorDetails.Custom.builder()
.setRefundReference(refundRef)
.build())
.build())
.build());
// Add a credit note so the receipt shows the refund
stripe.v1().creditNotes().create(
CreditNoteCreateParams.builder()
.setInvoice(invoiceId)
.setAmount(refundAmount)
.addRefund(CreditNoteCreateParams.Refund.builder()
.setType(CreditNoteCreateParams.Refund.Type.PAYMENT_RECORD_REFUND)
.setAmountRefunded(refundAmount)
.setPaymentRecordRefund(CreditNoteCreateParams.Refund.PaymentRecordRefund.builder()
.setPaymentRecord(paymentRecordId)
.setRefundGroup(refundRef)
.build())
.build())
.build());ruby
# Find the payment Stripe recorded for the invoice
payments = stripe.v1.invoice_payments.list({
invoice: invoice_id,
payment: { type: 'payment_record' },
})
payment_record_id = payments.data[0].payment.payment_record
# Report the refund on it
stripe.v1.payment_records.report_refund(payment_record_id, {
outcome: 'refunded',
amount: { value: refund_amount, currency: currency },
refunded: { refunded_at: Time.now.to_i },
processor_details: { type: 'custom', custom: { refund_reference: refund_ref } },
})
# Add a credit note so the receipt shows the refund
stripe.v1.credit_notes.create({
invoice: invoice_id,
amount: refund_amount,
refunds: [{
type: 'payment_record_refund',
amount_refunded: refund_amount,
payment_record_refund: { payment_record: payment_record_id, refund_group: refund_ref },
}],
})csharp
// Find the payment Stripe recorded for the invoice
var payments = await stripe.V1.InvoicePayments.ListAsync(new InvoicePaymentListOptions
{
Invoice = invoiceId,
Payment = new InvoicePaymentPaymentOptions { Type = "payment_record" },
});
var paymentRecordId = payments.Data[0].Payment.PaymentRecordId;
// Report the refund on it
await stripe.V1.PaymentRecords.ReportRefundAsync(paymentRecordId, new PaymentRecordReportRefundOptions
{
Outcome = "refunded",
Amount = new PaymentRecordAmountOptions { Value = refundAmount, Currency = currency },
Refunded = new PaymentRecordRefundedOptions { RefundedAt = DateTime.UtcNow },
ProcessorDetails = new PaymentRecordProcessorDetailsOptions
{
Type = "custom",
Custom = new PaymentRecordProcessorDetailsCustomOptions { RefundReference = refundRef },
},
});
// Add a credit note so the receipt shows the refund
await stripe.V1.CreditNotes.CreateAsync(new CreditNoteCreateOptions
{
Invoice = invoiceId,
Amount = refundAmount,
Refunds = new List<CreditNoteRefundOptions>
{
new CreditNoteRefundOptions
{
Type = "payment_record_refund",
AmountRefunded = refundAmount,
PaymentRecordRefund = new CreditNoteRefundPaymentRecordRefundOptions
{
PaymentRecord = paymentRecordId,
RefundGroup = refundRef,
},
},
},
});For a partial refund, record each refund separately with its own amount and reference.
The receipt then lists the credit note and the adjusted total, such as A$0.00 after a full refund. The original payment stays in the receipt's payment history, because a refund isn't a new payment.
Good to know
- Mark each invoice paid once: capture returns
capturedagain if you call it again. Skip an invoice that's already paid. - Refunds go through Maytes: Stripe refunds nothing for this invoice. Use Maytes refunds, then record the refund.

