PHP code example of worldstream-labs / omnipay-paysafecard

1. Go to this page and download the library: Download worldstream-labs/omnipay-paysafecard 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/ */

    

worldstream-labs / omnipay-paysafecard example snippets




mnipay\Omnipay;

$gateway = Omnipay::create('Paysafecard');
$gateway->setApiKey('yourApiKey');

// When deploying to production, don't forget to set test mode to false
$gateway->setTestMode(false);




mnipay\Omnipay;

$gateway = Omnipay::create('Paysafecard');
$gateway->setApiKey('yourApiKey');

$response = $gateway->authorize([
    'amount' => 10.00,
    'currency' => 'EUR',
    'success_url' => 'https://website/success/{payment_id}',
    'failure_url' => 'https://website/failure/{payment_id}',
    'notification_url' => 'https://website/notification/{payment_id}',
])->send();

if (!$response->isSuccessful()) {
    throw new \RuntimeException('Error with payment');
}

$paymentId = $response->getPaymentId(); // use this for the next call

redirect($response->getRedirectUrl());




$gateway = Omnipay::create('Paysafecard');
$gateway->setApiKey('yourApiKey');

$response = $gateway->fetchTransaction([
    'payment_id' = $paymentId
])->send();

if ($response->getStatus() === 'AUTHORIZED') {
    $captureResponse = $gateway->capture([
        'payment_id' = $paymentId
    ])->send();
}




$gateway = Omnipay::create('Paysafecard');
$gateway->setApiKey('yourApiKey');

$validationResponse = $gateway->validateRefund([
    'payment_id' => $paymentId,
    'amount' => 10.00,
    'currency' => 'EUR',
    'customer_email' => '[email protected]',
    'customer_id' => 1001,
])->send();

if (!$validationResponse->getStatus() != 'VALIDATION_SUCCESSFUL') {
    throw new \RuntimeException('Error with refund validation');
}

$refundResponse = $gateway->refund([
  'payment_id' => $paymentId,
  'refund_id' => $validationResponse->getRefundId(),
])->send();

if ($refundResponse->isSuccessful()) {
    // refund was successful
}




$gateway = Omnipay::create('Paysafecard');
$gateway->setApiKey('yourApiKey');

$refundResponse = $gateway->refund([
    'payment_id' => $paymentId,
    'amount' => 10.00,
    'currency' => 'EUR',
    'customer_email' => '[email protected]',
    'customer_id' => 1001,
])->send();

if ($refundResponse->isSuccessful()) {
    // refund was successful
}