无法将现有付款资料设置为客户的默认付款资料

Cannot set existing payment profile to be the default for a customer

我正在使用 updateCustomerPaymentProfile 端点尝试更新付款资料。这很好用,除了存在一个字段:defaultPaymentProfile.

有两个不同的问题。

1。 Authorize.Net Ruby SDK 输入问题

文档说defaultPaymentProfile是一个预期的字段,但是ruby SDK中的类型不允许,参见官方源代码:

https://github.com/AuthorizeNet/sdk-ruby/blob/002019e03a94ef582aa82983edf6a7a1a22b2316/lib/authorize...

关于这个我打开了a Github issue

然后我猴子修补了如下类型:

module AuthorizeNet::API 
  class CustomerPaymentProfileExType
    xml_accessor :defaultPaymentProfile
  end
end

之后,它接受发送请求,但我收到如下错误响应:

AuthorizeNetException: E00003: The element 'paymentProfile' in namespace 
'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 
'defaultPaymentProfile' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd

这是第二期...

2。 Authorize.Net API 在更新付款资料时不接受 defaultPaymentProfile

为了记录,我转储了发送到 API 的原始 XML 一旦我修补了 SDK 以便能够实际到达 API:

<updateCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <merchantAuthentication>
    <name>REDACTED</name>
    <transactionKey>REDACTED</transactionKey>
  </merchantAuthentication>
  <customerProfileId>REDACTED</customerProfileId>
  <paymentProfile>
    <customerType>individual</customerType>
    <billTo>
      <firstName>REDACTED</firstName>
      <lastName>REDACTED</lastName>
      <address>REDACTED</address>
      <city>REDACTED</city>
      <state>REDACTED</state>
      <zip>REDACTED</zip>
      <country>REDACTED</country>
      <phoneNumber>REDACTED</phoneNumber>
    </billTo>
    <payment>
      <creditCard>
        <cardNumber>XXXX4242</cardNumber>
        <expirationDate>2022-03</expirationDate>
      </creditCard>
    </payment>
    <customerPaymentProfileId>REDACTED</customerPaymentProfileId>
    <!-- This XML passes fine without the line below -->
    <defaultPaymentProfile>true</defaultPaymentProfile>
  </paymentProfile>
  <validationMode>liveMode</validationMode>
</updateCustomerPaymentProfileRequest>

这看起来与请求 suggested by the official API docs 完全一样,但是,服务器响应 E00003 我已经在上面分享过的错误。

备注

作为参考,我使用的 ruby 代码块:

        profile = AuthorizeNet::API::CustomerPaymentProfileExType.new
        profile.customerPaymentProfileId = current_profile.customerPaymentProfileId
        profile.billTo = billTo
        profile.payment = AuthorizeNet::API::PaymentType.new(
          AuthorizeNet::API::CreditCardType.new(
            cc_data.cardNumber, cc_data.expirationDate
          )
        ) 
        profile.taxId = user.tax_id if user.tax_id
        profile.defaultPaymentProfile = true
        profile.customerType = 'individual'

        request = AuthorizeNet::API::UpdateCustomerPaymentProfileRequest.new
        request.paymentProfile = profile
        request.customerProfileId = customer_profile_id
        request.validationMode = AuthorizeNet::API::ValidationModeEnum::LiveMode

        response = transaction.update_customer_payment_profile(request)

我做错了什么?

元素的顺序很重要。移动

<defaultPaymentProfile>true</defaultPaymentProfile>` 

以上

<customerPaymentProfileId>REDACTED</customerPaymentProfileId>`
<updateCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
  <merchantAuthentication>
    <name>REDACTED</name>
    <transactionKey>REDACTED</transactionKey>
  </merchantAuthentication>
  <customerProfileId>REDACTED</customerProfileId>
  <paymentProfile>
    <customerType>individual</customerType>
    <billTo>
      <firstName>REDACTED</firstName>
      <lastName>REDACTED</lastName>
      <address>REDACTED</address>
      <city>REDACTED</city>
      <state>REDACTED</state>
      <zip>REDACTED</zip>
      <country>REDACTED</country>
      <phoneNumber>REDACTED</phoneNumber>
    </billTo>
    <payment>
      <creditCard>
        <cardNumber>XXXX4242</cardNumber>
        <expirationDate>2022-03</expirationDate>
      </creditCard>
    </payment>
    <defaultPaymentProfile>true</defaultPaymentProfile>
    <customerPaymentProfileId>REDACTED</customerPaymentProfileId>
  </paymentProfile>
  <validationMode>liveMode</validationMode>
</updateCustomerPaymentProfileRequest>

感谢@John Conde,我可以解决这个问题。请求负载被拒绝,因为属性的顺序不正确。

如果您想使用 ruby SDK 将现有付款配置文件设置为默认付款配置文件,您可以通过为自己定义正确的类型来实现,如下所示:

module AuthorizeNet::API 
  class CustomerPaymentProfileExTypePatched
    include ROXML
    xml_accessor :customerType
    xml_accessor :billTo, as: AuthorizeNet::API::CustomerAddressType
    xml_accessor :payment, as: AuthorizeNet::API::PaymentType
    xml_accessor :driversLicense, as: AuthorizeNet::API::DriversLicenseType
    xml_accessor :taxId
    xml_accessor :defaultPaymentProfile
    xml_accessor :subsequentAuthInformation
    xml_accessor :customerPaymentProfileId

    def initialize(customerType = nil, billTo = nil, payment = nil, driversLicense = nil, taxId = nil, defaultPaymentProfile = nil, subsequentAuthInformation = nil, customerPaymentProfileId = nil)
      @customerType = customerType
      @billTo = billTo
      @payment = payment
      @driversLicense = driversLicense
      @taxId = taxId
      @defaultPaymentProfile = defaultPaymentProfile
      @subsequentAuthInformation = subsequentAuthInformation
      @customerPaymentProfileId = customerPaymentProfileId
    end
  end
end

那么你可以在你的代码中使用这个类型:

profile = AuthorizeNet::API::CustomerPaymentProfileExTypePatched.new