How do I install Stripe for Meteor 1.3? - javascript

I'm creating a meteor web app that will sell one of our customer's products. I've decided to try and use Stripe to handle the payments (in particular Stripe Connect), and to charge an 'application fee' for each sale.
My questions:
Do I still need to use mrgalaxy:stripe or kadira:stripe-connect in order to use the Node API for Stripe? I am getting incredibly confused with the documentation of these packages, which I now believe are outdated.
If not, exactly how should I install and import Stripe for my app?
What do I need to do differently on client and on server to import Stripe?
What I have tried:
In my app directory:
meteor npm install --save stripe.
In my client side javascript code:
import stripe from "stripe"
var stripe = require("stripe"("sk_******************")
Meteor.startup(function() {
stripe.setPublishableKey("sk_******************");
});
I believe the first are meant to do the same thing, but neither works!
Chrome debugger gives me :
Uncaught TypeError: require("http").createServer is not a function
which is running in node_modules/stripe/lib/stripe.js
I am epically confused right now and would give my right index finger for clear instruction on what exactly to write in my javascript file, so I can go from where I am now to creating my first charge object.
Thanks in advance!

The Stripe npm package needs to be run on the server side, not client side. Stripe.js if for client side. You create a token with Stripe.js and then send that token to your server and use the NPM package to create a charge.

Related

Challenges with Stripe integration in Meteor

I haven't been able to find any real solid tutorials / examples of integrating payment into a Meteor app, just what's available using Nodes.JS with Express
Stripe guide I'm trying (and failing) to follow / integrate into my app
This is a possible solution, but I could use help dissecting it for Stripe integration following the guide listed above
Are there any simple guides that do not include mrgalaxy:stripe as their solution
That package hasn't been updated since 2016 and I'd really prefer more up to date dependencies
I'm specifically stuck on await / async / promises and could use some help with the checkout portion
If I need to paste code I will, but mainly I'm looking for something more recent that can help me integrate a simple checkout process
Thanks!
It seems that Meteor has good compatibility with npm packages, so there shouldn't be anything necessary here. It looks like you've also asked over in the Meteor forums so you may get a better & more specific answer there.
I have integrated Stripe into my Meteor app. As previously stated you can use the stripe npm on the server side.
meteor npm install stripe
I tend to have a file somewhere in my project that I initialize my stripe from. eg. /imports/stripe.js:
import { Meteor } from 'meteor/meteor'
import Stripe from 'stripe'
const stripe = new Stripe(Meteor.settings.Stripe.secretKey, {
maxNetworkRetries: 2,
})
export default stripe
Then whenever I need to use the stripe api from my project I can just do:
import stripe from '/imports/stripe'
And to take advantage of checkout.js or other front end integration for the client side if you wish. They tend to be as easy as dropping <script> tag into your project index.html
https://stripe.com/docs/payments/checkout/accept-a-payment#redirect-checkout

Module not found: Error: Can't resolve 'dns' when using MongoDB

I'm new to Reactjs, Nodejs and MongoDB. I'm currently trying to change Mediums snowflake tool to store users scores in a database. I have installed yarn, mongodb and mongodb-core through npm. It is a single page web application which is what I think is causing me trouble. I add
var MongoClient = require('mongodb');
To SnowflakeApp.js and encounter the following error:
Module not found: Error: Can't resolve 'dns' in
'/home/mlAHO174/snowflake/node_modules/mongodb-core/lib'
I've tried googling this error and have discovered it could be a range of things. I'm not sure if it is because React is front end and I'm trying to alter back end or because mongoDB is installed incorrectly. I'm new to this so would be grateful for help!
DNS is a core module of Node.JS. Telling people they need to install DNS via NPM will end up with them having a completely different module that does something else.
https://nodejs.org/api/dns.html vs https://www.npmjs.com/package/dns
This error most likely means you are trying to do something from the client-side that needs to be done on the server-side. If MongoDB module can't find the DNS component, it's running on the client-side.
MongoDB has to run on the server. In order to access data from React dynamically you'll need to set up an API using something like Express or Apollo.
Update:
A great way to do this is with Azure Functions (TypeScript) or AWS (Lambda) functions
For anyone who encounters this Error while importing the clientPromise (like in the with-mongodb template):
Make sure you're in the /pages/ directory!
It won't work in other directories like /components.
(and you should take a break or get some coffee...)
The problem is that you are trying to connect to the database from the front end. If this were possible that would open up a whole world of security issues. You need to set up your database connections on the backend and then have the front end make requests to the backend to handle the database.
I solved this by installing and using 'bson' instead of 'mongodb' for the client part of the code. 'bson' has a tiny bit of what 'mongodb' has and it might have what you are looking for. 'bson' is built for the browser.
In my case I needed the "ObjectId" in the browser and pulling it in from 'bson' did the trick as I didn't want to reference 'mongodb' because of the error described in the OP.
The other answers are also correct depending on why you're getting this error.
I think - mongo package is meant to be run on servers only, not in the browser.
It does not work in Next.js pages file components too, but does work in getStaticProps, getServerSideProps, getStaticPaths etc - because they run on the server, not the client.
Alternative - use Firebase Realtime database, you can access it in client-side code too. Example - a website (say a React app) that is hosted on GitHub pages or some other static server, but doesn't have a web app server (aka backend).
welcome to stack overflow.
You need to understand and learn few basics of web-applications. There's frontend, backend and a layer between them and a layer between backend and database. Frontend includes react.js, angular.js or anything else that is on browser. Backend is used to take request from frontend, providing API's to frontend and ask for data from other API's or database. Database includes sql, no-sql.
The error you are facing if of a NPM module mongodb-core.js. Either it's not installed properly, or installed using wrong version of module which is not comparable with your node version, or wrong version of NPM, or module using another NPM module which is not installed.
The issue in your case is mongodb-core uses a module dns which is not been installed. Try to install dns with npm i dns. or remove and install mongodb-core again.

Problems with create-react-kotlin-app and backend

Question
I want to deploy my application on the server in production but I am struggling to do so.
When I use npm run build to produce an "Optimized" version of the app and launch it with serve, it doesn't seem to use the proxy.
Going back to the dev server with npm start, I get this error:
TypeError: Kotlin.defineModule is not a function
I cannot get out of this. Has someone got a similar configuration? How did you make it work in production? Do you use something to proxy the requests to your backend?
App configuration
Frontend:
Web app using create-react-kotlin-app in kotlin, react. It's on localhost:3000 (dev-server) and has a proxy to localhost:3001 (the backend).
Backend
Backend, which is a simple express router for auth and data managment from the database.
Thanks in advance
I'll go back and answer my question,
One is a bug on their side:
https://youtrack.jetbrains.com/issue/CRKA-66
I'm using a config that maybe is not ideal:
I copy the build folder that contains the optimized folder into the backend and I serve the main view "index.html" as an entry point using sendFile().
I then use the url and args to route the user into various react components pages, maybe in the future it's best to switch to: https://github.com/JetBrains/kotlin-wrappers/tree/master/kotlin-react-router-dom
according with the repo documentation, if you are getting Kotlin.defineModule is not a function you would need to run:
rm -rf node_modules/.cache

Twilio Client Javascript SDK

I'd like to know why there isn't a npm / yarn package to Twilio Client Javascript SDK 1.4.
I'm trying to use their voice service, following this tutorial, but in React Native.
Is this package for browser usage only? How could I have access to Twilio.Client on react-native?
I already implemented a programmable-chat with success, using the provided packages twilio-chat and twilio-common.
Meanwhile, is there any way of importing a remote file or using a local javascript file (twilio.min.js) to a react-native app?
Thanks in advance.
EDIT:
Further research lead me to believe that this SDK only work for browsers since it has to deal with audio events, connection status etc.
Correct me if I'm wrong.
I'm now trying to implement react-native-twilio-programmable-voice
.

Stuck with integrating Braintree with Meteor.js

So, I used sudo npm install -g braintree to install the package to a clean meteor project and have the following code:
if (Meteor.isClient){
Meteor.call('getBraintree')
braintree.setup("/* very long client token */", 'dropin', {
container: 'dropin'
});
};
if (Meteor.isServer) {
Meteor.startup(function(){
var braintreeApi = Meteor.npmRequire('braintree'),
gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "merchantId",
publicKey: "publicKey",
privateKey: "privateKey"
});
});
Meteor.methods({
'getBraintree': function getBraintree(){
var braintreeWeb = Meteor.npmRequire('braintree-web');
}
});
};
...and braintree is not defined # braintree.connect({ (I have sandbox access and all my keys in order). If I used npm to install the package to my Meteor directory, is there anything further that I'd have to do to my packages.js file as shown here, considering npm now works with meteor in v1? More generally, how do I configure a project so npm packages can be installed and used?
Edit: code is updated as of 12/11
Disclaimer: I work for Braintree :) Always feel free to reach out to our support if you are having issues with your integration.
Update: I've created an extremely basic Braintree and Meteor example application that may be of some help you.
Another disclaimer: I know very little about Meteor. I'll try to answer the broader non-meteor specific issues, and update with more meteor specific information if I can get it. Here are few potential issues:
You need both the client and the server side modules for a Braintree integration, braintree is the server-side (node) Braintree library and braintree-web is the client side package. I am not sure on the specifics of consuming a client side npm module in Meteor, so it may be easier for you to use a tool like bower or to hot link to the client side javascript by placing a script tag on your page:
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
braintree.connect is a server side method, and as such should only be called on the server (probably once during startup). You'll need it to generate a clientToken to be used on the client side. I have very little experience with Meteor, but I think it is suitable to call braintree.connect within Meteor.startup on the server:
// a better pattern would be to place this in a server/index.js file
// within your project, which Meteor knows to load as server only code
Meteor.startup(function () {
if (Meteor.isServer) {
var braintree = Meteor.npmRequire('braintree');
gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
publicKey: process.env.BT_PUBLIC_KEY,
privateKey: process.env.BT_PRIVATE_KEY,
merchantId: process.env.BT_MERCHANT_ID
});
}
});
braintree.setup should only be run on the client side, it is what interacts with the form on the client side.
Braintree has two packages on npm. One is for the server-side and the other is for client side.
https://www.npmjs.com/package/braintree will provide the server code (var gateway = braintree.connect…)
https://www.npmjs.com/package/braintree-web on the other hand, will provide the code for running in the browser (braintree.setup("/*very long client token*/", 'dropin', {).
In the case of meteor, you may need to include both packages. (Make sure to double check that your private key is kept secret on your server! It may be helpful to use the /server special directory to serve this purpose.)
require is not available inside Meteor like that. Use this package https://github.com/meteorhacks/npm to use npm packages.
Here is a package that is Synchronously Wrapped for meteor and Braintree https://atmospherejs.com/patrickml/braintree

Categories

Resources