Order management
Refunds, captures and cancellations follow the same pattern as a payment: describe the request with PaymentMethodFactory, hand it to a service and call its action. Each service stores a new transaction and fires an event.
| Service | Action | Event |
|---|---|---|
RefundService | refund() | RefundTransactionCompleted |
CaptureService | capture() | CaptureTransactionCompleted |
CancelAuthorizeService | void() | VoidTransactionCompleted |
The services are in the Buckaroo\Laravel\Api namespace. Like pay(), each action returns the response and the stored transaction.
Refund a payment
use Buckaroo\Laravel\Api\RefundService;
use Buckaroo\Laravel\Handlers\PaymentMethodFactory;
[$response, $refund] = RefundService::make(
PaymentMethodFactory::make('ideal')->setPayload([
'invoice' => 'INV-1001', // invoice of the original payment
'originalTransactionKey' => $transaction->transaction_key, // the payment to refund
'amountCredit' => 10.00, // full or partial amount
'currency' => 'EUR',
])
)->refund();- For a partial refund, pass a lower
amountCredit - Use the same service code as the original payment. It is stored in
$transaction->payment_method - The refund is stored as its own transaction with a negative amount, linked to the payment
Whether and how long a payment can be refunded differs per payment method. See Refunds.
Authorize and capture
Some methods can reserve the amount first and collect it later, for example when the order ships. Call shouldAuthorize() to start an authorization in place of a payment:
use Buckaroo\Laravel\Api\CaptureService;
use Buckaroo\Laravel\Api\PayService;
use Buckaroo\Laravel\Handlers\PaymentMethodFactory;
[$response, $authorization] = PayService::make(
PaymentMethodFactory::make('creditcard')
->shouldAuthorize()
->setPayload([
'name' => 'visa',
'invoice' => 'INV-1003',
'amountDebit' => 50.00,
'currency' => 'EUR',
])
)->pay();
// Later, for example when the order ships
[$response, $capture] = CaptureService::make(
PaymentMethodFactory::make('creditcard')->setPayload([
'name' => 'visa',
'invoice' => 'INV-1003',
'originalTransactionKey' => $authorization->transaction_key,
'amountDebit' => 50.00,
'currency' => 'EUR',
])
)->capture();Which methods support authorize and capture is described under Order management in the PHP SDK documentation.
Cancel an authorization
An amount that is reserved but not yet collected is cancelled, not refunded:
use Buckaroo\Laravel\Api\CancelAuthorizeService;
[$response, $void] = CancelAuthorizeService::make(
PaymentMethodFactory::make('creditcard')->setPayload([
'name' => 'visa',
'invoice' => 'INV-1003',
'originalTransactionKey' => $authorization->transaction_key,
'amountCredit' => 50.00,
'currency' => 'EUR',
])
)->void();Work with stored transactions
Every payment, refund, capture and cancellation is a row in the buckaroo_transactions table. The model gives you scopes and relations to query them:
use Buckaroo\Laravel\Models\BuckarooTransaction;
// All transactions for an order
$transactions = BuckarooTransaction::where('order', 'ORD-1001')->get();
// Only successful ones
$paid = BuckarooTransaction::where('order', 'ORD-1001')->successfulTransactions()->get();
// The refunds of a payment
$refunds = $transaction->refunds;| Column | Contents |
|---|---|
transaction_key | The Buckaroo transaction key |
related_transaction_key | The transaction this one belongs to, such as the payment of a refund |
payment_method | The service code |
order, invoice | Your order and invoice number |
amount, currency | The amount, negative for a refund, and its currency |
status | open, pending, paid, failed or cancelled |
status_code, status_subcode, status_subcode_description | The original Buckaroo status |
service_action | The action, such as pay or refund, with a push/ or return/ prefix once that request is processed |
is_test | Whether it is a test transaction |
Look up a transaction at Buckaroo
To check a transaction at Buckaroo itself, use the PHP SDK through the facade:
use Buckaroo\Laravel\Facades\Buckaroo;
$status = Buckaroo::api()->transaction($transaction->transaction_key)->status();See Look up a transaction in the PHP SDK documentation.
Updated about 7 hours ago