public static function CreateCustomerProfile(Payload $payload) { // Common setup for API credentials $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); $merchantAuthentication->setName(config('subscription.API_LOGIN_ID')); $merchantAuthentication->setTransactionKey(config('subscription.TRANSACTION_KEY')); $refId = 'ref' . time(); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber($payload->cardNumber); $creditCard->setExpirationDate($payload->expiryDate); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); // Create the Bill To info $billto = new AnetAPI\CustomerAddressType(); $billto->setFirstName($payload->firstName); $billto->setLastName($payload->lastName); $billto->setCompany($payload->company); $billto->setAddress($payload->address); $billto->setCity($payload->city); $billto->setState($payload->state); $billto->setZip($payload->zip); $billto->setCountry("USA"); // Create a Customer Profile Request // 1. create a Payment Profile // 2. create a Customer Profile // 3. Submit a CreateCustomerProfile Request // 4. Validate Profiiel ID returned $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentCreditCard); $paymentprofiles[] = $paymentprofile; $customerprofile = new AnetAPI\CustomerProfileType(); $customerprofile->setDescription($payload->description); $customerprofile->addToShipToList($billto); $merchantCustomerId = time() . rand(1, 150); $customerprofile->setMerchantCustomerId($merchantCustomerId); $customerprofile->setEmail($payload->email); $customerprofile->setPaymentProfiles($paymentprofiles); $request = new AnetAPI\CreateCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setProfile($customerprofile); $controller = new AnetController\CreateCustomerProfileController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null && $response->getMessages()->getResultCode() == "Ok") { return $response; } else { throw new PaymentErrorException($response->getMessages()->getMessage()[0]->getText()); } }
$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"); // Create a Customer Profile Request // 1. create a Payment Profile // 2. create a Customer Profile // 3. Submit a CreateCustomerProfile Request $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentCreditCard); $paymentprofiles[] = $paymentprofile; $customerprofile = new AnetAPI\CustomerProfileType(); $customerprofile->setDescription("Create Customer Profile Request Test for PHP"); $merchantCustomerId = time() . rand(1, 150); $customerprofile->setMerchantCustomerId($merchantCustomerId); $customerprofile->setEmail("*****@*****.**"); $customerprofile->setPaymentProfiles($paymentprofiles); $request = new AnetAPI\CreateCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setProfile($customerprofile); $controller = new AnetController\CreateCustomerProfileController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null && $response->getMessages()->getResultCode() == "Ok") { echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n";
$billto->setLastName("Johnson"); $billto->setCompany("Souveniropolis"); $billto->setAddress("14 Main Street"); $billto->setCity("Pecan Springs"); $billto->setState("TX"); $billto->setZip("44628"); $billto->setCountry("USA"); // Create a Customer Profile Request // 1. create a Customer Payment Profile // 2. create a Customer Profile // 3. Submit a CreateCustomerProfile Request // 4. Validate the profile id returned $paymentprofile = new AnetAPI\CustomerPaymentProfileType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentOne); $paymentprofiles[] = $paymentprofile; $customerprofile = new AnetAPI\CustomerProfileType(); $customerprofile->setDescription("Customer 2 Test PHP"); $merchantCustomerId = time() . rand(1, 150); $customerprofile->setMerchantCustomerId($merchantCustomerId); $customerprofile->setEmail("*****@*****.**"); $customerprofile->setPaymentProfiles($paymentprofiles); $request = new AnetAPI\CreateCustomerProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setRefId($refId); $request->setProfile($customerprofile); $controller = new AnetController\CreateCustomerProfileController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null && $response->getMessages()->getResultCode() == "Ok") { echo "CreateCustomerProfileRequest SUCCESS: PROFILE ID : " . $response->getCustomerProfileId() . "\n";