diff --git a/config.json.example b/config.json.example index 2af6b432ca..c217657c43 100644 --- a/config.json.example +++ b/config.json.example @@ -66,7 +66,8 @@ }, "mode":"sandbox", "client_id":"client_id", - "client_secret":"client_secret" + "client_secret":"client_secret", + "experience_profile_id": "" }, "IAP_GOOGLE_KEYDIR": "/path/to/google/public/key/dir/", "LOGGLY_TOKEN": "token", diff --git a/scripts/paypalBillingSetup.js b/scripts/paypalBillingSetup.js index d21cd80c1c..78fcedce2e 100644 --- a/scripts/paypalBillingSetup.js +++ b/scripts/paypalBillingSetup.js @@ -1,3 +1,5 @@ +require("babel-register"); +require("babel-polyfill"); // This file is used for creating paypal billing plans. PayPal doesn't have a web interface for setting up recurring // payment plan definitions, instead you have to create it via their REST SDK and keep it updated the same way. So this // file will be used once for initing your billing plan (then you get the resultant plan.id to store in config.json), @@ -7,10 +9,10 @@ var path = require('path'); var nconf = require('nconf'); var _ = require('lodash'); var paypal = require('paypal-rest-sdk'); -var blocks = require('../../../../common').content.subscriptionBlocks; +var blocks = require('../website/common').content.subscriptionBlocks; var live = nconf.get('PAYPAL:mode')=='live'; -nconf.argv().env().file('user', path.join(path.resolve(__dirname, '../../../config.json'))); +nconf.argv().env().file('user', path.join(path.resolve(__dirname, '../config.json'))); var OP = 'create'; // list create update remove @@ -49,6 +51,8 @@ _.each(blocks, function(block){ }); }) +// @TODO: Add cli library for this + switch(OP) { case "list": paypal.billingPlan.list({status: 'ACTIVE'}, function(err, plans){ @@ -91,4 +95,17 @@ switch(OP) { }); break; case "remove": break; + + case 'create-webprofile': + let webexpinfo = { + "name": "HabiticaProfile", + "input_fields": { + "no_shipping": 1, + }, + }; + + paypal.webProfile.create(webexpinfo, (error, result) => { + console.log(error, result) + }) + break; } diff --git a/website/server/libs/paypalPayments.js b/website/server/libs/paypalPayments.js index 7182476e3a..6c0ccadb66 100644 --- a/website/server/libs/paypalPayments.js +++ b/website/server/libs/paypalPayments.js @@ -37,6 +37,8 @@ paypal.configure({ client_secret: nconf.get('PAYPAL:client_secret'), }); +let experienceProfileId = nconf.get('PAYPAL:experience_profile_id'); + // TODO better handling of errors // @TODO: Create constants @@ -110,6 +112,10 @@ api.checkout = async function checkout (options = {}) { }], }; + if (experienceProfileId) { + createPayment.experience_profile_id = experienceProfileId; + } + let result = await this.paypalPaymentCreate(createPayment); let link = _.find(result.links, { rel: 'approval_url' }).href; return link;