braintree / braintree_java

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

generate(ClientTokenRequest request) accepting "null" value for customerId #44

Closed ghost closed 8 years ago

ghost commented 8 years ago

I am not entirely sure why this is the case but

ClientTokenRequest clientTokenRequest = new ClientTokenRequest()
        .customerId(null);

return BT.clientToken().generate(clientTokenRequest);

does create a server token. I did not test if I can use this token actually but shouldn't there be an error message saying that this user does not exist in my vault?

mtmarsh3 commented 8 years ago

Hi Silentsnooc,

Thanks for reaching out, we are currently looking into this.

mtmarsh3 commented 8 years ago

I was not able to reproduce your issue, is BT representing a BraintreeGateway? When I tried calling generate(null), I received a NullPointerException and did not generate a server token due to the line below, which is within ClientTokenGateway.

Could you tell me what version of the client library you are using? I would also recommend reaching out to support at: support@braintreepayments.com for further help.

ghost commented 8 years ago

@mtmarsh3 Hi!

Yes, BT is a BraintreeGateway instance.

I just saw that I modified the code wrong! I set the request object null in the code. I've edited my original post from

return BT.clientToken().generate(null);

to

ClientTokenRequest clientTokenRequest = new ClientTokenRequest()
        .customerId(null);

return BT.clientToken().generate(clientTokenRequest);

I've just been running this and I'm receiving a token that way. Is this intended? The version I'm using is

<dependency>
    <groupId>com.braintreepayments.gateway</groupId>
    <artifactId>braintree-java</artifactId>
    <version>2.65.0</version>
</dependency>
mtmarsh3 commented 8 years ago

Thanks for the update. This is the intended behavior, as generating a ClientTokenRequest without a specified customerId should operate the same in both the ClientTokenRequest() and ClientTokenRequest().customerId(null) constructors.

pblesi commented 8 years ago

I am going to close this issue. If you have further questions, feel free to reopen this issue.

Thkasis commented 5 years ago

Since the nature of problem is the same I add it under this thread. Trying to generate token using Node.js, giving an arbitrary string as customerID that doesn't get captured in err and rather the response comes with an error message object like below. I'm using Braintree 2.15.0 & Node.js.

gateway.clientToken.generate({ customerId: "someRandomText" }, function (err, response) { //err is null and rather response is an object like below });

Example response : RESPONSE RECEIVED FROM FUNCTION: 200, { "result": { "token": { "errors": { "validationErrors": {}, "errorCollections": { "clientToken": { "validationErrors": { "customerId": [ { "attribute": "customer_id", "code": "92804", "message": "Customer specified by customer_id does not exist" } ] }, "errorCollections": {} } } }, "params": "", "message": "Customer specified by customer_id does not exist", "success": false } } }

Shouldn't that error be captured in err instead of response?

crookedneighbor commented 5 years ago

the err param is reserved for issues with the request itself. IE, if the Braintree Gateway was to return a 500 or if the underlying API route you were attempting to hit did not exist and returned a 404.

All 422 errors are returned as results where success is false, which is what is happening here. You're hitting the client token generation route, which does exist, but using a customer id that does not, which triggers a validation error.

Please contact our support team if you have additional questions about this: https://help.braintreepayments.com/