Skip to content


Andreas Kollaros edited this page May 28, 2014 · 7 revisions
Clone this wiki locally

Including the library



or if you are using composer


require 'vendor/autoload.php';

Setting up the gateway

use AktiveMerchant\Billing\Base; //Use Base class
use AktiveMerchant\Billing\MyGateway; //Use a gateway

Base::mode('test') // Remove this on production mode

$gateway = new MyGateway(array('login'=>'<password>', 'password'=>'<password>'));

Create a new instance of a gateway and add an array with credential options. According to gateway, credential options may vary. In this case MyGateway needs only login and password.

Setting up the CreditCard object

use AktiveMerchant\Billing\CreditCard;

$credit_card = new CreditCard( 
        "first_name" => "John",
        "last_name" => "Doe",
        "number" => "41111111111111",
        "month" => "12",
        "year" => "2012",
        "verification_value" => "123"

$credit_card->isValid(); // Returns true or false

Sending a transaction

# Extra options for transaction
$options = array(
    'order_id' => 'REF' . $gateway->generateUniqueId(),
    'description' => 'Test Transaction',
    'address' => array(
        'address1' => '1234 Street',
        'zip' => '98004',
        'state' => 'WA'

$amount = 100; #100 cents 1.00 dollars

# Authorize transaction
$response = $gateway->authorize($amount, $credit_card, $options);
if ( $response->success() ) {
    echo 'Success Authorize';
} else {
    echo $response->message();

$options array contains some information that needed from transaction. Options are not common for all gateways, although there are some common keys like address or billing_address, order_id etc.

Analyzing Response

Each transaction returns an AktiveMerchant\Billing\Response object. From this object you can get information about transaction status and details.

  • AktiveMerchant\Billing\Response::success() Returns true on success or false if not.
  • AktiveMerchant\Billing\Response::test() Returns true if gateway is in test mode or false if not.
  • AktiveMerchant\Billing\Response::fraud_review() Whether the request was flagged for fraud review.
  • AktiveMerchant\Billing\Response::authorization() Contains any information required to capture, refund, or void a transaction.
  • AktiveMerchant\Billing\Response::message() Human-readable message provided with the response.
  • AktiveMerchant\Billing\Response::avs_result() Address verification result.
  • AktiveMerchant\Billing\Response::cvv_result() Card verification value result.
  • AktiveMerchant\Billing\Response::params() All additional parameters available for this response
Something went wrong with that request. Please try again.