cancel
Showing results for 
Search instead for 
Did you mean: 

Shipping Address not Passing when Creating Customer Using API with Official PHP Library

I am in need of your help. The issue I am having, is that I am passing a shipping address to your API when creating a customer account, but it is not appearing on the transaction for the customer in the dashboard. I am getting no errors.

I first create a customer account, using a token -- I pass to that the shipping and billing address and opaque data token. Then I charge the card. However, when I create the customer account and charge the card over the API, only the billing address is showing in the dashboard under the transaction. I cannot figure out what is wrong!

I have attached the code (in PHP), which works successfully in production with many customers (but still doesn’t pass the shipping address, even in production), and is pretty much one to one with the code for it on GitHub (using your own library example on GitHub). So your PHP library, your PHP code example. I also attached the request and response objects. You can see the shipping address clearly defined in the request object. And the response object returns “Successful”.

For example, here is the transaction that I create (got emailed to me, but same as in the dashboard). This is just the relevant snippet:

(NOTE: I have replaced sensitive information, with ******, in the examples below)

==== CUSTOMER BILLING INFORMATION ===

Customer ID :

First Name : ********

Last Name : ********

Company :

Address : ********

City : ********

State/Province : ********

Zip/Postal Code : ********

Country : ********

Phone : ********

Fax :

E-Mail : ********

 

==== CUSTOMER SHIPPING INFORMATION ===

First Name :

Last Name :

Company :

Address :

City :

State/Province :

Zip/Postal Code :

Country :

 

The code I am using, is below. I am setting the “Shipping To” address, with the $shippingProfiles variable. If I var_dump the variable, I get:

Array

(

    [0] => net\authorize\api\contract\v1\CustomerAddressType Object

        (

            [phoneNumber:net\authorize\api\contract\v1\CustomerAddressType:private] => ************

            [faxNumber:net\authorize\api\contract\v1\CustomerAddressType:private] =>

            [email:net\authorize\api\contract\v1\CustomerAddressType:private] =>

            [firstName:net\authorize\api\contract\v1\NameAndAddressType:private] => ************

            [lastName:net\authorize\api\contract\v1\NameAndAddressType:private] => ************

            [company:net\authorize\api\contract\v1\NameAndAddressType:private] =>

            [address:net\authorize\api\contract\v1\NameAndAddressType:private] => ************

            [city:net\authorize\api\contract\v1\NameAndAddressType:private] => Virginia Beach

            [state:net\authorize\api\contract\v1\NameAndAddressType:private] => VA

            [zip:net\authorize\api\contract\v1\NameAndAddressType:private] => 23452

            [country:net\authorize\api\contract\v1\NameAndAddressType:private] => US

        )

 

Now, here is the code:

 

public function createCustomer($token = null, $cardDetails = null) {

$tokens = explode("|", $token); // obtained with Accept.js
$dataDescriptor = $tokens[0];
$dataValue = $tokens[1];



/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName($this->accountConfig['api-login-id']);
$merchantAuthentication->setTransactionKey($this->accountConfig['api-key']);

// Set the transaction's refId
$refId = 'ref' . time();

// Create a Customer Profile Request
// 1. (Optionally) create a Payment Profile
// 2. (Optionally) create a Shipping Profile
// 3. Create a Customer Profile (or specify an existing profile)
// 4. Submit a CreateCustomerProfile Request
// 5. Validate Profile ID returned
// Set the payment data for the payment profile to a token obtained from Accept.js
$op = new AnetAPI\OpaqueDataType();
$op->setDataDescriptor($dataDescriptor);
$op->setDataValue($dataValue);
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setOpaqueData($op);

// Create the Bill To info for new payment type
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName($this->getCustomerFirstName());
$billto->setLastName($this->getCustomerLastName());
$billto->setAddress($this->getAddressLine1() . ' ' . $this->getAddressLine2());
$billto->setCity($this->getAddressCity());
$billto->setState($this->getAddressState());
$billto->setZip($this->getAddressZip());
$billto->setCountry($this->getAddressCountry());
$billto->setPhoneNumber($this->getCustomerPhone());

// Create the Ship To info for new payment type
$shipto = new AnetAPI\CustomerAddressType();
$shipto->setFirstName($this->getShippingFirstName());
$shipto->setLastName($this->getShippingLastName());
$shipto->setAddress($this->getShippingAddressLine1() . ' ' . $this->getShippingAddressLine2());
$shipto->setCity($this->getShippingCity());
$shipto->setState($this->getShippingState());
$shipto->setZip($this->getShippingZip());
$shipto->setCountry($this->getShippingCountry());
$shipto->setPhoneNumber($this->getCustomerPhone());

// Create an array of any shipping addresses
$shippingProfiles = [$shipto];

// Create a new Customer Payment Profile object
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentOne);
$paymentprofile->setDefaultPaymentProfile(true);
$paymentprofiles[] = $paymentprofile;

// Create a new CustomerProfileType and add the payment profile object
$customerprofile = new AnetAPI\CustomerProfileType();
$customerprofile->setDescription("Customer for {$this->getCustomerEmail()} on {$this->getWebsite()} for Order #{$this->getOrderNumber()}");
//$customerprofile->setMerchantCustomerId("M_".$this->getCustomerEmail()); // removed because it has a limit of 20 characters. It is not required anyway if setting the description and email.
$customerprofile->setEmail($this->getCustomerEmail());
$customerprofile->setPaymentProfiles($paymentprofiles);
$customerprofile->setShipToList($shippingProfiles);

// Assemble the complete transaction request
$request = new AnetAPI\CreateCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setProfile($customerprofile);

// Create the controller and get the response
$controller = new AnetController\CreateCustomerProfileController($request);
if ($this->accountConfig['sandbox-mode']) {

$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
} else {
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
}

if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
//echo "Successfully created customer profile : " . $response->getCustomerProfileId() . "\n";

$paymentProfiles = $response->getCustomerPaymentProfileIdList();
$this->logInfo("Created customer id {$response->getCustomerProfileId()} for {$this->getCustomerEmail()} on {$this->getWebsite()} for Order #{$this->getOrderNumber()}");


return $response->getCustomerProfileId() . '|' . $paymentProfiles[0];
//echo "SUCCESS: PAYMENT PROFILE ID : " . $paymentProfiles[0] . "\n";
} else {
//echo "ERROR : Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
//echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
$this->setError(['type' => 'create customer', 'msg' => "Authorize.NET create customer ERROR for {$this->getCustomerEmail()} on {$this->getWebsite()} for Order #{$this->getOrderNumber()}", 'number' => null], $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText(), $response);
return false;
}

}

 

So with the code, you can see I am creating a new CustomerProfileType, and calling setShipToList, and passing $shippingProfiles. The output of $shippingProfiles, is right above the code, above. So I am passing a valid object. I am then pasing the $custmerprofile to $request->setProfile(), and then calling the API. I get no errors, and I get back a Success Message.

Here is my $request object:

 

object(net\authorize\api\contract\v1\CreateCustomerProfileRequest)#1888 (5) {
["profile":"net\authorize\api\contract\v1\CreateCustomerProfileRequest":private]=>
object(net\authorize\api\contract\v1\CustomerProfileType)#1850 (6) {
["paymentProfiles":"net\authorize\api\contract\v1\CustomerProfileType":private]=>
array(1) {
[0]=>
object(net\authorize\api\contract\v1\CustomerPaymentProfileType)#1814 (6) {
["payment":"net\authorize\api\contract\v1\CustomerPaymentProfileType":private]=>
object(net\authorize\api\contract\v1\PaymentType)#1811 (8) {
["creditCard":"net\authorize\api\contract\v1\PaymentType":private]=>
NULL
["bankAccount":"net\authorize\api\contract\v1\PaymentType":private]=>
NULL
["trackData":"net\authorize\api\contract\v1\PaymentType":private]=>
NULL
["encryptedTrackData":"net\authorize\api\contract\v1\PaymentType":private]=>
NULL
["payPal":"net\authorize\api\contract\v1\PaymentType":private]=>
NULL
["opaqueData":"net\authorize\api\contract\v1\PaymentType":private]=>
object(net\authorize\api\contract\v1\OpaqueDataType)#1815 (4) {
["dataDescriptor":"net\authorize\api\contract\v1\OpaqueDataType":private]=>
string(27) "COMMON.ACCEPT.INAPP.PAYMENT"
["dataValue":"net\authorize\api\contract\v1\OpaqueDataType":private]=>
string(216) "**************************************************************************************************************************************************************************"
["dataKey":"net\authorize\api\contract\v1\OpaqueDataType":private]=>
NULL
["expirationTimeStamp":"net\authorize\api\contract\v1\OpaqueDataType":private]=>
NULL
}
["emv":"net\authorize\api\contract\v1\PaymentType":private]=>
NULL
["dataSource":"net\authorize\api\contract\v1\PaymentType":private]=>
NULL
}
["driversLicense":"net\authorize\api\contract\v1\CustomerPaymentProfileType":private]=>
NULL
["taxId":"net\authorize\api\contract\v1\CustomerPaymentProfileType":private]=>
NULL
["defaultPaymentProfile":"net\authorize\api\contract\v1\CustomerPaymentProfileType":private]=>
bool(true)
["customerType":"net\authorize\api\contract\v1\CustomerPaymentProfileBaseType":private]=>
string(10) "individual"
["billTo":"net\authorize\api\contract\v1\CustomerPaymentProfileBaseType":private]=>
object(net\authorize\api\contract\v1\CustomerAddressType)#1802 (11) {
["phoneNumber":"net\authorize\api\contract\v1\CustomerAddressType":private]=>
string(14) "(555) 555-5555"
["faxNumber":"net\authorize\api\contract\v1\CustomerAddressType":private]=>
NULL
["email":"net\authorize\api\contract\v1\CustomerAddressType":private]=>
NULL
["firstName":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(6) "*****"
["lastName":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(7) "*****"
["company":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
NULL
["address":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(24) "*****"
["city":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(13) "*****"
["state":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(2) "FL"
["zip":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(5) "33437"
["country":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(2) "US"
}
}
}
["shipToList":"net\authorize\api\contract\v1\CustomerProfileType":private]=>
array(1) {
[0]=>
object(net\authorize\api\contract\v1\CustomerAddressType)#1801 (11) {
["phoneNumber":"net\authorize\api\contract\v1\CustomerAddressType":private]=>
string(14) "(555) 555-5555"
["faxNumber":"net\authorize\api\contract\v1\CustomerAddressType":private]=>
NULL
["email":"net\authorize\api\contract\v1\CustomerAddressType":private]=>
NULL
["firstName":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(6) "*****"
["lastName":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(7) "*****"
["company":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
NULL
["address":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(29) "***** "
["city":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(14) "*****"
["state":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(2) "VA"
["zip":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(5) "23452"
["country":"net\authorize\api\contract\v1\NameAndAddressType":private]=>
string(2) "US"
}
}
["profileType":"net\authorize\api\contract\v1\CustomerProfileType":private]=>
NULL
["merchantCustomerId":"net\authorize\api\contract\v1\CustomerProfileBaseType":private]=>
NULL
["description":"net\authorize\api\contract\v1\CustomerProfileBaseType":private]=>
string(72) "Customer for *****@*****.com on *****.shop for Order #2548056"
["email":"net\authorize\api\contract\v1\CustomerProfileBaseType":private]=>
string(19) "*****@*****.com"
}
["validationMode":"net\authorize\api\contract\v1\CreateCustomerProfileRequest":private]=>
NULL
["merchantAuthentication":"net\authorize\api\contract\v1\ANetApiRequestType":private]=>
object(net\authorize\api\contract\v1\MerchantAuthenticationType)#1816 (9) {
["name":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
string(9) "*****"
["transactionKey":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
string(16) "*****"
["sessionToken":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
NULL
["password":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
NULL
["impersonationAuthentication":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
NULL
["fingerPrint":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
NULL
["clientKey":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
NULL
["accessToken":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
NULL
["mobileDeviceId":"net\authorize\api\contract\v1\MerchantAuthenticationType":private]=>
NULL
}
["clientId":"net\authorize\api\contract\v1\ANetApiRequestType":private]=>
string(13) "sdk-php-1.9.9"
["refId":"net\authorize\api\contract\v1\ANetApiRequestType":private]=>
string(13) "ref1683616545"
}

 

 

 

And here is my $response object:


object(net\authorize\api\contract\v1\CreateCustomerProfileResponse)#2081 (7) {
["customerProfileId":"net\authorize\api\contract\v1\CreateCustomerProfileResponse":private]=>
string(9) "911672929"
["customerPaymentProfileIdList":"net\authorize\api\contract\v1\CreateCustomerProfileResponse":private]=>
array(1) {
[0]=>
string(9) "911026658"
}
["customerShippingAddressIdList":"net\authorize\api\contract\v1\CreateCustomerProfileResponse":private]=>
array(1) {
[0]=>
string(9) "911715531"
}
["validationDirectResponseList":"net\authorize\api\contract\v1\CreateCustomerProfileResponse":private]=>
array(0) {
}
["refId":"net\authorize\api\contract\v1\ANetApiResponseType":private]=>
string(13) "ref1683616545"
["messages":"net\authorize\api\contract\v1\ANetApiResponseType":private]=>
object(net\authorize\api\contract\v1\MessagesType)#2077 (2) {
["resultCode":"net\authorize\api\contract\v1\MessagesType":private]=>
string(2) "Ok"
["message":"net\authorize\api\contract\v1\MessagesType":private]=>
array(1) {
[0]=>
object(net\authorize\api\contract\v1\MessagesType\MessageAType)#2093 (2) {
["code":"net\authorize\api\contract\v1\MessagesType\MessageAType":private]=>
string(6) "I00001"
["text":"net\authorize\api\contract\v1\MessagesType\MessageAType":private]=>
string(11) "Successful."
}
}
}
["sessionToken":"net\authorize\api\contract\v1\ANetApiResponseType":private]=>
NULL
}
array(1) {
[0]=>
object(net\authorize\api\contract\v1\MessagesType\MessageAType)#2093 (2) {
["code":"net\authorize\api\contract\v1\MessagesType\MessageAType":private]=>
string(6) "I00001"
["text":"net\authorize\api\contract\v1\MessagesType\MessageAType":private]=>
string(11) "Successful."
}
}

 

 

So I am at a loss. You can see the shipping address is in the $request, just before it is passed into

CreateCustomerProfileController

and the $response, shows it being successful.

 

I then go onto take the customer profile Id, and the paymentProfile, and use that to charge the card (that code isnt' included, but is straight forward). But after doing the charge, using the profile id and the payment profile, the shipping address is blank, both in the dashboard, and in the emails I receive from authorize.net. What is wrong here????

 

 

 

 

 

 

0 REPLIES 0