mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Added new web profile for checkout (#8699)
* Added new web profile for checkout * Fixed es6 syntax * Fixed config path
This commit is contained in:
committed by
Sabe Jones
parent
c509c8e04f
commit
19ba1290f6
@@ -66,7 +66,8 @@
|
|||||||
},
|
},
|
||||||
"mode":"sandbox",
|
"mode":"sandbox",
|
||||||
"client_id":"client_id",
|
"client_id":"client_id",
|
||||||
"client_secret":"client_secret"
|
"client_secret":"client_secret",
|
||||||
|
"experience_profile_id": ""
|
||||||
},
|
},
|
||||||
"IAP_GOOGLE_KEYDIR": "/path/to/google/public/key/dir/",
|
"IAP_GOOGLE_KEYDIR": "/path/to/google/public/key/dir/",
|
||||||
"LOGGLY_TOKEN": "token",
|
"LOGGLY_TOKEN": "token",
|
||||||
|
|||||||
@@ -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
|
// 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
|
// 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),
|
// 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 nconf = require('nconf');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var paypal = require('paypal-rest-sdk');
|
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';
|
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
|
var OP = 'create'; // list create update remove
|
||||||
|
|
||||||
@@ -49,6 +51,8 @@ _.each(blocks, function(block){
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// @TODO: Add cli library for this
|
||||||
|
|
||||||
switch(OP) {
|
switch(OP) {
|
||||||
case "list":
|
case "list":
|
||||||
paypal.billingPlan.list({status: 'ACTIVE'}, function(err, plans){
|
paypal.billingPlan.list({status: 'ACTIVE'}, function(err, plans){
|
||||||
@@ -91,4 +95,17 @@ switch(OP) {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "remove": 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ paypal.configure({
|
|||||||
client_secret: nconf.get('PAYPAL:client_secret'),
|
client_secret: nconf.get('PAYPAL:client_secret'),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let experienceProfileId = nconf.get('PAYPAL:experience_profile_id');
|
||||||
|
|
||||||
// TODO better handling of errors
|
// TODO better handling of errors
|
||||||
// @TODO: Create constants
|
// @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 result = await this.paypalPaymentCreate(createPayment);
|
||||||
let link = _.find(result.links, { rel: 'approval_url' }).href;
|
let link = _.find(result.links, { rel: 'approval_url' }).href;
|
||||||
return link;
|
return link;
|
||||||
|
|||||||
Reference in New Issue
Block a user