Shell Python Node PHP C# Ruby

Pay an Invoice

curl -s "https://api.payload.co/transactions" \
    -u secret_key_3bW9JMZtPVDOfFNzwRdfE:\
    -X POST \
    -d "customer_id=acct_3bW9JND5iKnAlOYn9u82q" \
    -d "amount=100" \
    -d "type=payment" \
    -d "allocations[0][invoice_id]=inv_3bW9JND5iKnAlOYn9u82q"
invoice = pl.Invoice.get('inv_3bW9JND5iKnAlOYn9u82q')

if invoice.status != 'paid':
    payment = pl.Payment.create(
        amount=invoice.amount_due,
        customer_id=invoice.customer_id,
        allocations=[
            pl.PaymentItem( invoice_id=invoice.id )
        ]
    ))
invoice = Payload::Invoice.get('inv_3bW9JND5iKnAlOYn9u82q')

if invoice.status != 'paid'
    payment = Payload::Payment.create(
        amount: invoice.amount_due,
        customer_id: invoice.customer_id,
        allocations: [
            Payload::PaymentItem.new(
                invoice_id: invoice.id
            )
        ]
    )
end
<?php
$invoice = Payload\Invoice::get('inv_3bW9JND5iKnAlOYn9u82q');
$transaction = Payload\Transaction::get('inv_2bW9JND5an6AlOYn9ufx3');

if ( invoice.status != 'paid' ) {
    $payment = Payload\Transaction::create(array(
        'amount' => $invoice->amount_due,
        'customer_id' => $invoice->customer_id,
        'type' => 'payment',
        'payment_method_id' => $transaction->payment_method_id,
        'allocations' => array(
            Payload\LineItem::new(array(
                'invoice_id'=>$invoice->id,
                'entry_type' => 'payment'
            ))
        )
    ));
}
?>
pl.Invoice.get('inv_3bW9JND5iKnAlOYn9u82q')
    .then(function( invoice ){
        if ( invoice.status != 'paid' ) {
            pl.Payment.create({
                    amount: invoice.amount_due,
                    customer_id: invoice.customer_id,
                    allocations: [
                        new pl.PaymentItem({
                            invoice_id: invoice.id,
                        })
                    ]
                })
        }
    })
var invoice = pl.Invoice.get("inv_3bW9JND5iKnAlOYn9u82q");

if ( invoice.status != "paid" ) {
    var payment = pl.Payment.create(new {
        amount=invoice.amount_due,
        customer_id=invoice.customer_id,
        allocations=new[]{
            new pl.PaymentItem(new{
                invoice_id=invoice.id
            })
        }
    });
}

To pay an Invoice, create a payment object with an allocations array. Add a line_item where the type is payment and set the invoice_id to the desired invoice. This will allocate the transaction to the invoice, subtracting from any balance due on that invoice and adjusting the invoice status to paid or partially_paid.

Note: If no payment method is specified, the API will attempt the payment using the customer's default payment method if set.

Once a successful payment has been processed for an invoice there will be an additional line item on the invoice with an entry_type of payment. You will find a transaction_id value that references the payment. If there is no outstanding balance the invoice's status will update to paid.

Payload.js & mobile options

If you're using Checkout, you can pass the invoice_id to the checkout instance and it will automatically allocate any successful payments.

If you're using Secure inputs, you can create a hidden input with the attribute pl-input="invoice_id" and the set the value to the invoice id or pass it in as an attribute of the payment object when initializing the Payload.Form.


Send request for payment

To send a payment request for an invoice, see the Send a Payment Link section for further information.