updateCustomerPaymentProfileRequest 文档错误?无法post更新支付信息,E00003

updateCustomerPaymentProfileRequest documentation error? Can't post updated payment information, E00003

我postJSON根据这篇文章来测试API: https://developer.authorize.net/api/reference/index.html#customer-profiles-update-customer-payment-profile

它清楚地表明我可以包括从他们那里收到的更新的付款元素:

paymentProfile  Contains payment information for the customer profile.
Sensitive information that is not being updated can be masked.

这是我的全部对象:

{
    "updateCustomerPaymentProfileRequest": {
        "merchantAuthentication": {
            "name": "XXXXX",
            "transactionKey": "XXXXX"
        },
        "refId": "XXXXX",
        "customerProfileId": "XXXXX",
        "paymentProfile": {
            "defaultPaymentProfile": true,
            "customerPaymentProfileId": "XXXXX",
            "payment": {
                "creditCard": {
                    "cardNumber": "XXXX1111",
                    "expirationDate": "2023-12"
                }
            },
            "originalNetworkTransId": "XXXXX",
            "originalAuthAmount": 0.0,
            "billTo": {
                "phoneNumber": "XXXXX-XXXXX",
                "firstName": "XXXXX",
                "lastName": "XXXXX",
                "address": "XXXXX XXXXX",
                "city": "XXXXX",
                "state": "XXXXX",
                "zip": "XXXXX-XXXXX",
                "country": "US"
            }
        },
        "validationMode": "testMode"
    }
} 

在 return 中,我收到此错误:

{
    "messages": {
        "resultCode": "Error",
        "message": [
            {
                "code": "E00003",
                "text":"The element \'paymentProfile\' in namespace \'AnetApi/xml/v1/schema/AnetApiSchema.xsd\' has invalid child element \'payment\' in namespace \'AnetApi/xml/v1/schema/AnetApiSchema.xsd\'."
            }
        ]
    }
}

这毫无意义。它几乎与文档完全匹配。在错误消息中,他们提到了 xml 架构。当我打开它时,它显示了不同类型的付款资料:

https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd

显示:

<xs:element name="updateCustomerPaymentProfileRequest">
  <xs:complexType>
    <xs:complexContent>
      <xs:extension base="anet:ANetApiRequest">
        <xs:sequence>
          <xs:element name="customerProfileId" type="anet:numericString"/>
          <xs:element name="paymentProfile" type="anet:customerPaymentProfileExType"/>
          <xs:element name="validationMode" type="anet:validationModeEnum" minOccurs="0"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:element>

其中 customerPaymentProfileExType 只是一个 customerPaymentProfileId:

<xs:complexType name="customerPaymentProfileExType">
  <xs:complexContent>
    <xs:extension base="anet:customerPaymentProfileType">
      <xs:sequence>
        <xs:element name="customerPaymentProfileId" type="anet:numericString" minOccurs="0"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

如果我提供 JSON 以匹配上述规范,我会收到此错误:

{
    "refId": "XXXXX",
    "messages": {
        "resultCode": "Error",
        "message": [
            {
                "code": "E00029",
                "text": "Payment information is required."
            }
        ]
    }
}

解决方案:defaultPaymentProfile 和 customerPaymentProfileId 必须列在 paymentProfile 中的支付实体之后。

所以这样做:

        "paymentProfile": {
            "payment": {
                "creditCard": {
                    "cardNumber": "XXXX1111",
                    "expirationDate": "2023-12"
                }
            },
            "defaultPaymentProfile": true,
            "customerPaymentProfileId": "XXXXX"
        },

不是:

        "paymentProfile": {
            "defaultPaymentProfile": true,
            "customerPaymentProfileId": "XXXXX",
            "payment": {
                "creditCard": {
                    "cardNumber": "XXXX1111",
                    "expirationDate": "2023-12"
                }
            },
        },