Reply
Highlighted
Member
Posts: 3
Registered: ‎10-20-2011

testMode vs liveMode for Update Payment Profile

I'm trying to understand something, my code for an "updateCustomerPaymentProfileRequest" works in testMode but not in liveMode.  I am using a testing account.  What confuses me, is that when I send a "createCustomerProfileRequest", which conatins payment information.

 

I am sending nearly identcial information.  (The differences being, that I am not sending an email address, or merchantCustomerId when updating.)  I am using a testing account, and testing credit cards.

 

Does anyone know what's causing this?

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: testMode vs liveMode for Update Payment Profile

If you're using test mode on a production account, as opposed to live mode on a sandbox account, my advice would be to geta a sandbox account and use live mode. It'll be much more like production. As for the specific problem you're having, it could be all sorts of different things, and there's no way to tell without knowing what the error is. Please post your code (in a code box, 5th icon from the left in Rich Text mode) and also the full response (edited, of course, to remove anything you want to keep private). If using PHP:

 

$response = updateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $paymentProfile, $validationMode);

print_r($response);

 If working directly with the XML, just paste the XML response - again, in a code box.

Highlighted
Member
Posts: 3
Registered: ‎10-20-2011

Re: testMode vs liveMode for Update Payment Profile

Thanks TJ,  I've actually been using the XML method, so if I should be doing it some other way let me know.  The error I'm getting is: "[E00027] There is one or more missing or invalid required fields."  My code is:

	$updateInfo = 
		"<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
		"<updateCustomerPaymentProfileRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" .
			MerchantAuthenticationBlock().
			"<customerProfileId>$anetProfileID</customerProfileId>".
			"<paymentProfile>".
				"<billTo>".
					"<firstName>$firstName</firstName>".
					"<lastName>$lastName</lastName>".
					"<zip>$ZIP</zip>".
				"</billTo>".
				"<payment>".
				 "<creditCard>".
					  "<cardNumber>$CCNumber</cardNumber>".
					  "<expirationDate>$expiration</expirationDate>". // required format for API is YYYY-MM
				 "</creditCard>".
				"</payment>".
			"<customerPaymentProfileId>$paymentID</customerPaymentProfileId>".
			"</paymentProfile>".
			"<validationMode>liveMode</validationMode>".
		"</updateCustomerPaymentProfileRequest>";

	$updateResponse = send_xml_request($updateInfo);
	$updateParsed = parse_api_response($updateResponse);
	
	if ("Ok" == $updateParsed->messages->resultCode) {
		echo "customerProfileId <b>"
			. htmlspecialchars($updateParsed->customerProfileId)
			. "</b> was successfully updated.<br><br>";
	}
	else	{
		echo $updateParsed;
	}

All of those variables are properly set, and they get set properly in the customer profile when using testmode.  The only thing that I change is <validationMode>liveMode</validationMode> to <validationMode>testMode</validationMode>.

 

I am using a sandbox account, if that makes a diference.  So are there additional required fields for liveMode or something?

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: testMode vs liveMode for Update Payment Profile

I don't see anything wrong with the XML, assuming the parts I can't see are formulated properly. However, there could be something in the data that's causing the XML to flake out. Can you post your XML with all values inserted? Just slightly edit the parts you don't want us to see.

 

In general, incidently, it's easier to use the PHP API layered on top of the XML. This is a few lines of code from the CIM.markdown file in the doc folder of the PHP SDK:

 

$paymentProfile = new AuthorizeNetPaymentProfile;

$paymentProfile->customerType = "individual"; $paymentProfile->payment->creditCard->cardNumber = "4111111111111111"; $paymentProfile->payment->creditCard->expirationDate = "2017-11";
$response = $request->updateCustomerPaymentProfile($customerProfileId, $paymentProfileId, $paymentProfile);

 And if you're going to do XML, at least use a PHP block. It's so much easier:

 

print <<<BLOCK
<?xml version="1.0" encoding="utf-8"?> 
<updateCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"> 
  <merchantAuthentication> 
    <name>{$GLOBALS['_authorize_id']}</name> 
    <transactionKey>{$GLOBALS['_authorize_key']}</transactionKey> 
  </merchantAuthentication> 
  <customerProfileId>{$data['profile']}</customerProfileId> 
  <paymentProfile> 
    <billTo> 
      <firstName>{$data['first']}</firstName> 
      <lastName>{$data['first']}</lastName> 
      <company>{$data['company']}</company> 
      <address>{$data['address']}</address> 
      <city>{$data['city']}</city> 
      <state>{$data['state']}</state> 
      <zip>{$data['zip']}</zip> 
      <country>{$data['country']}</country> 
      <phoneNumber>{$data['phone']}</phoneNumber> 
      <faxNumber>{$data['fax']}</faxNumber> 
    </billTo> 
    <payment> 
      <creditCard> 
        <cardNumber>{$data['cardNum']}</cardNumber> 
        <expirationDate>{$data['cardExp']}</expirationDate> 
      </creditCard> 
    </payment> 
    <customerPaymentProfileId>{$data['payment_profile']}</customerPaymentProfileId> 
  </paymentProfile> 
</updateCustomerPaymentProfileRequest>
BLOCK;

 Something like that. See how much easier to read the code is?

Highlighted
Member
Posts: 3
Registered: ‎10-20-2011

Re: testMode vs liveMode for Update Payment Profile

Ah, after finding the SDK, I have improved my code.  I much prefer the object method to the xml method.  Anyway, it seems that whatever I've done has fixed the initial problem, and my update request now works in testMode and liveMode.  Here is my (hopefully) final code:

 

		$request = new AuthorizeNetCIM;
		$updatedProfile->billTo->firstName = $firstName;
		$updatedProfile->billTo->lastName = $lastName;
		$updatedProfile->billTo->zip = $ZIP;
		$updatedProfile->payment->creditCard->cardNumber = $CCNumber;
		$updatedProfile->payment->creditCard->expirationDate = $expiration;
		$updateResponse = $request->updateCustomerPaymentProfile($anetProfileID, $paymentID, $updatedProfile, "liveMode");	
			if ("Ok" == $updateResponse->xml->messages->resultCode) {
				echo 'Update Request Succeeded';
			}
			else	{
				print_r($updateResponse->xml->messages);
				//echo 'Update Request Failed<br />';
			}

 

Thanks for all your help.