<?php require 'vendor/autoload.php'; use net\authorize\api\contract\v1 as AnetAPI; use net\authorize\api\controller as AnetController; define("AUTHORIZENET_LOG_FILE", "phplog"); // Common setup for API credentials $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); $merchantAuthentication->setName("5KP3u95bQpv"); $merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S"); $refId = 'ref' . time(); //Set profile ids of profile to be updated $request = new AnetAPI\UpdateCustomerPaymentProfileRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setCustomerProfileId("36731856"); $controller = new AnetController\GetCustomerProfileController($request); // We're updating the billing address but everything has to be passed in an update // For card information you can pass exactly what comes back from an GetCustomerPaymentProfile // if you don't need to update that info $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("XXXX1111"); $creditCard->setExpirationDate("XXXX"); $paymentCreditCard = new AnetAPI\PaymentType(); $paymentCreditCard->setCreditCard($creditCard); // Create the Bill To info for new payment type $billto = new AnetAPI\CustomerAddressType(); $billto->setFirstName("Mrs Mary"); $billto->setLastName("Doe"); $billto->setAddress("1 New St."); $billto->setCity("Brand New City"); $billto->setState("WA");
$billto->setCompany("My company"); $billto->setAddress("588 Willis Ct"); $billto->setCity("Vacaville"); $billto->setState("CA"); $billto->setZip("95688"); $billto->setPhoneNumber("555-555-1212"); $billto->setfaxNumber("999-999-9999"); $billto->setCountry("USA"); // Create a new Customer Payment Profile $paymentprofile = new AnetAPI\CustomerPaymentProfileExType(); $paymentprofile->setCustomerType('individual'); $paymentprofile->setBillTo($billto); $paymentprofile->setPayment($paymentCreditCard); $paymentprofile->setCustomerPaymentProfileId($getcustomerprofileid); $paymentprofiles[] = $paymentprofile; // Submit a UpdatePaymentProfileRequest to update an existing create a new Customer Payment Profile $paymentprofilerequest = new AnetAPI\UpdateCustomerPaymentProfileRequest(); $paymentprofilerequest->setMerchantAuthentication($merchantAuthentication); $paymentprofilerequest->setCustomerProfileId($getcustomerprofileid); $paymentprofilerequest->setPaymentProfile($paymentprofile); $paymentprofilerequest->setRefId($refId); $paymentprofilerequest->setValidationMode("liveMode"); $controller = new AnetController\UpdateCustomerPaymentProfileController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null && $response->getMessages()->getResultCode() == "Ok") { echo "Update Customer Payment Profile SUCCESS: " . "\n"; $retrievedcustomerprofile = $response->getProfile(); } else { echo "Update Customer Payment Profile: ERROR Invalid response\n"; echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " . $response->getMessages()->getMessage()[0]->getText() . "\n"; }