1. Go to this page and download the library: Download karser/payum-saferpay 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/ */
karser / payum-saferpay example snippets
//config.php
use Payum\Core\GatewayFactoryInterface;
use Payum\Core\PayumBuilder;
use Payum\Core\Payum;
use Karser\PayumSaferpay\SaferpayGatewayFactory;
/** @var Payum $payum */
$payum = (new PayumBuilder())
->addDefaultStorages()
->addGatewayFactory('saferpay', static function(array $config, GatewayFactoryInterface $coreGatewayFactory) {
return new SaferpayGatewayFactory($config, $coreGatewayFactory);
})
->addGateway('saferpay', [
'factory' => 'saferpay',
# this is test credentials
'username' => 'API_401860_80003225',
'password' => 'C-y*bv8346Ze5-T8',
'customerId' => '401860',
'terminalId' => '17795278',
'interface' => 'TRANSACTION', #optionally, can be defined via details too
'sandbox' => true,
])
->getPayum()
;
//capture.php
use App\Entity\Payment;
use Payum\Core\Payum;
use Payum\Core\Request\Capture;
use Karser\PayumSaferpay\Constants;
/** @var Payum $payum */
$storage = $payum->getStorage(Payment::class);
$payment = $storage->create();
$payment->setNumber(uniqid());
$payment->setCurrencyCode('USD');
$payment->setTotalAmount(123); //$1.23 USD
$payment->setDescription('test payment');
// capture using TRANSACTION interface (default)
$payment->setDetails(['Interface' => Constants::INTERFACE_TRANSACTION]);
// or capture using PAYMENT_PAGE interface
$payment->setDetails(['Interface' => Constants::INTERFACE_PAYMENT_PAGE]);
$storage->update($payment);
$token = $payum->getTokenFactory()->createCaptureToken('saferpay', $payment, 'done.php');
$captureRequest = new Capture($token);
$captureRequest->setModel($payment);
$reply = $this->gateway->execute($captureRequest, true);
//then redirect user to $reply->getUrl();
//done.php
use App\Entity\Payment;
use Payum\Core\Payum;
use Payum\Core\Request\GetHumanStatus;
/** @var Payum $payum */
$token = $payum->getHttpRequestVerifier()->verify($_GET);
$this->payum->getHttpRequestVerifier()->invalidate($token);
$payment = $payum->getStorage(Payment::class)->find($token);
$this->assertStatus(GetHumanStatus::STATUS_CAPTURED, $payment);
$this->gateway->execute($status = new GetHumanStatus($payment));
//status of the payment is in $status->getValue()
use Karser\PayumSaferpay\Constants;
$payment = $storage->create();
$payment->setDetails(['Payment' => ['Recurring' => ['Initial' => true]]]);
//or
$payment->setDetails(['Payment' => ['Installment' => ['Initial' => true]]]);
//then capture the payment
$captureRequest = new Capture($token);
$captureRequest->setModel($payment);
$reply = $this->gateway->execute($captureRequest, true);
//then redirect user to $reply->getUrl();