API Example Payment Credit Card
From InClickAdServer
Funding an Advertiser Account with a Credit Card (Gateway)
This API Service Request will fund an Advertiser account using the credit card gateway system. This API Service Request can also be used to setup the account for Automatic Billing.
The Code Example
<?php require_once "../globals/globals.php"; require_once INCLICK_CORE_DIR . "/external/classes/accounting/IMG_AccountingManagerClient.php"; require_once INCLICK_CORE_DIR . "/external/classes/accounting/IMG_CreditCard.php"; //THE BASE URL OF YOUR AD SERVER DEPLOYMENT $base_url = INCLICK_WEB_URL; //THE SERVICE KEY TO ACCESS THE API $service_key = "YOUR_API_SERVICE_KEY"; //INSTANTIATE THE API CLIENT $accounting_manager = new IMG_AccountingManagerClient($base_url, $service_key); $credit_card = new IMG_CreditCard(); //SET THE PAYMENT DATA $credit_card->setCardNumber("5424000000000015"); $credit_card->setCardVerificationNumber('524'); $credit_card->setExpirationMonth('12'); $credit_card->setExpirationYear('10'); $advertiser_id = 1001; $save_for_rebilling = false; $first_time_deposit = false; $amount = "25.02"; $promotional_code = ""; $result = $accounting_manager->processAdvertiserCreditCardPayment($advertiser_id, $amount, $credit_card, $save_for_rebilling, $first_time_deposit, $promotional_code); if($result->succeeded() == 1) { $card_result = $result->getReturnValue(); } else { } ?>
Breaking it Down
require "../globals/globals.php";
This require references the local inClick Ad Server deployment configuration files allowing your code to utilize the pre-packaged API Objects as well as the bundled PHPOlait services.
require_once INCLICK_CORE_DIR . "/external/classes/accounting/IMG_AccountingManagerClient.php"; require_once INCLICK_CORE_DIR . "/external/classes/accounting/IMG_CreditCard.php";
These requires (includes) contain the API Objects and Classes needed for this API Service Request.
$base_url = INCLICK_WEB_URL; $service_key = "YOUR_API_SERVICE_KEY";
The $base_url is the URL to your inClick Ad Server deployment, the ad server root URL. For local host API usage, the constant of INCLICK_WEB_URL is defined in the globals.php file referenced earlier. Remote deployments, deployments where the ad server and API Request Location are not on the same server, would change this to the fully qualified URL to the ad server root directory.
The $service_key is one of the the api_service_keys values you created for your ad server. (more information)
$accounting_manager = new IMG_AccountingManagerClient($base_url, $service_key); $credit_card = new IMG_CreditCard();<php> This is where we create the instance of the classes needed to fund an account using the credit card gateway. ---- <php>$credit_card->setCardNumber("5424000000000015"); $credit_card->setCardVerificationNumber('524'); $credit_card->setExpirationMonth('12'); $credit_card->setExpirationYear('10');
Here we set the value for each credit card object.
$advertiser_id = 1001; $save_for_rebilling = false; $first_time_deposit = false; $amount = "25.02"; $promotional_code = "";
Here we set the additional values to complete the transaction.
- TIP: When performing test transactions, be sure to use the House Advertiser account, 1001. Credits posted to the House Advertiser account will not count towards your inClick.net account.
$result = $accounting_manager->processAdvertiserCreditCardPayment($advertiser_id, $amount, $credit_card, $save_for_rebilling, $first_time_deposit, $promotional_code);
With all required parameters set, we process the API Service Reqeuest.
if($result->succeeded() == 1){ $card_result = $result->getReturnValue(); echo "Charge Success - Message: " . $card_result->getErrorString(); } else { echo "Charge Failed - Message: " .$result->getErrorMessage(); }
This section of code is provided to give you a visual confirmation of what occurred.
