diff --git a/src/controllers/payments/paypalBillingSetup.js b/src/controllers/payments/paypalBillingSetup.js index c286313ae5..38b70c0101 100644 --- a/src/controllers/payments/paypalBillingSetup.js +++ b/src/controllers/payments/paypalBillingSetup.js @@ -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; } \ No newline at end of file