Skip to content

Instantly share code, notes, and snippets.

@amasses
Created July 26, 2012 00:17
Show Gist options
  • Save amasses/3179508 to your computer and use it in GitHub Desktop.
Save amasses/3179508 to your computer and use it in GitHub Desktop.
PHP token payments example
<?php
include_once("FatZebra.class.php");
define("FATZEBRA_USERNAME", "TEST");
define("FATZEBRA_TOKEN", "TEST");
define("FATZEBRA_GATEWAY", "gateway.sandbox.fatzebra.com.au"); // Live: gateway.fatzebra.com.au
define("FATZEBRA_TEST_MODE", true);
$gateway = new FatZebra\Gateway(FATZEBRA_USERNAME, FATZEBRA_TOKEN, FATZEBRA_TEST_MODE, FATZEBRA_GATEWAY); // The last option can be omitted to use the live gateway
$card_holder = "Mark Smith";
$card_number = "5123456789012346";
$expiry = "05/2013";
$cvv = "123";
$result = $gateway->tokenize($card_holder, $card_number, $expiry, $cvv);
if ($result->successful) {
echo "Card Tokenized - Card Token: " . $result->response->token;
// Store the token in your database...
} else {
// Error in data etc
echo "Errors Tokenizing Card: ";
foreach($result->errors as $error) {
echo " - " . $error . "\r\n";
}
}
?>
<?php
include_once("FatZebra.class.php");
define("FATZEBRA_USERNAME", "TEST");
define("FATZEBRA_TOKEN", "TEST");
define("FATZEBRA_GATEWAY", "gateway.sandbox.fatzebra.com.au"); // Live: gateway.fatzebra.com.au
define("FATZEBRA_TEST_MODE", true);
$gateway = new FatZebra\Gateway(FATZEBRA_USERNAME, FATZEBRA_TOKEN, FATZEBRA_TEST_MODE, FATZEBRA_GATEWAY); // The last option can be omitted to use the live gateway
$amount = 10.00;
$reference = "TEST" . rand(); // Unique reference
$token = "abc123"; // Get the token from your database here. Keep the token private, consider it to be like a credit card number
$cvv = "123"; // If possible use the CVV, however this can be blank/null - never store the CVV.
$result = $gateway->token_purchase($token, $amount, $reference, $cvv);
if ($result->successful && $result->response->successful) {
echo "Your transaction was successful. Authorization: " . $result->response->authorization . ", Transaction ID: . " $result->response->id;
} else if($result->successful) {
// Declined or otherwise
echo "Your transaction was not successful: " . $result->response->message);
} else {
// Error in data etc
echo "Errors processing transaction: ";
foreach($result->errors as $error) {
echo " - " . $error . "\r\n";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment