Hi,
I try to integrate Braintree to meteor with this tutorial: https://blog.trombone.io/taking-payments-with-meteor-braintree/
But i have some error:
[client]: SCSS Files Compilation: 0.212ms \
[client]: HTML Files Compilation: 61.369ms \
[client]: ES2015 modules Compilation: 657.164ms
[client]: TypeScript Files Compilation: 22.341ms
[server]: SCSS Files Compilation: 0.191ms \
[server]: HTML Files Compilation: 0.023ms \
[server]: ES2015 modules Compilation: 1209.193ms
server/methods.ts (331, 21): Property 'clientId' does not exist on type '{}'.
[server]: TypeScript Files Compilation: 11.267ms
W20180723-10:02:22.798(4)? (STDERR) /home/maitaior/.meteor/packages/meteor-tool/.1.6.1_3.dgmyr5.69xkn++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
W20180723-10:02:22.799(4)? (STDERR) throw(ex);
W20180723-10:02:22.799(4)? (STDERR) ^
W20180723-10:02:22.800(4)? (STDERR)
W20180723-10:02:22.800(4)? (STDERR) TypeError: Cannot read property 'Environment' of undefined
W20180723-10:02:22.800(4)? (STDERR) at methods.js (server/methods.ts:19:21)
W20180723-10:02:22.801(4)? (STDERR) at fileEvaluate (packages/modules-runtime.js:343:9)
W20180723-10:02:22.801(4)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180723-10:02:22.801(4)? (STDERR) at server/main.ts:13:4
W20180723-10:02:22.802(4)? (STDERR) at /home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/boot.js:411:36
W20180723-10:02:22.802(4)? (STDERR) at Array.forEach (<anonymous>)
W20180723-10:02:22.802(4)? (STDERR) at /home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/boot.js:220:19
W20180723-10:02:22.803(4)? (STDERR) at /home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/boot.js:471:5
W20180723-10:02:22.803(4)? (STDERR) at Function.run (/home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/profile.js:510:12)
W20180723-10:02:22.803(4)? (STDERR) at /home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/boot.js:470:11
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.
Here the code:
let env = braintree.Environment.Sandbox;
if (Meteor.settings.environment === 'production') {
env = braintree.Environment.Production;
}
const gateway = braintree.connect({
environment: env,
merchantId: Meteor.settings.braintree.merchantId,
publicKey: Meteor.settings.braintree.publicKey,
privateKey: Meteor.settings.braintree.privateKey,
});
I already installed:
npm install braintree-web
npm install braintree
Whats wrong?
you will need either:
import braintree from 'braintree';
or:
const braintree = require('braintree');
at the top of your file
1 Like
Yes, i imported like that:
import braintree from 'braintree';
and
import { braintree } from 'braintree';
There is the same error for both “Cannot read property environement”
And for:
const braintree = require('braintree');
I have this:
[client]: SCSS Files Compilation: 0.255ms -
[client]: HTML Files Compilation: 56.000ms -
[client]: ES2015 modules Compilation: 684.121ms
[client]: TypeScript Files Compilation: 24.498ms
[server]: SCSS Files Compilation: 0.274ms |
[server]: HTML Files Compilation: 0.030ms |
[server]: ES2015 modules Compilation: 645.756ms
server/methods.ts (332, 21): Property 'clientId' does not exist on type '{}'.
[server]: TypeScript Files Compilation: 6.516ms
W20180723-11:03:04.535(4)? (STDERR) /home/maitaior/.meteor/packages/meteor-tool/.1.6.1_3.dgmyr5.69xkn++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
W20180723-11:03:04.536(4)? (STDERR) throw(ex);
W20180723-11:03:04.536(4)? (STDERR) ^
W20180723-11:03:04.537(4)? (STDERR)
W20180723-11:03:04.537(4)? (STDERR) TypeError: Cannot read property 'merchantId' of undefined
W20180723-11:03:04.537(4)? (STDERR) at methods.js (server/methods.ts:28:43)
W20180723-11:03:04.538(4)? (STDERR) at fileEvaluate (packages/modules-runtime.js:343:9)
W20180723-11:03:04.538(4)? (STDERR) at require (packages/modules-runtime.js:238:16)
W20180723-11:03:04.538(4)? (STDERR) at server/main.ts:13:4
W20180723-11:03:04.539(4)? (STDERR) at /home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/boot.js:411:36
W20180723-11:03:04.539(4)? (STDERR) at Array.forEach (<anonymous>)
W20180723-11:03:04.539(4)? (STDERR) at /home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/boot.js:220:19
W20180723-11:03:04.540(4)? (STDERR) at /home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/boot.js:471:5
W20180723-11:03:04.540(4)? (STDERR) at Function.run (/home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/profile.js:510:12)
W20180723-11:03:04.540(4)? (STDERR) at /home/maitaior/Bureau/Test/app/.meteor/local/build/programs/server/boot.js:470:11
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.
Did you start meteor with a settings.json file?
meteor run --settings settings.json
1 Like
Oh sorry, i created a wrong settings.json
I run with
npm start
And you make me realize that they are 2 settings.json, 1 for development and 1 for production.
The server run now with no error, except this:
server/methods.ts (332, 21): Property 'clientId' does not exist on type '{}'.
Thank you very much for your time.
1 Like
Why import braintree from 'braintree';
doesnt work, and why const braintree = require('braintree');
works for me?
1 Like
That I don’t know! They are meant to work the same!
1 Like
Also i have an error message when i run the server:
Property 'clientId' does not exist on type '{}'.
With the getClientToken function:
getClientToken: (clientId) => {
const generateToken = Meteor.wrapAsync(gateway.clientToken.generate, gateway.clientToken);
const options = {};
if (clientId) {
options.clientId = clientId;
}
const response = generateToken(options);
return response.clientToken;
}
Are you using Typescript?
AFAIK the easiest way around that is then by saying the options object can hold any type:
const options = <any>{};
1 Like
Yes, i’m using Typescript.
That’s solve the issue, thanks you!