12-02-2016 01:51 PM
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']);
12-05-2016 10:31 AM
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("email@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: