jstayfaded
jstayfaded

Reputation: 31

How do i get billing address into Authorize.net sdk for php?

I am trying to set up authorize.net's SDK for php and I am having trouble getting the billing address to work properly. I checked the sample on GitHub and I am able to get transactions to go through to my sandbox account but I don't know how to get the billing info to show up. Please keep in mind I am no php wiz so please don't assume things if there is a deeper explanation.

Here is the code...

<?php
require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");

// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("My api login");
$merchantAuthentication->setTransactionKey("my api key");

// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("6011000000000012");
$creditCard->setExpirationDate("2038-12");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);


// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType( "authCaptureTransaction"); 
$transactionRequestType->setAmount(9.51);
$transactionRequestType->setPayment($paymentOne);

//Billing Address
$billTo = new AnetAPI\billToType();
$billTo->setfirstName("Jordan");
$billTo->setlastName("Smith");
$billTo->setaddress("381 Indian Ave");
$billTo->setcity("Bridgeport");
$billTo->setstate("CT");
$billTo->setzip("06606");
$billTo->setcountry("USA");


$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransactionRequest( $transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);

if ($response != null)
{
    $tresponse = $response->getTransactionResponse();

    if (($tresponse != null) && ($tresponse->getResponseCode()=="1") )   
    {
        echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
        echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";
    }
    else
    {
        echo  "Charge Credit Card ERROR :  Invalid response\n";
    }
}
else
{
    echo  "Charge Credit card Null response returned";
}
?>

Thanks for any help.

Here is a picture of the transaction details...enter image description here

Upvotes: 0

Views: 833

Answers (0)

Related Questions