soneritics/buckaroo

Buckaroo Payment Services implementation

1.0.0 2016-06-16 18:31 UTC

This package is auto-updated.

Last update: 2024-04-23 17:22:41 UTC


README

Buckaroo payment provider implementation classes

Example

You can see a working example of the code in the Soneritics/Buckaroo-Example repository.

Sneak preview of the code example :-)

TransactionRequest (Start of the payment)

$gateway = new \Buckaroo\Gateways\Test;
$transactionRequest = new \Buckaroo\ServiceOperations\TransactionRequest;
$buckaroo = new \Buckaroo\Buckaroo($gateway, $websiteKey, $secretKey);

$transactionRequest
    ->setCurrency(new \Buckaroo\Currency\EUR)
    ->setPaymentMethod(new \Buckaroo\PaymentMethods\iDeal)
    ->setAmount(12.5)
    ->setInvoiceNumber('Test-' . time())
    ->setReturnURL($returnURL)
    ->setCancelURL($returnURL)
    ->setRejectURL($returnURL)
    ->setErrorURL($returnURL);

$response = $buckaroo->performServiceOperation($transactionRequest);

try {
    $redirectURL = $response->getField('BRQ_REDIRECTURL');
    header("Location: {$redirectURL}");
} catch (Exception $ex) {
    echo 'ERROR: Something went wrong: ' . $ex->getMessage();
}

TransactionStatus (return page)

try {
    $transactionStatusResponse = new \Buckaroo\Response\TransactionStatusResponse($_POST, $secretKey);

    if ($transactionStatusResponse->getStatus() === \Buckaroo\Status::SUCCESS) {
        $order = $transactionStatusResponse->getInvoiceNumber();
        $currency = $transactionStatusResponse->getCurrency();
        $amount = $transactionStatusResponse->getAmount();
        echo "The order {$order} with amount {$currency} {$amount} has been paid.";
    } elseif ($transactionStatusResponse->getStatus() === \Buckaroo\Status::PENDING_PROCESSING) {
        $paymentCode = $transactionStatusResponse->getPaymentCode();
        echo "The order is pending. Fetch transaction details later for order with payment code {$paymentCode}.";
    } else {
        echo 'Order has not been paid for.';
    }
} catch (\Buckaroo\Exceptions\InvalidSignatureException $e) {
    echo 'Signature does not match, possible break in attempt.';
}