Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

norkor's avatar

Subscriptions in Braintree with laravel/cashier-braintree / Laravel 5.2

Need to integrate laravel/cashier-braintree in my Laravel app. Having pretty much no experience with Braintree integration it's really hard to make it work. Can somebody explain in steps how it works, or some tutorial that would be good for this? Tried to follow integration for Stripe, cause they are similar but no success.

This is how my code looks like right now

Intergraded oureastudios/laravel5-braintree so then in console form-data I get payment_method_nounce correctly, but how do I pass client token to my checkout method?

<form id="checkout" action="{{ url('subscriptions/checkout') }}" method="post">
        {{ csrf_field() }}
        <div class="form-group">
            <label for="">Choose option:</label>
            <select name="plan" id="plan" class="form-control">
                <option value="small">Small ($5/month)</option>
                <option value="large">Large ($10/month)</option>
            </select>
        </div>
        <div class="form-group">
            <div id="number" class="form-control"></div>
        </div>
        <div class="form-group">
            <div id="expiration-date" class="form-control"></div>
        </div>
        <div class="form-group">
            <div id="cvv" class="form-control"></div>
        </div>
        <input type="submit" id="submit" value="Pay">
    </form>
    <script src="https://js.braintreegateway.com/v2/braintree.js"></script>
    <script>
        var colorTransition = 'color 100ms ease-out';

        braintree.setup("@braintreeClientToken", "custom", {
            id: "checkout",
            hostedFields: {
                styles: {
                    // Style all elements
                    "input": {
                        "color": "#333"
                    },

                    // Styling element state
                    ":focus": {
                        "color": "blue"
                    },
                    ".valid": {
                        "color": "green"
                    },
                    ".invalid": {
                        "color": "red"
                    },

                    // Media queries
                    // Note that these apply to the iframe, not the root window.
                    "@media screen and (max-width: 700px)": {
                        "input": {}
                    }
                },
                number: {
                    selector: "#number"
                },
                expirationDate: {
                    selector: "#expiration-date"
                },
                cvv: {
                    selector: "#cvv"
                }
            }
        });
    </script>

On checkout method getting

Unable to create Braintree customer: Unknown payment_method_nonce.
Expiration date is required.
Credit card number is required.
Credit card must include number, payment_method_nonce, or venmo_sdk_payment_method_code. 

Don't know how to pass @braintreeClientToken in checkout method..

Maybe someone knows how to make this working?

0 likes
1 reply
gomako's avatar

I know this is old, but I had the same issue, cashier doesn't seem to provide an interface to generate a user token. I did it this way:

Add the following to AppServiceProvider in the boot() method:

\Braintree\Configuration::environment(env('BRAINTREE_ENV'));
\Braintree\Configuration::merchantId(env('BRAINTREE_MERCHANT_ID'));
\Braintree\Configuration::publicKey(env('BRAINTREE_PUBLIC_KEY'));
\Braintree\Configuration::privateKey(env('BRAINTREE_PRIVATE_KEY'));

Then you can generate the client token by including the following in your javascript:

braintree.setup("{{ (\Braintree\ClientToken::generate()) }}" , "custom", {
  ...The rest of your setup options... 
});
1 like

Please or to participate in this conversation.