[guadec-web-regcfp] Script to update paid status
- From: Patrick Uiterwijk <puiterwijk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [guadec-web-regcfp] Script to update paid status
- Date: Fri, 19 Jun 2015 13:37:22 +0000 (UTC)
commit 5103a4a1d4aeffa1b324bbb0042990e4d39e78b6
Author: Patrick Uiterwijk <puiterwijk redhat com>
Date: Fri Jun 19 15:37:12 2015 +0200
Script to update paid status
bin/payment-status-update | 47 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/bin/payment-status-update b/bin/payment-status-update
new file mode 100755
index 0000000..1bd9c96
--- /dev/null
+++ b/bin/payment-status-update
@@ -0,0 +1,47 @@
+#!/usr/bin/env node
+
+var db = require('../models/index');
+
+var env = process.env.NODE_ENV || "development";
+var config = require('../config/config.json')[env];
+var paypal = require('paypal-rest-sdk');
+paypal.configure(config['paypal']);
+
+var models = require('../models');
+var RegistrationPayment = models.RegistrationPayment;
+
+
+RegistrationPayment.findAll({
+ where: {
+ type: 'paypal'
+ }
+}).complete(function(err, payments) {
+ if(!!err) {
+ console.log("Error getting payments: " + err);
+ } else {
+ payments.forEach(function(val, index, array) {
+ console.log("Looking up payment " + val['id'] + " (" + val['details'] + ")");
+ paypal.payment.get(val['details'], function(error, payment) {
+ if(!!error) {
+ console.log("Payment " + val['id'] + " Error");
+ console.log(error);
+ } else {
+ console.log("Payment " + val['id'] + " Response: ");
+ console.log("\tPaid: " + val['paid']);
+ console.log("\tPayPal state: " + payment.state);
+
+ if(val['paid'] && payment.state != 'approved') {
+ console.log('\tNOT APPROVED, but paid');
+ val.paid = false;
+ val.save();
+ }
+ else if(!val['paid'] && payment.state == 'approved') {
+ console.log('\tApproved, but not paid');
+ val.paid = true;
+ val.save();
+ }
+ };
+ });
+ });
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]