PHP code example of easytransac / easytransac-sdk-php
1. Go to this page and download the library: Download easytransac/easytransac-sdk-php 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/ */
easytransac / easytransac-sdk-php example snippets
\EasyTransac\Core\Services::getInstance()->setEnvironment('sandbox');
\EasyTransac\Core\Services::getInstance()->provideAPIKey('YOUR_API_KEY_HERE');
\EasyTransac\Core\Services::getInstance()->setEnvironment('sandbox');
\EasyTransac\Core\Services::getInstance()->setDebug(true);
\EasyTransac\Core\Services::getInstance()->setRequestTimeout(30);
$customer = (new EasyTransac\Entities\Customer())
->setFirstname('Demo')
->setLastname('Mini SDK')
->setCity('Strasbourg')
->setUid('a1b2c3d4');
$card = (new EasyTransac\Entities\CreditCard())
->setNumber('1111111111111111')
->setMonth('10')
->setYear('2025')
->setCVV('123');
$transaction = (new EasyTransac\Entities\DirectTransaction())
->setAmount(100)
->setClientIp('127.0.0.1')
->setCustomer($customer)
->setCreditCard($card);
$request = new EasyTransac\Requests\DirectPayment();
$response = $request->execute($transaction);
if ($response->isSuccess()) {
$transactionItem = $response->getContent();
if ($transactionItem->getSecure()) {
echo $transactionItem->getSecureUrl();
} else {
var_dump($transactionItem->getStatus());
var_dump($transactionItem->getTid());
}
} else {
var_dump($response->getErrorMessage());
}
$response = \EasyTransac\Core\PaymentNotification::getContent($_POST, $myApiKey);
var_dump($response->toArray());
var_dump($response->getStatus());
var_dump($_POST);
$request = new EasyTransac\Requests\DirectPayment();
$response = $request->execute($transaction);
var_dump($response->getRealJsonResponse());
var_dump($response->getRealArrayResponse());
use EasyTransac\Core\Services;
use EasyTransac\Entities\Customer;
use EasyTransac\Entities\DropinSessionTransaction;
use EasyTransac\Requests\DropinSession;
Services::getInstance()
->provideAPIKey('your_api_key')
->setEnvironment(Services::ENV_SANDBOX);
$customer = (new Customer())
->setFirstname('John')
->setLastname('Doe')
->setEmail('[email protected] ');
$transaction = (new DropinSessionTransaction())
->setOrderId('ORDER-123')
->setAmount(1000)
->setDescription('Drop-in test order')
->setLanguage('FRE')
->setReturnUrl('https://merchant.test/return')
->setCancelUrl('https://merchant.test/cancel')
->setNotificationUrl('https://merchant.test/notify')
->setProviders(['applepay', 'googlepay'])
->setCustomer($customer);
$response = (new DropinSession())->execute($transaction);
if (!$response->isSuccess()) {
var_dump($response->getErrorCode(), $response->getErrorMessage());
exit(1);
}
$session = $response->getContent();
var_dump([
'token' => $session->getToken(),
'request_id' => $session->getRequestId(),
'status' => $session->getStatus(),
]);
bash
composer json
{
"ransac/easytransac-sdk-php": "*"
}
}