This package is a fork of https://github.com/sandelld/meteor-paypal-extended, limiting PayPal functions to server side only for security purpose. In Sandelld's package, the PayPal functions are exposed to the client side, allowing anyone to pull card details from vault which is very dangerous.
Meteor Package for easy Paypal payment processing, extended to support the following additional features supported by the REST API:
- Store card details in the vault
- Use a stored card for a transaction
- Delete a stored card
- Lookup stored details for a specific card
- List all cards based on filter criteria
- Lookup a sale to verify it has been successful
- Refund a sale (partial/full)
If you only require basic authorisation / ability to make a payment then use the original package
meteor add 19degrees:paypal
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:
Paypal.config({
'host': 'api.sandbox.paypal.com',
'port': '',
'client_id': 'Your Paypal Client Id',
'client_secret': 'Your Paypal Client Secret'
});
Format is Paypal.*transaction_type*({ {/*card data*/}, {/*transaction data*/}, function(err, res){...})
Paypal.authorize({
name: 'Buster Bluth',
number: '4111111111111111',
type: 'visa',
cvv2: '123',
expire_year: '2015',
expire_month: '01'
},
{
total: '100.00',
currency: 'HKD'
},
function(error, results){
if(error)
//Deal with Error
else
//results contains:
// saved (true or false)
// if false: "error" contains the reasons for failure
// if true: "payment" contains the transaction information
});
For information on the payment object returned see Paypal's Payment Option Documentation
Transaction types are: Paypal.authorize
and
Paypal.purchase
for the difference, see Paypal's
Documentation
For additional information on fields, check out the Paypal REST API documentation
Store a credit card in the Vault:
var cardData = {
//name: 'Buster Bluth',
number: '4111111111111111',
type: 'visa',
cvv2: '123',
expire_year: '2015',
expire_month: '01'
external_customer_id: "123456789",
merchant_id: "company_name",
external_card_id: "abcdefghijk123457"
};
Paypal.vaultCreate(cardData, function(err, results){
if (err) console.error(err);
else console.log(results);
});
Pay with a stored card:
var cardData = { credit_card_id: "CARD-7XT34685RB132680FKVNVW2Y" }; // stored card reference
Paypal.purchase(cardData, {total: '6.50', currency: 'GBP'}, function(err, results){
if (err) console.error(err);
else console.log(results);
});
Delete a stored card
var cardRef = "CARD-7XT34685RB132680FKVNVW2Y"; // stored card reference
Paypal.vaultDelete(cardRef, function(err, results){
if (err) console.error(err);
else console.log(results);
});
Get details back for a stored card
var cardRef = "CARD-7XT34685RB132680FKVNVW2Y"; // stored card reference
Paypal.vaultGet(cardRef, function(err, results){
if (err) console.error(err);
else console.log(results);
});
Lookup card details based on a filter
var cardFilter = "?merchant_id=yourcompanyname"; // use any parameters you stored with the card
Paypal.vaultList(cardFilter, function(err, results){
if (err) console.error(err);
else console.log(results);
});
Lookup a sale
var txRef = "86P78153J2013135X"; // returned when you execute a payment
Paypal.saleLookup(txRef, function(err, results){
if (err) console.error(err);
else console.log(results);
});
Refund a sale
var txRef = "86P78153J2013135X"; // returned when you execute a payment
var refundInfo = {total: '2.00', currency: 'GBP'}
Paypal.saleRefund(txRef, refundInfo, function(err, results){
if (err) console.error(err);
else console.log(results);
});
Full credit to David Brear for building the package, I've just extended his work to include additional features that I needed for my project.