Skip to content
akDeveloper edited this page Feb 7, 2013 · 8 revisions

Including the library

<?php

require_once('path/to/autoload.php');

or if you are using composer

<?php

require 'vendor/autoload.php';

Setting up the gateway

<?php
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

<?php
use AktiveMerchant\Billing\CreditCard;

$credit_card = new CreditCard( 
    array(
        "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

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

# Authorize transaction
$response = $gateway->authorize('100', $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 foreach gateway, althought 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
Clone this wiki locally