Last active
March 30, 2016 22:31
-
-
Save incarnate/bfddd8fc31281bacb8d4 to your computer and use it in GitHub Desktop.
Examples of using eWAY's PHP SDK with logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Using the provided eWAY logger | |
// This logger logs to PHP's error log using error_log() | |
// Usually this will be in Apache's error log, but it will depend on your host. | |
$ewayLogger = new \Eway\Rapid\Service\Logger(); | |
$apiKey = '60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR'; | |
$apiPassword = 'API-P4ss'; | |
$apiEndpoint = \Eway\Rapid\Client::MODE_SANDBOX; | |
$client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint, $ewayLogger); | |
$transaction = [ | |
'Customer' => [ | |
'CardDetails' => [ | |
'Name' => 'John Smith', | |
'Number' => '4444333322221111', | |
'ExpiryMonth' => '12', | |
'ExpiryYear' => '25', | |
'CVN' => '123', | |
] | |
], | |
'Payment' => [ | |
'TotalAmount' => 1000, | |
], | |
'TransactionType' => \Eway\Rapid\Enum\TransactionType::PURCHASE, | |
]; | |
$response = $client->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction); | |
if (isset($response->TransactionStatus) && $response->TransactionStatus) { | |
echo 'Payment successful! ID: '.$response->TransactionID; | |
} else { | |
if ($response->getErrors()) { | |
foreach ($response->getErrors() as $error) { | |
echo "Error: $error (".\Eway\Rapid::getMessage($error).")<br>\n"; | |
} | |
} else { | |
echo 'Sorry, your payment was declined'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Using Monolog | |
// https://github.com/Seldaek/monolog | |
use Monolog\Logger; | |
use Monolog\Handler\StreamHandler; | |
// Create a logging instance writing to test.log | |
$logger = new Logger("testlog"); | |
$logger->pushHandler(new StreamHandler("test.log")); | |
$apiKey = '60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR'; | |
$apiPassword = 'API-P4ss'; | |
$apiEndpoint = 's4nydboX'; | |
$client = \Eway\Rapid::createClient($apiKey, $apiPassword, $apiEndpoint, $logger); | |
// Or add the logger later like so | |
// $client->setLogger($logger); | |
$transaction = [ | |
'Customer' => [ | |
'CardDetails' => [ | |
'Name' => 'John Smith', | |
'Number' => '4444333322221111', | |
'ExpiryMonth' => '12', | |
'ExpiryYear' => '25', | |
'CVN' => '123', | |
] | |
], | |
'Payment' => [ | |
'TotalAmount' => 1000, | |
], | |
'TransactionType' => \Eway\Rapid\Enum\TransactionType::PURCHASE, | |
]; | |
$response = $client->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction); | |
if (isset($response->TransactionStatus) && $response->TransactionStatus) { | |
echo 'Payment successful! ID: '.$response->TransactionID; | |
} else { | |
if ($response->getErrors()) { | |
foreach ($response->getErrors() as $error) { | |
echo "Error: $error (".\Eway\Rapid::getMessage($error).")<br>\n"; | |
} | |
} else { | |
echo 'Sorry, your payment was declined'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment