PHP code example of gatomontes / athmovil-php
1. Go to this page and download the library: Download gatomontes/athmovil-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/ */
gatomontes / athmovil-php example snippets
declare(strict_types=1);
use AthMovil\{Amount, Payment};
use AthMovil\Simulation\Simulator;
$simulation = new Simulator();
$client = $simulation->client();
$created = $client->createPayment(new Payment(
total: Amount::fromDecimal('25.00'),
phoneNumber: '7875550100',
metadata1: 'ORDER-1001',
metadata2: 'STORE-MANATI',
items: [
['name' => 'Coffee', 'description' => 'Ground coffee', 'quantity' => 2,
'price' => '8.00', 'tax' => null, 'metadata' => 'SKU-COFFEE'],
['name' => 'Mug', 'description' => 'Ceramic mug', 'quantity' => 1,
'price' => '9.00', 'tax' => null, 'metadata' => 'SKU-MUG'],
],
subtotal: Amount::fromDecimal('25.00'),
tax: Amount::fromDecimal('0.00'),
));
$simulation->confirmPayment($created->ecommerceId()); // Simulated customer action
$paid = $client->authorizePayment($created->authToken());
$refund = $client->refundPayment($paid->referenceNumber(), Amount::fromDecimal('5.00'));
echo $paid->metadata1(); // ORDER-1001
echo $refund->refund()['name']; // Test Payer
echo $simulation->exportHistory(); // Redacted requests, responses, state changes
use AthMovil\Simulation\{Simulator, FileStore};
$simulation = new Simulator(
businessId: 'store-one',
store: new FileStore('/private/local-development/athmovil'),
);
$client = $simulation->client();
use AthMovil\Simulation\{Fault, Operation};
$simulation->confirmPayment($id);
$simulation->cancelPayment($anotherId); // Customer cancellation
$simulation->expirePayment($thirdId);
$simulation->failNext(Operation::Authorize, Fault::Reject, 'BTRA_0005');
$simulation->failNext(Operation::Authorize, Fault::TimeoutBefore);
$simulation->failNext(Operation::Refund, Fault::TimeoutAfter);
use AthMovil\Simulation\{Simulator, FrozenClock};
$clock = new FrozenClock();
$simulation = new Simulator(clock: $clock, seed: 'repeatable-test');
$clock->advance(600);
$entries = $simulation->history();
$json = $simulation->exportHistory();
$simulation->reset();
use AthMovil\PaymentPoller;
$result = (new PaymentPoller($client))->waitForConfirmation(
$id, $authToken, maxAttempts: 10, intervalMilliseconds: 1000,
);
json
{
"repositories": [{"type": "vcs", "url": "https://github.com/gatomontes/athmovil-php"}],
"sh
git clone https://github.com/gatomontes/athmovil-php.git
cd athmovil-php
composer install
composer test
php examples/simulation.php