1. Go to this page and download the library: Download transact-pro/gw3-client 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/ */
transact-pro / gw3-client example snippets
use TransactPro\Gateway\Gateway;
use TransactPro\Gateway\Responses\Constants\Status;
$gw = new Gateway('<API BASE URL>/v3.0');
// Setup gateway authorization credentials
$gw->auth()
->setAccountGUID("3383e58e-9cde-4ffa-85cf-81cd25b2423e")
->setSecretKey('super-secret-key');
// Create transaction object
$sms = $gw->createSms();
// Set sRequest = $sms->build();
// Process transaction to gateway
$response = $gw->process($smsRequest);
// Parse Gateway response as a payment response
$paymentResponse = $sms->parseResponse($response);
if (!empty($paymentResponse->error)) {
throw new \RuntimeException("GW error: {$paymentResponse->error->message}");
}
// Redirect user to received URL
if ($paymentResponse->gw->statusCode === Status::CARD_FORM_URL_SENT) {
header("Location: {$paymentResponse->gw->redirectUrl}");
}
use TransactPro\Gateway\Gateway;
use TransactPro\Gateway\Responses\Constants\Status;
$gw = new Gateway('<API BASE URL>/v3.0');
// Setup gatewayl authorization credentials
$gw->auth()
->setAccountGUID("3383e58e-9cde-4ffa-85cf-81cd25b2423e")
->setSecretKey('super-secret-key');
// Create transaction object
$sms = $gw->createSms();
// Set way response as a payment response
$paymentResponse = $sms->parseResponse($response);
echo $paymentResponse->gw->statusCode === Status::SUCCESS ? "SUCCESS" : "FAILED";
use TransactPro\Gateway\Gateway;
$gw = new Gateway('<API BASE URL>/v3.0');
// first, you need to setup authorization.
// you can change authorization data in runtime.
// Thus, following operations will work under
// new authorization.
$gw->auth()
->setAccountGUID("3383e58e-9cde-4ffa-85cf-81cd25b2423e")
->setSecretKey('super-secret-key');
$operation = $gw->createOPERATION();
// here you setup your request through public methods
// that expose you blocks of information, that you can fill for the
// operation of your choice.
// build() will prepare `Request` object that `$gw` will use
// for the request.
$operationRequest = $operation->build();
// process() will perform provided request to the gateway
// `$response` will have response data (headers, body).
$response = $gw->process($operationRequest);
// parse received raw response to an appropriate class
$parsedResponse = $operation->parseResponse($response);
use TransactPro\Gateway\DataSets\Command;
// create a payment to init card verification process
$message->command()->setCardVerificationMode(Command::CARD_VERIFICATION_MODE_INIT);
// complete card verification
$operation = $gw->createCardVerification();
$operation->data()->setGatewayTransactionID($initialResponseGatewayTransactionId);
$operationRequest = $operation->build();
$response = $gw->process($request);
echo $response->getStatusCode() === 200 ? 'SUCCESS' : 'FAILURE';
// send a payment with flag to accept only verified cards
$message->command()->setCardVerificationMode(Command::CARD_VERIFICATION_MODE_VERIFY);
use TransactPro\Gateway\DataSets\Command;
// option 1: create a payment with flag to save payment data
$message->command()->setPaymentMethodDataSource(Command::DATA_SOURCE_SAVE_TO_GATEWAY);
// option 2: send "create token" request with payment data
$operation = $gw->createToken();
$operation->paymentMethod()
->setPAN('<card number>')
->setExpire('<card expiry>')
->setCardHolderName('<cardholder name>');
$operation->money()
->setCurrency('<desired currency>');
$operationRequest = $operation->build();
$response = $gw->process($request);
// send a payment in "token usage" mode with flag to load payment data by token
$message->useToken();
$message->command()
->setPaymentMethodDataSource(Command::DATA_SOURCE_USE_GATEWAY_SAVED_CARDHOLDER_INITIATED)
->setPaymentMethodDataToken('<initial gateway-transaction-id>');
$response = $gw->process($message);
$paymentResponse = $message->parseResponse($response);
if (
!empty($paymentResponse->error) &&
$paymentResponse->error->code === ErrorCode::EEC_ACQUIRER_SOFT_DECLINE &&
!empty($paymentResponse->gw->redirectUrl)
) {
header("Location: {$paymentResponse->gw->redirectUrl}");
}
use TransactPro\Gateway\Responses\GatewayResponse;
use TransactPro\Gateway\Responses\CallbackResult;
use TransactPro\Gateway\Http\Crypto\ResponseDigest;
// verify data digest
$responseDigest = new ResponseDigest($_POST['sign'] ?? '');
$responseDigest->setOriginalUri($paymentResponse->getDigest()->getUri()); // optional, set if available
$responseDigest->setOriginalCnonce($paymentResponse->getDigest()->getCnonce()); // optional, set if available
$responseDigest->setBody($_POST['json'] ?? '');
$responseDigest->verify("3383e58e-9cde-4ffa-85cf-81cd25b2423e", "super-secret-key");
// parse callback data as a payment response
$callbackResponse = GatewayResponse::createFromJSON($_POST['json'] ?? '', CallbackResult::class);
echo $callbackResponse->gw->statusText;
use TransactPro\Gateway\Interfaces\ResponseInterface;
// NB. Merchant GUID/secret must be used instead of account GUID/secret!
$gw->auth()
->setMerchantGUID('8D80-921D-BB99-45ED')
->setSecretKey('super-secret-key');
$message = $gw->createReport();
$message->filterData()
->setDtCreatedFrom(time() - 86400)
->setDtFinishedTo(time());
$request = $message->build();
$response = $gw->process($request);
// get raw body
$reportCSV = $response->getBody();
// get parsed body as iterator where each row is an associative array
// with keys from the first line and values are from all other lines
$csvResponse = $message->parseResponse($response);
print_r($csvResponse->getHeaders());
foreach ($csvResponse as $key => $value) {
print_r($value);
}
use TransactPro\Gateway\Gateway;
$gw = new Gateway('https://customurl.com');
use TransactPro\Gateway\Gateway;
$httpClient = new MyClient(); // implements HttpClientInterface
$gw = new Gateway('<API BASE URL>/v3.0');
$gw->setHttpClient($httpClient);
// use it!
// ...