Created
April 14, 2016 08:38
-
-
Save roelvan/519dcfc43d5bc39768c4118599640a0b to your computer and use it in GitHub Desktop.
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
postRoutes.route '/api/process-payment', (params, req, res, next) -> | |
res.statusCode = 404 | |
res.setHeader 'Content-Type', 'application/x-www-form-urlencoded' | |
paymentId = req.body.id | |
console.log "====== MOLLIE BODY ======" | |
console.log req.body, params | |
console.log "====== MOLLIE BODY ======" | |
mollieApiKey = Meteor.settings.mollie.apiKey | |
mollie = new Mollie.API.Client | |
mollie.setApiKey mollieApiKey | |
mollie.payments.get paymentId, Meteor.bindEnvironment (payment) -> | |
if payment.error | |
console.error payment.error | |
statusText = "Error: #{payment.error.message}" | |
return res.end statusText | |
bookingId = payment.metadata.bookingId | |
# possible statuses: 'open', 'cancelled', 'error', 'paid', 'paidout' | |
console.log "====== MOLLIE PAYMENT ======" | |
console.log "id: #{payment.id}" | |
console.log "status: #{payment.status}" | |
console.log "bookingId: #{bookingId}" | |
console.log "====== MOLLIE PAYMENT ======" | |
if payment.isPaid() | |
Meteor.call 'markAsPaid', bookingId, (e) -> | |
if e | |
statusText = "Error: #{e.reason}" | |
return res.end statusText | |
else | |
statusText = 'Inschrijving werd als betaald gemarkeerd.' | |
res.statusCode = 200 | |
return res.end statusText | |
else | |
statusText = "Error: werd nog niet betaald, huidige status: #{payment.status}." | |
return res.end statusText |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment