cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Updating a CIM payment profile CC expiration fails

I am trying to follow the PHP example found in https://github.com/AuthorizeNet/sample-code-php.git example update-customer-payment-profile.php to update an existing payment profile's credit card expiration but the example is not clear on how to do it. The best it says is: 

	  // For card information you can pass exactly what comes back from an GetCustomerPaymentProfile
	  // if you don't need to update that info

Since I need to modify the card information I thought it would be a simple case of doing a getCreditCard()->setExpirationDate() on the payment information returned from the getCustomerPaymentProfile(). The editing appears to work but I cannot add the payment back to a new customerPaymentProfile without failing. Here is my code snippet:

// getting the existing PaymentProfile
$request = new AnetAPI\GetCustomerPaymentProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication)
	->setRefId($refId)
	->setCustomerProfileId($cpid)
	->setCustomerPaymentProfileId($ppid);

$controller = new AnetController\GetCustomerPaymentProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
	$payment = $response->getPaymentProfile()->getPayment();
	$payment->getCreditCard()->setExpirationDate($expDate);
}
else {
    errorReturn($response);
}

$paymentprofile = new AnetAPI\CustomerPaymentProfileExType();
$paymentprofile->setCustomerPaymentProfileId($ppid)
	->setBillTo($billto)
	->setPayment($payment);

The format of the $expDate is 'MMYY'. When I remove the setPayment() -no problems. Any thoughts?

wdbaker54
Contributor
1 ACCEPTED SOLUTION

Accepted Solutions

Hi @wdbaker54,

 

The setPayment() function takes an instance of PaymentType, but what's returned by $response->getPaymentProfile()->getPayment(); is an instance of PaymentMaskedType. So, it's not quite as simple as getting the response and feeding it right back in. You'll probably have to be more explicit about it.

 

If you replaced your $controller section with the following, it should work:

$controller = new AnetController\GetCustomerPaymentProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
	  $payCard = new AnetAPI\CreditCardType();
	  $payCard->setCardNumber($response->getPaymentProfile()->getPayment()->getCreditCard()->getCardNumber());
	  $payCard->setExpirationDate($expDate);
	  $payment = new AnetAPI\PaymentType();
	  $payment->setCreditCard($payCard);

 

View solution in original post

Aaron
All Star
2 REPLIES 2

Hi @wdbaker54,

 

The setPayment() function takes an instance of PaymentType, but what's returned by $response->getPaymentProfile()->getPayment(); is an instance of PaymentMaskedType. So, it's not quite as simple as getting the response and feeding it right back in. You'll probably have to be more explicit about it.

 

If you replaced your $controller section with the following, it should work:

$controller = new AnetController\GetCustomerPaymentProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) {
	  $payCard = new AnetAPI\CreditCardType();
	  $payCard->setCardNumber($response->getPaymentProfile()->getPayment()->getCreditCard()->getCardNumber());
	  $payCard->setExpirationDate($expDate);
	  $payment = new AnetAPI\PaymentType();
	  $payment->setCreditCard($payCard);

 

Aaron
All Star

I appreciate the help, Aaron. I was chasing my tail something fierce and couldn't understand the documentation since PHP is something I picked up this last couple years and using the ANetAPI is something in the last month - still learning!