File: /var/www/dev.captainschairit.com/wp-content/themes/captainschare/update-customer-profile.php
<?php
require 'vendor/autoload.php';
require_once 'constants/SampleCodeConstants.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
function updateCustomerProfile($customerProfileId, $customerPaymentProfileId, $email, $customer_id)
{
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCodeConstants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCodeConstants::MERCHANT_TRANSACTION_KEY);
// Set the transaction's refId
$refId = 'ref' . time();
// Get Current Profile
$request = new AnetAPI\GetCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setCustomerProfileId($customerProfileId);
$controller = new AnetController\GetCustomerProfileController($request);
// $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::PRODUCTION);
// echo '<pre>'; print_r($response->getProfile()->getMerchantCustomerId()); exit;
// Update an existing customer profile
$updatecustomerprofile = new AnetAPI\CustomerProfileExType();
$updatecustomerprofile->setCustomerProfileId($customerProfileId);
// $updatecustomerprofile->setDescription("Updated existing Profile Request");
$updatecustomerprofile->setEmail($email);
// $merchantCustomerId = 'M_'.time().rand(1,150);
$updatecustomerprofile->setMerchantCustomerId($customer_id);
// echo 'here'; exit;
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
// $paymentprofile->setBillTo($billto);
// $paymentprofile->setPayment($paymentCreditCard);
// $paymentprofiles[] = $paymentprofile;
$request_profile = new AnetAPI\UpdateCustomerProfileRequest();
$request_profile->setMerchantAuthentication($merchantAuthentication);
$request_profile->setProfile($updatecustomerprofile);
// $request = new AnetAPI\UpdateCustomerPaymentProfileRequest();
// $request->setMerchantAuthentication($merchantAuthentication);
// $request->setCustomerProfileId($customerProfileId);
// $request->setPaymentProfile( $paymentprofile );
// $request->setPaymentProfiles($paymentprofiles);
// echo 'here'; exit;
$controller = new AnetController\UpdateCustomerProfileController($request_profile);
// $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::PRODUCTION);
// echo '<pre>'; print_r($response); exit;
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
// echo "UpdateCustomerProfile SUCCESS : " . "\n";
// Validate the description and e-mail that was updated
$request = new AnetAPI\GetCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setCustomerProfileId($customerProfileId);
$controller = new AnetController\GetCustomerProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::PRODUCTION);
// $response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
}
else
{
// echo "ERROR : UpdateCustomerProfile: Invalid response\n";
$errorMessages = $response->getMessages()->getMessage();
// echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
// if(!defined('DONT_RUN_SAMPLES'))
// updateCustomerProfile();