PHP code example of sauladam / omnipay-paysafecard-rest
1. Go to this page and download the library: Download sauladam/omnipay-paysafecard-rest 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/ */
sauladam / omnipay-paysafecard-rest example snippets
use Omnipay\Omnipay;
$gateway = Omnipay::create('Paysafecard_Rest');
$gateway->setApiKey('yourApiKey');
// Testmode is on by default, so you want to switch it off for production.
$gateway->setTestMode(false); // default: true
$response = $gateway->authorize([
'amount' => 0.01,
'currency' => 'EUR',
'success_url' => 'http://success.com/{payment_id}',
'failure_url' => 'http://fail.com/{payment_id}',
'notification_url' => 'http://notify.com/{payment_id}',
'customer_id' => 1234,
])->send();
if ($response->isSuccessful()) {
$paymentId = $response->getPaymentId();
// this is the url you should redirect the customer
// to or display within an iframe
$authUrl = $response->authUrl();
} else {
echo 'Something went wrong: ' . $response->getMessage();
}
if($response->getStatus() == 'AUTHORIZED')
{
// The customer has authorized the payment, we're now ready to capture it.
}
$response = $gateway->capture([
'payment_id' => $paymentId,
])->send();
if($response->getStatus() == 'SUCCESS') {
// You have successfully captured the payment, the order is ready to ship.
}
$validationResponse = $gateway->validateRefund([
// same data as above
])->send();
if(! $validationResponse->isSuccessful() || $validationResponse->getStatus() != 'VALIDATION_SUCCESSFUL') {
// something went wrong...
}
$refundResponse = $gateway->refund([
'payment_id' => $paymentId,
'refund_id' => $response->getRefundId(),
])->send();
if($refundResponse->isSuccessful()) {
echo "The refund was successful and the refund id is " . $refundResponse->getRefundId();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.