mrt:paypal

v1.1.1Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Paypal for Meteor

Meteor Package for easy Paypal payment processing.

Usage

mrt add paypal

Setup

If you haven't already, sign up for a developer account at: https://developer.paypal.com/

Create a sandbox application and copy your REST API CREDENTIALS.

Create a file server/paypal_config.js including:

1  Meteor.Paypal.config({
2    'host': 'api.sandbox.paypal.com',
3    'port': '',
4    'client_id': 'Your Paypal Client Id',
5    'client_secret': 'Your Paypal Client Secret'
6  });

Basic

Format is Meteor.Paypal.*transaction_type*({ {/*card data*/}, {/*transaction data*/}, function(err, res){...})

1  Meteor.Paypal.authorize({
2      name: 'Buster Bluth',
3      number: '4111111111111111',
4      type: 'visa',
5      cvv2: '123',
6      expire_year: '2015',
7      expire_month: '01'
8    },
9    {
10      total: '100.10',
11      currency: 'USD'
12    },
13    function(error, results){
14      if(error)
15        //Deal with Error
16      else
17        //results contains:
18        //  saved (true or false)
19        //  if false: "error" contains the reasons for failure
20        //  if true: "payment" contains the transaction information
21    });

For information on the payment object returned see Paypal's Payment Option Documentation

Transaction types are: Meteor.Paypal.authorize and Meteor.Paypal.purchase for the difference, see Paypal's Documentation

Extras

Include {{> paypalCreditCardForm }} in a template. In the template's javascript file, include:

1  Template.paypalCreditCardForm.events({
2    'submit #paypal-payment-form': function(evt, tmp){
3      evt.preventDefault();
4      
5      var card_data = Template.paypalCreditCardForm.card_data();
6      
7      //Probably a good idea to disable the submit button here to prevent multiple submissions.
8      
9      Meteor.Paypal.purchase(card_data, {total: '100.50', currency: 'USD'}, function(err, results){
10        if (err) console.error(err);
11        else console.log(results);
12      });
13    }
14  });

Acknowledgements

Special Thanks to Phillip Jacobs (@phillyqueso) for his help with Fibers and Futures without which, this project would've failed.