Shell Python Node PHP C# Ruby

Voids and Refunds


Void a Payment

curl "https://api.payload.co/transactions/txn_3bW9JN4BVk3wU0ZZQs2Ay" \
    -u secret_key_3bW9JMZtPVDOfFNzwRdfE: \
    -X PUT \
    -d "status=voided"
payment = pl.Transaction.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')
payment.update(status='voided')
payment = Payload::Transaction.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')
payment.update(status: 'voided')
<?php
$payment = Payload\Transaction::get('txn_3bW9JN4BVk3wU0ZZQs2Ay');
$payment->update(array( 'status' => 'voided' ))
?>
pl.Transaction.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')
    .then(function(payment){
        return payment.update({ status: 'voided' })
    })
var payment = pl.Payment.get("txn_3bW9JN4BVk3wU0ZZQs2Ay");
payment.update(new { status="voided" });

To cancel a recent payment before it settles, update its status to voided using the PUT method (or update method if you're using the SDKs) on the transaction object. If a payment has already settled, you can initiate a refund instead.


Refund a Payment

curl "https://api.payload.co/transactions/" \
    -u secret_key_3bW9JMZtPVDOfFNzwRdfE: \
    -d "type=refund" \
    -d "amount=100" \
    -d "ledger[0][assoc_transaction_id]=txn_3bW9JN4BVk3wU0ZZQs2Ay"
payment = pl.Payment.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')

refund = pl.Refund.create(
    amount=payment.amount,
    ledger=[{
        'assoc_transaction_id': payment.id
    }]
)
payment = Payload::Payment.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')

refund = Payload::Refund.create(
    amount: payment.amount,
    ledger: [{
        'assoc_transaction_id' => payment.id
    }]
)
<?php
$payment = Payload\Transaction::get('txn_3bW9JN4BVk3wU0ZZQs2Ay');

$refund = Payload\Transaction::create(array(
    'type' => 'refund',
    'amount' => $payment->amount,
    'ledger' => array(array(
        'assoc_transaction_id' => $payment->id
    ))
));
?>
pl.Payment.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')
    .then(function(payment){
        return pl.Refund.create({
            amount: payment.amount,
            ledger: [{
                assoc_transaction_id: payment.id
            }]
        })
    })
var payment = pl.Payment.get("txn_3bW9JN4BVk3wU0ZZQs2Ay");

var refund = pl.Refund.create(new {
    amount=payment.amount,
    ledger=new[]{
        new pl.Ledger(new{ assoc_transaction_id=payment.id })
    }
});

// Or the short form
var refund = payment.refund();

To refund a payment, create a new refund transaction with a ledger entry setting the assoc_transaction_id to the original payment's id.


Partially Refund a Payment

curl "https://api.payload.co/transactions/" \
    -u secret_key_3bW9JMZtPVDOfFNzwRdfE: \
    -d "type=refund" \
    -d "amount=10" \
    -d "ledger[0][assoc_transaction_id]=txn_3bW9JN4BVk3wU0ZZQs2Ay"
payment = pl.Payment.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')

refund = pl.Refund.create(
    amount=10,
    ledger=[{
        'assoc_transaction_id': payment.id
    }]
)
payment = Payload::Payment.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')

refund = Payload::Refund.create(
    amount: 10,
    ledger: [{
        'assoc_transaction_id' => payment.id
    }]
)
<?php
$payment = Payload\Transaction::get('txn_3bW9JN4BVk3wU0ZZQs2Ay');

$refund = Payload\Transaction::create(array(
    'type' => 'refund',
    'amount' => 10,
    'ledger' => array(array(
        'assoc_transaction_id' => $payment->id
    ))
));
?>
pl.Payment.get('txn_3bW9JN4BVk3wU0ZZQs2Ay')
    .then(function(payment){
        return pl.Refund.create({
            amount: 10,
            ledger: [{
                assoc_transaction_id: payment.id
            }]
        })
    })
var payment = pl.Payment.get("txn_3bW9JN4BVk3wU0ZZQs2Ay");

var refund = pl.Refund.create(new {
    amount=10,
    ledger=new[]{
        new pl.Ledger(new{ assoc_transaction_id=payment.id })
    }
});

// Or the short form
var refund = payment.refund();

To refund only part of a payment, create a new refund transaction with a ledger entry setting the assoc_transaction_id to the original payment's id and set the amount attribute of the refund to the desired amount.