Just a few quick notes and hints here since I don’t have time right now to post a more complete guide about implementing PayPal in a Meteor app:
I’ve integrated with PayPal just a week ago and it definitely works. What I basically did was:
Add meteorhacks:npm for usage of npm modules.
Use PayPal’s node sdk, i.e. packages.json should contain:
{"paypal-rest-sdk": "1.5.2"}
Create a config file e.g. in server/lib:
paypal = Meteor.npmRequire('paypal-rest-sdk');
paypal.configure({
mode: 'sandbox', //sandbox or live
client_id: 'yourclientid',
client_secret: 'yoursecret'
});
Use methods paypal.payment.create and paypal.payment.execute for communication with the PayPal API, something like this:
var ppCreate = Meteor.wrapAsync(paypal.payment.create.bind(paypal.payment));
var ppExecute = Meteor.wrapAsync(paypal.payment.execute.bind(paypal.payment));
Then you can use both of these methods something like this:
var response = ppCreate( ... paypal json/object just like in the SDK docs and samples ...);
if (resp.state !== 'created') {
... error handling ...
}
And then using iron:router create a URL that PayPal can redirect the user to after successful authorization of the payment (or cancellation):
Router.route('/payment/paypal/callback/:action', {
name: 'paymentPaypalCallback'
});
Which reflects the paths you submitted to the PayPal API in the request json:
...
redirect_urls: {
return_url: Meteor.absoluteUrl('payment/paypal/callback/execute', {replaceLocalhost: true}),
cancel_url: Meteor.absoluteUrl('payment/paypal/callback/cancel', {replaceLocalhost: true})
}
...
The replaceLocahost: true
is important for trying things out with the app running on localhost; without that setting PayPal won’t redirect the user back to your app since it will accept 127.0.0.1 but not localhost (at least that’s how I understand it).
What PayPal will do is not call an additional route on your server, but simply redirect the user with enough additional params that you can properly identify and verify, and then execute
that payment.
Is that clear enough and does that help?
I initially also considered using the meteor-paypal package, but I looked at the source and found it to be so simple and thought I could write my own code in a way that suited me and the application better, and so I did, and it was the right choice. That package also just used the paypal-rest-sdk
npm module and provider a very thin wrapper around it.