braintree / braintree_php

Braintree PHP library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
546 stars 224 forks source link

Issues getting client token #267

Closed alexbohariuc closed 4 years ago

alexbohariuc commented 4 years ago

General information

Issue description

I have a weird issue: I have a drop in UI configured as a donation form in a Wordpress theme. Everything looks good, i can connect to the gateway, but i have a problem getting the client token. To be more specific i get this error:

    name: "DropinError"
    message: "There was an error creating Drop-in."
    _braintreeWebError: r
    name: "BraintreeError"
    code: "CLIENT_INVALID_AUTHORIZATION"
    message: "Authorization is invalid. Make sure your client token or tokenization key is valid."
    type: "MERCHANT"
    details: undefined

The response is the following:

token: "{"version":1,"authorizationFingerprint":"...","configUrl":"https://api.braintreegateway.com:443/merchants/.../client_api/v1/configuration","graphQL":{"url":"https://payments.braintree-api.com/graphql","date":"2018-05-08"},"challenges":[],"environment":"production","clientApiUrl":"https://api.braintreegateway.com:443/merchants/.../client_api","assetsUrl":"https://assets.braintreegateway.com","authUrl":"https://auth.venmo.com","analytics":{"url":"https://client-analytics.braintreegateway.com/..."},"threeDSecureEnabled":true,"paypalEnabled":false}"

However, sometimes it works and in the response I only get the token.

This is where i'm getting the token in js:

    var processClientToken = function (response) {
            braintree.dropin.create(
                {
                    authorization: response.token,
                    selector: "#bt-dropin",
                    paypal: {
                        flow: "vault"
                    },
                    card: {
                        cardholderName: {
                            required: true
                        }
                    }
                },
                processDropInCreation,
                console.log(response)
            );
        };

        $.get("/path/clientToken.php", processClientToken, "json");

And this is the clientToken.php file:

    <?php

    require_once ('../../../../braintree/includes/braintree_init.php');

    echo json_encode([
      token => $gateway->ClientToken()->generate()
    ]);

Any ideas?

hollabaq86 commented 4 years ago

👋 @alexbohariuc, please contact Support referencing this issue. They can assist you in troubleshooting your integration.