Search code examples
javabraintree

Braintree, How to use application generated ids with a new customer


So I have simple java based server backend. I would like to create an empty customer and use an id that is generated in my application, not the id that is assigned by braintree. I tried to use this approach:

String testId = "12345678";

log.info("Create customer with id: " + testId);
    CustomerRequest customerRequest = new CustomerRequest()
            .customerId(testId)
            .firstName("Martin")
            .lastName("Mojko");
braintreeGateway.customer().create(customerRequest);

However, the setter customerId is ignored and braintree assigns different id to this customer. It is there any way to use own ids?


Solution

  • Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

    You should use .id instead of .customerId to assign your generated ID to your customer. The request will look something like this:

    CustomerRequest request = new CustomerRequest()
      .id(testId)
      .firstName("Martin")
      .lastName("Mojko");
    
    Result<Customer> result = gateway.customer().create(request);