cancel
Showing results for 
Search instead for 
Did you mean: 

Capture Customer Information using PHP

How do I capture other fields like "last name", "first name", and "email" so that they show up in the transaction details?  I am using php.  My form correctly passes the credit card number, expiration date, and amount.  What code can I use to pass other fields?

 

Here's mycode that is correctly passing the credit card information:

$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber($credit_card); 
$creditCard->setExpirationDate($_POST['expmonth'] . "-" . $_POST['expyear']);
$creditCard->setCardCode($_POST['securitycode']);



aaron0045
Member
2 REPLIES 2

Hi @aaron0045,

 

Sending other information is very similar to the way you're sending the card information. In addition to making a new CreditCardType(), you'd make an instance of one of the other classes, like CustomerDataType(), NameAndAddressType(), or CustomerAddressType(). If you want to see where all of these classes are defined, you can dig into the PHP SDK in vendor/authorizenet/authorizenet/lib/net/authorize/api/contract/v1.

 

In your case, you'd do something like this:

 

// Customer info 
$customer = new AnetAPI\CustomerDataType();
$customer->setEmail("foo@example.com");

// Bill To
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");

Then, add the following two lines to where you're building your $transactionRequestType object:

 

  $transactionRequestType->setCustomer($customer);
  $transactionRequestType->setBillTo($billto);

 

Aaron
All Star

Thanks for this!

 

This was very confusing at first because the CustomerAddressType provides a setEmail() method, but it doesn't seem to have any effect.