Search code examples
paypalbraintree

What are valid payment-method-tokens?


I'm trying to create a credit card and therefore I need to call paymentMethodNone(). According to the documentation I can

Use PaymentMethod.create() to create a payment method for an existing customer:

// It's not clear what A_PAYMENT_METHOD_TOKEN has to be
Result<PaymentMethodNonce> result = bt.paymentMethodNonce()
                                      .create("A_PAYMENT_METHOD_TOKEN");

String nonceFromTheClient = result.getTarget().getNonce();
Customer customer = customerResult.getTarget();

PaymentMethodRequest paymentMethodRequest = new PaymentMethodRequest()
        .customerId(customer.getId())
        .paymentMethodNonce(nonceFromTheClient);

Result<? extends PaymentMethod> paymentMethodResult = bt.paymentMethod()
                                                        .create(paymentMethodRequest);

PaymentMethod paymentMethod = paymentMethodResult.getTarget();

However, no word about what valid tokens are in the documentation. Neither here nor here - or am I just blind?


Solution

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

    You do not need a payment_method_token to create a PaymentMethod.

    To create a credit card, you will need to create a PaymentMethod. First, retrieve the payment_method_nonce from the incoming request. Next, create the PaymentMethod using PaymentMethodRequest.

    //payment_method_nonce will be a post parameter in the request
    //set nonceFromTheClient to equal payment_method_nonce
    PaymentMethodRequest paymentMethodRequest = new PaymentMethodRequest()
                .customerId(customer.getId())
                .paymentMethodNonce(nonceFromTheClient);
    Result<? extends PaymentMethod> result = gateway.paymentMethod().create(request);