$billto->setCompany("Tennis Shirts Are Us");
$billto->setAddress("588 Willis Court");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");
// Create additional payment data and add a new credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4007000000027");
$creditCard->setExpirationDate("2038-12");
$paymentTwo = new AnetAPI\PaymentType();
$paymentTwo->setCreditCard($creditCard);
$request = new AnetAPI\CreateCustomerPaymentProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setCustomerProfileId($customerProfileId);
$paymentprofile2 = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile2->setCustomerType('business');
$paymentprofile2->setBillTo($billto);
$paymentprofile2->setPayment($paymentTwo);
$paymentprofiles2[] = $paymentprofile2;
$request->setPaymentProfile($paymentprofile2);
$controller = new AnetController\CreateCustomerPaymentProfileController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    echo "CreateCustomerPaymentProfileRequest SUCCESS: PROFILE ID : " . $response->getCustomerPaymentProfileId() . "\n";
    $customerProfileId = $response->getCustomerPaymentProfileId();
} else {
    echo "CreateCustomerPaymentProfileRequest ERROR :  Invalid response\n";
}
$transactionRequestType = new AnetAPI\TransactionRequestType();
$billto->setLastName("Doe");
$billto->setCompany("My company");
$billto->setAddress("123 Main St.");
$billto->setCity("Bellevue");
$billto->setState("WA");
$billto->setZip("98004");
$billto->setPhoneNumber("000-000-0000");
$billto->setfaxNumber("999-999-9999");
$billto->setCountry("USA");
// Create a new Customer Payment Profile
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentCreditCard);
$paymentprofile->setTaxId("level2");
$paymentprofiles[] = $paymentprofile;
// Submit a CreateCustomerPaymentProfileRequest to create a new Customer Payment Profile
$paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
$paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);
$paymentprofilerequest->setCustomerProfileId($getcustomerprofileid);
$paymentprofilerequest->setPaymentProfile($paymentprofile);
$paymentprofilerequest->setValidationMode("liveMode");
$controller = new AnetController\CreateCustomerPaymentProfileController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    echo "Create Customer Payment Profile SUCCESS: " . "\n";
    $retrievedcustomerpaymentprofile = $response->getCustomerPaymentProfileId();
} else {
    echo "Create Customer Payment Profile: ERROR Invalid response\n";
    echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
}
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Mrs Mary");
$billto->setLastName("Doe");
$billto->setCompany("My company");
$billto->setAddress("123 Main St.");
$billto->setCity("Bellevue");
$billto->setState("WA");
$billto->setZip("98004");
$billto->setPhoneNumber("000-000-0000");
$billto->setfaxNumber("999-999-9999");
$billto->setCountry("USA");
// Create a new Customer Payment Profile
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentCreditCard);
$paymentprofiles[] = $paymentprofile;
// Submit a CreateCustomerPaymentProfileRequest to create a new Customer Payment Profile
$paymentprofilerequest = new AnetAPI\CreateCustomerPaymentProfileRequest();
$paymentprofilerequest->setMerchantAuthentication($merchantAuthentication);
$paymentprofilerequest->setCustomerProfileId($existingcustomerprofileid);
$paymentprofilerequest->setPaymentProfile($paymentprofile);
$paymentprofilerequest->setValidationMode("liveMode");
$controller = new AnetController\CreateCustomerPaymentProfileController($paymentprofilerequest);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null && $response->getMessages()->getResultCode() == "Ok") {
    echo "Create Customer Payment Profile SUCCESS: " . $response->getCustomerPaymentProfileId() . "\n";
} else {
    echo "Create Customer Payment Profile: ERROR Invalid response\n";
    echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . "  " . $response->getMessages()->getMessage()[0]->getText() . "\n";
}