braintree / braintree_java

Braintree Java library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
158 stars 99 forks source link

CustomerRequest missing riskDataCustomerRequest element on XML generation #85

Closed Stexxen closed 3 years ago

Stexxen commented 3 years ago

General information

Issue description

CustomerRequest https://github.com/braintree/braintree_java/blob/master/src/main/java/com/braintreegateway/CustomerRequest.java#L156

The method buildRequest does not add the element RiskDataCustomerRequest even though is it part of the Customer Request.

Test Case

    CustomerRequest customerRequest = new CustomerRequest();
    customerRequest.riskData().customerBrowser(USER_AGENT);
    customerRequest.riskData().customerIP(REMOTE_IP);
    customerRequest.customField("test_field", "test123);
    System.out.println(customerRequest.toXML());

will output

<customer>
    <customFields>
        <test_field>test123</test_field>
    </customFields>
</customer>

I think all that is required is to add the missing addElement statement. i.e.

addElement("riskDataCustomerRequest", riskDataCustomerRequest).
sestevens commented 3 years ago

@Stexxen Thanks for raising this issue. It looks like a bug in the SDK. We'll post here once we have a fix out for this.

sestevens commented 3 years ago

@Stexxen We're also happy to accept PRs if this is something you're interested in fixing!

Stexxen commented 3 years ago

@sestevens Could be something we can do, but someone from Braintree will need to confirm that the XML tag

<riskDataCustomerRequest></riskDataCustomerRequest>

Is the correct tag, as I'm only guessing that's what it should be.

sestevens commented 3 years ago

@Stexxen The tag should be:

<risk-data></risk-data>

It looks like the element is being added correctly in our .NET SDK: https://github.com/braintree/braintree_dotnet/blob/18dc68b57092258f5f5e7982a7b0146394a5bd97/src/Braintree/CustomerRequest.cs#L102.

Stexxen commented 3 years ago

unfortunately it looks like they use different XML schemas. (Do they use different endpoints)?

Java (camelCase)

   addElement("deviceData", deviceData).
   addElement("paymentMethodNonce", paymentMethodNonce).
   addElement("defaultPaymentMethodToken", defaultPaymentMethodToken).

C# (kebab-case)

  AddElement("device-data", DeviceData).
  AddElement("payment-method-nonce", PaymentMethodNonce).
  AddElement("default-payment-method-token", DefaultPaymentMethodToken).

Unless the implementation specific RequestBuilder does something to normalise the 2 naming conventions?

Stexxen commented 3 years ago

That said, it suggests that the Java line would either be

   addElement("riskData", riskDataCustomerRequest).

or

   addElement("riskData", riskDataCustomerRequest.riskData()).
sestevens commented 3 years ago

Oh, good catch. The endpoint accepts XML tags in both dash case and camel case. So it would be

addElement("riskData", riskDataCustomerRequest).
sestevens commented 3 years ago

@Stexxen This issue has been fixed in version 3.2.0 of the SDK.