PHP code example of payrexx / omnipay-payrexx

1. Go to this page and download the library: Download payrexx/omnipay-payrexx library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

payrexx / omnipay-payrexx example snippets




use Omnipay\Omnipay;

$gateway = Omnipay::create('Payrexx');
$gateway->setApiKey('API_KEY'); // You find the API key in your Payrexx merchant backend
$gateway->setInstance('INSTANCE'); // That's your Payrexx instance name (INSTANCE.payrexx.com)

// Let's create a Payrexx gateway
$response = $gateway->purchase([
    'amount' => '100', // CHF 100.00
    'currency' => 'CHF',
    'psp' => 36, // Payrexx Direct
    'skipResultPage' => true,
    'successRedirectUrl' => 'https://www.merchant-website.com/success',
    'failedRedirectUrl' => 'https://www.merchant-website.com/failed',
])->send();

// A Payrexx gateway is always a redirect
if ($response->isRedirect()) {
    // Redirect URL to Payrexx gateway
    var_dump($response->getRedirectUrl());
    $response->redirect();
}

// That will be the Payrexx gateway ID
var_dump($response->getTransactionReference());

// Check if Payrexx gateway has been paid
$response = $gateway->completePurchase([
    'transactionReference' => $response->getTransactionReference(),
])->send();

// If Payrexx gateway has been paid, we will get a transaction reference (Payrexx transaction ID)
if ($response->getTransactionReference()) {
    // Optional: Fetch the corresponding transaction data => $response->getData()
    $response = $gateway->fetchTransaction([
        'transactionReference' => $response->getTransactionReference(),
    ])->send();

    // Let's refund CHF 50.00 (PSP has to support refunds => Payrexx Direct supports refunds)
    $response = $gateway->refund([
        'transactionReference' => $response->getTransactionReference(), // That's the Payrexx transaction ID as well
        'amount' => 50, // CHF 50.00
    ])->send();

    if ($response->isSuccessful()) {
        echo 'Refund was successful';
    }
}