Created
February 11, 2015 23:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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