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

Trouble with the defaultPaymentProfile flag

Hi Folks,

 

I am creating a customer profile with two payment profiles. I am explicitly assigning one of the payment profiles to be the default payment profile.

 

However, when I then follow that up with a call to getProfile, both of the payment profiles are returned and neither of them is marked as the default.

 

One of my requirements is to allow the customer to select and/or change their default payment profile, so this is causing me an issue as I'd hoped to rely on this flag to implement this requirement.

 

Has anyone else had trouble working with default payment profiles, or can help me understand what it is that I'm doing wrong?

 

If needed, I can provide code samples.

 

Thanks,

--Jason

JasonSki7475
Member
16 REPLIES 16

 

Get Customer Profile retrieves an existing customer profile along with all the associated payment profiles and shipping addresses.

 

Get Customer Payment Profile will return the default payment profile, if a default payment profile has been previously designated.

Powered by NexWebSites.com -
Certified Authorize.net developers
NexusSoftware
Trusted Contributor

Yes, I picked up that information in the API docs, thank you! I am just not understanding why when I do retrieve that payment profile, the defaultPaymentProfile flag is not returned as true. I am allowed to set the value, but can't retrieve the value.

 

So what process would I follow to change credit card 2 to be the primary and ensure  that credit card 1 is not any longer?

 

If I call updatePaymentProfile and set it to default, will that automatically remove that setting from the other profile?

 

Thanks,

--Jason

You would call updateCustomerPaymentProfileRequest with the
defaultPaymentProfile field set to Boolean true or 1, this field designates the payment profile as the default payment profile.


When a default payment profile has been designated, you can use getCustomerPaymentProfileRequest with customerProfileId as the only parameter.

 

Note: If some fields in the updateCustomerPaymentProfileRequest are not submitted or are submitted with a blank value, the values in the original profile are removed.

Powered by NexWebSites.com -
Certified Authorize.net developers

I just tried calling that getCustomerPaymentProfile without submitting the payment profile id, and it did not return the default payment profile, in fact it says there is no default payment profile, which indicates to me that the flag isn't even working. So perhaps I am doing something wrong with setting it as default? I am setting defaultPaymentProfile to true and defaultPaymentProfileSpecified to be true as well, is this incorrect?

 

--Jason

Setting the  <defaultPaymentProfile>true</defaultPaymentProfile> works. Let's see your code. 

Powered by NexWebSites.com -
Certified Authorize.net developers

Alrighty, I can do that.

 

Here's the main service method. I ripped out logging and things like that to keep it readable.

 

public ProfileIDs createProfile(Guid transactionGuid, FC_Payment.Data.Customer customer, PlanCode planCode)

{

createCustomerProfileRequest request = new createCustomerProfileRequest();

request.refId = customer.ID;

request.profile = new customerProfileType();

request.profile.merchantCustomerId = customer.ID.ToString();

request.profile.email = customer.EmailAddress;

request.profile.description = customer.Description;

request.profile.paymentProfiles = ANetPaymentProcessor.MapCustomerToANetPaymentProfiles(customer).ToArray();

request.profile.shipToList = new customerAddressType[] {

ANetPaymentProcessor.MapCustomerAddressToANetCustomerAddress(customer.MailingAddress, customer.LastName,

customer.FirstName, customer.CompanyName) };

request.validationMode = ANetPaymentProcessor.CIMValidationMode;

request.validationModeSpecified = true;

ANetMakeRequest requestMaker = new ANetMakeRequest(planCode);

 

createCustomerProfileResponse response = (createCustomerProfileResponse)requestMaker.MakeRequest(request);

ProfileIDs profileIDs = new ProfileIDs();

profileIDs.CustomerProfileID = response.customerProfileId;

profileIDs.PaymentProfileIDs = new List<string>(response.customerPaymentProfileIdList);

return profileIDs;

}

 

Here's the code for the MapCustomerToANetPaymentProfiles method. We only allow credit cards by the way. This just takes the data from the Customer parameter above and maps it to the auth.net object.

 

public static List<customerPaymentProfileExType> MapCustomerToANetPaymentProfiles(FC_Payment.Data.Customer customer)

{

List<customerPaymentProfileExType> pymtProfiles = new List<customerPaymentProfileExType>();

 

if (customer.CreditCards != null && customer.CreditCards.Count > 0)

{

foreach (CustomerCreditCard creditCard in customer.CreditCards)

{

customerPaymentProfileExType pymtProfile = new customerPaymentProfileExType();

pymtProfile.customerPaymentProfileId = string.IsNullOrEmpty(creditCard.PaymentProfileID) ? null : creditCard.PaymentProfileID;

pymtProfile.defaultPaymentProfile = creditCard.IsPrimary;

pymtProfile.defaultPaymentProfileSpecified = creditCard.IsPrimary;

pymtProfile.billTo = new customerAddressType();

pymtProfile.billTo.address = customer.BillingAddress.Street1;

pymtProfile.billTo.city = customer.BillingAddress.City;

pymtProfile.billTo.state = customer.BillingAddress.StateProvinceCode;

pymtProfile.billTo.zip = customer.BillingAddress.PostalCode;

pymtProfile.billTo.country = customer.BillingAddress.Country;

pymtProfile.billTo.phoneNumber = customer.BillingAddress.Phone;

pymtProfile.billTo.faxNumber = customer.BillingAddress.Fax;

pymtProfile.billTo.firstName = creditCard.FirstNameOnCard;

pymtProfile.billTo.lastName = creditCard.LastNameOnCard;

pymtProfile.billTo.company = customer.CompanyName;

pymtProfile.customerType = customer.Type == CustomerType.Individual ? customerTypeEnum.individual : customerTypeEnum.business;

pymtProfile.payment = new paymentType();

creditCardType cc = new creditCardType();

cc.cardNumber = creditCard.CardNumber;

cc.cardCode = creditCard.CVVCode;

//Expiration month and year could be present as either the actual numbers or masked as XX.

int expMonth, expYear;

if (Int32.TryParse(creditCard.ExpirationMonth, out expMonth) &&

Int32.TryParse(creditCard.ExpirationYear, out expYear))

{

cc.expirationDate = string.Format("{0}-{1:D2}", expYear, expMonth);

}

else

{

cc.expirationDate = string.Format("{0}{1}", creditCard.ExpirationYear, creditCard.ExpirationMonth);

}

pymtProfile.payment.Item = cc;

pymtProfiles.Add(pymtProfile);

}

}

 

return pymtProfiles;

}

 

 

I'm not sure if I can post screen shots here, but I did put a breakpoint just before the the request is issued and the payment profiles do have the flags set appropriately, one is true and one is false.

Is there something else I can show?

 

--Jason

 

I was able to grab the XML also:

 

<?xml version="1.0" encoding="utf-8"?><createCustomerProfileRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"><merchantAuthentication><name>SCRUBBED</name><transactionKey>SCRUBBED</transactionKey></merchantAuthentication><refId>SCRUBBED</refId><profile><merchantCustomerId>scrubbed</merchantCustomerId><description>Chewsi Subscriber</description><email>developer@scrubbed.com</email><paymentProfiles xsi:type="customerPaymentProfileExType"><billTo><firstName>Name</firstName><lastName>Card1</lastName></billTo><payment><creditCard><cardNumber>4007000000027</cardNumber><expirationDate>2018-12</expirationDate><cardCode>223</cardCode></creditCard></payment><defaultPaymentProfile>true</defaultPaymentProfile></paymentProfiles><paymentProfiles xsi:type="customerPaymentProfileExType"><billTo><firstName>Name</firstName><lastName>Card2</lastName></billTo><payment><creditCard><cardNumber>6011000000000012</cardNumber><expirationDate>2018-12</expirationDate><cardCode>223</cardCode></creditCard></payment></paymentProfiles><shipToList><firstName>Blue</firstName><lastName>Moon</lastName></shipToList></profile><validationMode>testMode</validationMode></createCustomerProfileRequest>

 

 

And I do see the node for the default payment profile.

In order to set the DefaultPaymentProfile the CreateCustomerPaymentProfileRequest is required to have to have customerType and BillTo / CustomerAddress.

Powered by NexWebSites.com -
Certified Authorize.net developers

We don't collect a customer address. Is there no way around this?