Skip to content

Instantly share code, notes, and snippets.

@sergical
Created February 11, 2015 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergical/38573459644a1a5ebd00 to your computer and use it in GitHub Desktop.
Save sergical/38573459644a1a5ebd00 to your computer and use it in GitHub Desktop.
This is my method in Meteor when a user tries to pay the invoice. I want to be able to set up a custom email receipt but I don't know where to start.
Meteor.methods({
payInvoice: function (token, transfer) {
// TODO: add checks
console.log('=== Pay Invoive ===');
console.log(token);
console.log(JSON.stringify(transfer, null, 2));
console.log('===================');
var Stripe = StripeAPI(transfer.invoice.stripe.accessToken);
var charge = Stripe.charges.create({
amount: transfer.invoice.grandTotal * 100,
currency: "usd",
card: token.id,
// XXX: Update application fee rate
application_fee: transfer.invoice.total * 2 + 20,
receipt_email: transfer.recipientEmail,
description: 'Payment to ' + transfer.senderEmail
}, transfer.invoice.stripe.accessToken, Meteor.bindEnvironment(function(err, charge) {
if (err && err.type === 'StripeCardError') {
// The card has been declined
console.log('The card has been declined');
}
if (err) {
console.log(err);
}
console.log(charge);
Transfers.update(transfer._id, {$set: {"invoice.stripe.chargeToken": charge}});
return transfer._id;
}));
},
//etc
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment