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.

ServiceActionEvent
RefundServicerefund()RefundTransactionCompleted
CaptureServicecapture()CaptureTransactionCompleted
CancelAuthorizeServicevoid()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;
ColumnContents
transaction_keyThe Buckaroo transaction key
related_transaction_keyThe transaction this one belongs to, such as the payment of a refund
payment_methodThe service code
order, invoiceYour order and invoice number
amount, currencyThe amount, negative for a refund, and its currency
statusopen, pending, paid, failed or cancelled
status_code, status_subcode, status_subcode_descriptionThe original Buckaroo status
service_actionThe action, such as pay or refund, with a push/ or return/ prefix once that request is processed
is_testWhether 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.



Did this page help you?