如何使用Authorize.Net CIM检索付款信息

时间:2012-12-11 19:53:31

标签: c# authorize.net payment-processing

我正在尝试使用Authorize.Net CIM API使用GetCustomerPaymentProfile检索付款信息。特别是,我需要蒙面信用卡号码和信用卡类型或掩码支票帐号。我已阅读API文档并遵循它,但没有intellisense所以我的项目将无法编译。

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

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

使用C#,我该怎么做?

编辑: 看起来支付对象是动态的。这是我最终使用的代码。谢谢你的帮助!

        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 个答案:

答案 0 :(得分:2)

我不知道C#,但如果它的语义遵循其他语言,那么这应该有效:

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

以下是一个示例XML输出,可能对您有所帮助:

<?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>