REST-example.php

Modified on Tue, 15 May, 2018 at 8:34 AM

<?php

/*

REST Developer Documentation:       https://www.forte.net/devdocs/api_resources/forte_api_v3.htm

Best Practices for Payment Forms:   https://www.forte.net/devdocs/reference/payment_forms.htm

Transaction Response Codes:         https://www.forte.net/devdocs/reference/response_codes.htm

Frequently Asked Questions:         https://www.forte.net/devdocs/reference/faq.htm

Forte Technical Support:

            7:00 am - 7:00 pm CST

            866.290.5400 option 5

            integration@forte.net


///////////////////////////////////////////////////////////// */


//$base_url        = 'https://api.forte.net/v3';             //production

$base_url          = 'https://sandbox.forte.net/api/v3';     //sandbox

$organization_id   = 'org_xxxxxx';

$location_id       = 'loc_xxxxxx';

$api_access_id     = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

$api_secure_key    = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

$auth_token        = base64_encode($api_access_id . ':' . $api_secure_key);

$endpoint          = $base_url . '/organizations/' . $organization_id . '/locations/' . $location_id . '/transactions';


//Address Info

$address = array(

'first_name' => 'Bill',

'last_name' => 'Customer'

);


//eCheck Info

$echeck = array(

'account_holder' => 'Bill G Customer',

'routing_number' => '123123123',

'account_number' => '123456789',

'account_type' => 'checking'

);


//Credit Card Info

$card = array(

'card_type' => 'VISA',

'name_on_card' => 'Bill G Customer',

'account_number' => '4111111111111111',

'expire_month' => '12',

'expire_year' => '2020',

'card_verification_value' => '123'

);


$params = array(

'action' => 'sale',             //sale, authorize, credit, void, capture, inquiry, verify, force, reverse

'card' => $card,                //change to 'echeck' => $echeck for an ACH transaction

'billing_address' => $address,

'authorization_amount' => 1.22,

'customer_token' => '',

'paymethod_token' => '',

'transaction_id' => '',

'original_transaction_id' => '',

'authorization_code' => ''

);


$ch = curl_init($endpoint);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_VERBOSE, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_TIMEOUT, 30);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');              //POST, GET, PUT or DELETE (Create, Read, Update or Delete)

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));   //disable this line for GETs and DELETEs

curl_setopt($ch, CURLOPT_HTTPHEADER, array(

'Authorization: Basic ' . $auth_token,

'X-Forte-Auth-Organization-id: ' . $organization_id,

'Accept:application/json',

'Content-type: application/json'

));


$response = curl_exec($ch);

$info = curl_getinfo($ch);

curl_close($ch);

$data = json_decode($response);


echo '<pre>';

print_r('HttpStatusCode: ' . $info['http_code'] . '<br><br>');

print_r($data);

echo '</pre>';

?>

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article