refactor(paypal): some plan debugging cleanup

This commit is contained in:
Tyler Renelle
2014-12-04 15:27:44 -07:00
parent c9b0898499
commit f3fc6644b8
+21 -4
View File
@@ -8,8 +8,10 @@ var nconf = require('nconf');
_ = require('lodash');
nconf.argv().env().file('user', path.join(path.resolve(__dirname, '../../../config.json')));
var paypal = require('paypal-rest-sdk');
var OP = "create"; // list create update remove
var blocks = require('habitrpg-shared').content.subscriptionBlocks;
var live = nconf.get('PAYPAL:mode')=='live';
var OP = 'get'; // list create update remove
paypal.configure({
'mode': nconf.get("PAYPAL:mode"), //sandbox or live
@@ -25,8 +27,8 @@ var billingPlanAttributes = {
"type": "INFINITE",
"merchant_preferences": {
"auto_bill_amount": "yes",
"cancel_url": nconf.get("BASE_URL"),
"return_url": nconf.get('BASE_URL') + '/paypal/subscribe/success'
"cancel_url": live ? 'https://habitrpg.com' : 'http://localhost:3000',
"return_url": (live ? 'https://habitrpg.com' : 'http://localhost:3000') + '/paypal/subscribe/success'
},
payment_definitions: [{
"type": "REGULAR",
@@ -52,7 +54,22 @@ switch(OP) {
console.log({err:err, plans:plans});
});
break;
case "get":
paypal.billingPlan.get(nconf.get("PAYPAL:billing_plans:12"), function (err, plan) {
console.log({err:err, plan:plan});
})
break;
case "update":
var update = {
"op": "replace",
"path": "/merchant_preferences",
"value": {
"cancel_url": "https://habitrpg.com"
}
};
paypal.billingPlan.update(nconf.get("PAYPAL:billing_plans:12"), update, function (err, res) {
console.log({err:err, plan:res});
});
break;
case "create":
paypal.billingPlan.create(blocks["12"].definition, function(err,plan){
@@ -71,6 +88,6 @@ switch(OP) {
console.log({err:err, response:response, id:plan.id});
});
});
case "remove":
break;
case "remove": break;
}