1. Go to this page and download the library: Download academe/elavon-epg-psr7 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 / elavon-epg-psr7 example snippets
use Academe\Elavon\Epg\Psr7\Messages\Request\Transaction\CreateTransactionRequest;
use Academe\Elavon\Epg\Psr7\Messages\Response\Transaction\TransactionResponse;
use Academe\Elavon\Epg\Psr7\Support\ElavonApiFactory;
use GuzzleHttp\Client;
// 1. Configure the API factory (reusable for multiple requests)
$factory = ElavonApiFactory::configure()
->withRegion('eu') // 'eu' or 'us'
->withEnvironment('sandbox') // 'sandbox' or 'live'
->withAuthentication($merchantAlias, $apiSecret); // Your credentials
// 2. Create the transaction request
$request = CreateTransactionRequest::fromData([
'transaction' => [
'total' => [
'amount' => '99.99',
'currencyCode' => 'USD',
],
'card' => [
'number' => '4111111111111111',
'securityCode' => '123',
'expirationMonth' => 12,
'expirationYear' => 2025,
'holderName' => 'John Doe',
],
'description' => 'Order #12345',
],
]);
// 3. Build and apply API configuration
$psr7Request = $factory->apply($request->build());
// 4. Send with Guzzle (or any PSR-18 client)
$client = new Client();
$psr7Response = $client->sendRequest($psr7Request);
// 5. Parse the response
$response = TransactionResponse::fromPsr7Response($psr7Response);
if ($response->isSuccessful()) {
echo "Transaction ID: {$response->transaction->id}\n";
echo "State: {$response->transaction->state->value}\n";
} else {
echo "Error: {$response->error->getMessage()}\n";
}
use Academe\Elavon\Epg\Psr7\Dtos\Transaction;
$transaction = Transaction::fromData([
// Note: major units, but can also supply ['amountMinor' => 9999, ...]
'total' => ['amount' => '99.99', 'currencyCode' => 'USD'],
'card' => [
'number' => '4111111111111111',
'securityCode' => '123',
'expirationMonth' => 12,
'expirationYear' => 2025,
'holderName' => 'John Doe',
],
'description' => 'Order #12345',
]);
$request = new CreateTransactionRequest($transaction);
use Academe\Elavon\Epg\Psr7\Dtos\Transaction;
use Academe\Elavon\Epg\Psr7\Dtos\Card;
use Academe\Elavon\Epg\Psr7\Enums\Currency;
use Money\Money;
$transaction = new Transaction(
total: new Money('9999', Currency::USD), // Note: minor units
card: new Card(
number: '4111111111111111',
securityCode: '123',
expirationMonth: 12,
expirationYear: 2025,
holderName: 'John Doe',
),
description: 'Order #12345',
);
$request = new CreateTransactionRequest($transaction);
use Academe\Elavon\Epg\Psr7\Dtos\QueryParams;
use Academe\Elavon\Epg\Psr7\Messages\Request\Order\RetrieveOrderListRequest;
use Academe\Elavon\Epg\Psr7\Messages\Response\Order\OrderListResponse;
// First page with pagination
$queryParams = QueryParams::create()->withLimit(25);
$request = (new RetrieveOrderListRequest($queryParams))->build();
$request = $factory->apply($request);
$response = OrderListResponse::fromPsr7Response($client->sendRequest($request));
if ($response->isSuccessful()) {
foreach ($response->orders as $order) {
echo "Order: {$order->id} - {$order->description}\n";
}
// Fetch next page using the nextPageToken
if ($response->nextPageToken) {
$nextParams = QueryParams::create()
->withLimit(25)
->withPageToken($response->nextPageToken);
$nextRequest = (new RetrieveOrderListRequest($nextParams))->build();
// ...
}
}