使用Authorize.Net Ruby SDK无法将现有支付配置设为客户默认配置
问题根因
你遇到的E00003报错不是字段非法,而是API服务端对请求XML的字段顺序有严格的XSD校验要求,你当前请求中defaultPaymentProfile节点放在了customerPaymentProfileId之后,不符合XSD定义的字段顺序,所以被判定为非法子元素。
修复方案
方案1:修正猴子补丁的字段定义和赋值顺序
你原来的猴子补丁只添加了字段声明,没有指定类型和序列化顺序,需要修改为以下定义:
module AuthorizeNet::API class CustomerPaymentProfileExType # 显式指定字段类型为布尔值,且声明顺序要早于customerPaymentProfileId,保证序列化时顺序符合XSD要求 xml_accessor :defaultPaymentProfile, type: Boolean end end
同时调整你代码中的赋值顺序,先给defaultPaymentProfile赋值,再给customerPaymentProfileId赋值:
profile = AuthorizeNet::API::CustomerPaymentProfileExType.new # 先赋值defaultPaymentProfile profile.defaultPaymentProfile = true # 再赋值其他字段 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.customerType = 'individual'
方案2:使用兼容性更高的替代实现
如果调整顺序后仍然报错,可以改用两步实现的方式,规避该接口的字段顺序坑:
- 先不传
defaultPaymentProfile字段,正常调用updateCustomerPaymentProfile接口更新支付配置信息 - 再调用
updateCustomerProfile接口,将defaultPaymentProfileId参数设置为本次更新的支付配置ID,即可完成默认支付配置的设置。
内容的提问来源于stack exchange,提问作者Pandaiolo
相关产品推荐
相关产品推荐

