1. Go to this page and download the library: Download academe/omnipay-datatrans 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/ */
academe / omnipay-datatrans example snippets
$gateway = Omnipay::create('Datatrans');
$gateway->setMerchantId('{merchantId}');
$gateway->setSign('{sign}');
// Send purchase request. authorize() is also supported.
$response = $gateway->purchase([
'transactionId' => '{merchant-site-id}',
'amount' => '10.00',
'currency' => 'CHF',
])->send();
// This is a redirect gateway, so redirect right away.
// By default, this will be a POST redirect.
$response->redirect();
// Minimum data for the card is the expiry month and year.
$card = new \Omnipay\Common\CreditCard([
'expiryMonth' => $expiryMonth,
'expiryYear' => $expiryYear,
// The saved cardReference can be supplied here or later.
'number' => $cardReference,
]);
//$response = $xmlGateway->purchase([
$response = $xmlGateway->authorize([
'card' => $card,
// Supply the card reference here if not in the $card object:
'cardReference' => $cardReference,
'amount' => '20.00',
'currency' => 'EUR',
'transactionId' => $transactionId,
// The original payment method
'paymentMethod' => \Omnipay\Datatrans\Gateway::PAYMENT_PAYMENT_METHOD_VIS,
])->send();