I am using the updateCustomerPaymentProfile
endpoint to try to update a payment profile. This works well, except for the presence of one field: defaultPaymentProfile
.
There are two different issues.
The docs say defaultPaymentProfile
is an expected field, but the type does not allow it in ruby SDK, see in the official source code:
I opened a Github issue about this.
I then monkey patched the type as following:
module AuthorizeNet::API
class CustomerPaymentProfileExType
xml_accessor :defaultPaymentProfile
end
end
After that, it accepts to send the request but I receive an error response as following:
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
Which is the second issue...
defaultPaymentProfile
when updating a payment profileFor the record, I dumped the raw XML that is sent to the API once I patched the SDK to be able to actually reach the 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>
This looks exactly the same as the request suggested by the official API docs, yet, the server respond with a E00003
error that I already shared above.
As a reference, the block of ruby code that I am using:
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)
What am I doing wrong?
The order of the elements matter. Move
<defaultPaymentProfile>true</defaultPaymentProfile>`
above
<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>