2
votes

I'm trying to retrieve payment information using GetCustomerPaymentProfile using the Authorize.Net CIM API. Particularly, I need the masked credit card number and credit card type OR masked checking account number. I've read the API documentation and followed it but there is no intellisense so my project won't compile.

var data = Service.GetCustomerPaymentProfile(MerchantAuthentication, profileId, customerPaymentProfileId);

var creditCard = data.creditCard... (nothing here)

Using C#, how would I do this?

EDIT: Looks like the payment object is a dynamic. Here's the code I ended up using. Thanks for the help!

        if (data.paymentProfile.payment.Item.GetType() == typeof(CreditCardMaskedType))
        {
            var obj = (CreditCardMaskedType) data.paymentProfile.payment.Item;
            retval.CreditCardNumber = obj.cardNumber;
            retval.CreditCardType = obj.cardType;
        }

        if (data.paymentProfile.payment.Item.GetType() == typeof(BankAccountMaskedType))
        {
            var obj = (BankAccountMaskedType)data.paymentProfile.payment.Item;
            retval.BankAccountNumber = obj.accountNumber;
            retval.BankRoutingNumber = obj.routingNumber;
        }
1
could you show your code and error message you get please?Arsen Mkrtchyan

1 Answers

2
votes

I don't know C# but if its semantics follow other languages this should work:

var creditCard = data.paymentProfile.payment.creditCard.cardNumber;

Here's a sample XML output which may be helpful to you:

<?xml version="1.0" encoding="utf-8"?>
<getCustomerPaymentProfileResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <messages>
    <resultCode>Ok</resultCode>
    <message>
      <code>I00001</code>
      <text>Successful.</text>
    </message>
  </messages>
  <paymentProfile>
    <billTo>
      <firstName>John</firstName>
      <lastName>Smith</lastName>
      <address>123 Main Street</address>
      <city>Townsville</city>
      <state>NJ</state>
      <zip>12345</zip>
      <phoneNumber>800-555-1234</phoneNumber>
    </billTo>
    <customerPaymentProfileId>4796541</customerPaymentProfileId>
    <payment>
      <creditCard>
        <cardNumber>XXXX1111</cardNumber>
        <expirationDate>XXXX</expirationDate>
      </creditCard>
    </payment>
  </paymentProfile>
</getCustomerPaymentProfileResponse>