Braintree (synchronous meteor)

Hello. Thanks for read
Please need help with the synchronous call, to obtain the braintree token

File: imports/api/braintree/methods.js

Way A : This is the synchronous way but don’t works

import {Meteor}    from 'meteor/meteor';
import braintree   from 'braintree';

let gateway = braintree.connect({
    environment: braintree.Environment.Sandbox,
    merchantId: 'KEY',
    publicKey:  'KEY',
    privateKey: 'KEY'
});

Meteor.methods({ getToken: (clientId) => {
    var generateToken = Meteor.wrapAsync(gateway.clientToken.generate, gateway.clientToken);
    var options = {};
    if (clientId) {
        options.clientId = clientId;
    }
    var response = generateToken(options);
    return response.clientToken;
}});

Way B : This is the asynchronous way but I dont want it

import {Meteor}    from 'meteor/meteor';
import braintree   from 'braintree';

let gateway = braintree.connect({
    environment : braintree.Environment.Sandbox,
    merchantId  : 'KEY',
    publicKey   : 'KEY',
    privateKey  : 'KEY'
});

Meteor.methods({ getToken: (clientId) => {
    gateway.clientToken.generate({}, function (err, response) {
        console.log('Print something');
        return response.clientToken;
    });
}});

My question is: How I can to do for run in synchronous mode?

1 Like

Why?

What do you get in the response object?

Have you tried wrapping the call in a try/catch and logging any error?