mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
* Added payment to groups and pay with group plan with Stripe * Added edit card for Stripe * Added stripe cancel * Added subscribe with Amazon payments * Added Amazon cancel for group subscription * Added group subscription with paypal * Added paypal cancel * Added ipn cancel for Group plan * Added a subscription tab and hid only the task tab when group is not subscribed * Fixed linting issues * Fixed tests * Added payment unit tests * Added back refresh after stripe payment * Fixed style issues * Limited grouop query fields and checked access * Abstracted subscription schema * Added year group plan and more access checks * Maded purchase fields private * Removed id and timestampes * Added else checks to ensure user subscription is not altered. Removed active field from group model * Added toJSONTransform function * Moved plan active check to other toJson function * Added check to see if purchaed has been populated * Added purchase details to private * Added correct data usage when paying for group sub
65 lines
2.9 KiB
JavaScript
65 lines
2.9 KiB
JavaScript
import amazonPayments from 'amazon-payments';
|
|
import nconf from 'nconf';
|
|
import common from '../../common';
|
|
import Bluebird from 'bluebird';
|
|
import {
|
|
BadRequest,
|
|
} from './errors';
|
|
|
|
// TODO better handling of errors
|
|
|
|
const i18n = common.i18n;
|
|
const IS_PROD = nconf.get('NODE_ENV') === 'production';
|
|
|
|
let amzPayment = amazonPayments.connect({
|
|
environment: amazonPayments.Environment[IS_PROD ? 'Production' : 'Sandbox'],
|
|
sellerId: nconf.get('AMAZON_PAYMENTS:SELLER_ID'),
|
|
mwsAccessKey: nconf.get('AMAZON_PAYMENTS:MWS_KEY'),
|
|
mwsSecretKey: nconf.get('AMAZON_PAYMENTS:MWS_SECRET'),
|
|
clientId: nconf.get('AMAZON_PAYMENTS:CLIENT_ID'),
|
|
});
|
|
|
|
let getTokenInfo = Bluebird.promisify(amzPayment.api.getTokenInfo, {context: amzPayment.api});
|
|
let createOrderReferenceId = Bluebird.promisify(amzPayment.offAmazonPayments.createOrderReferenceForId, {context: amzPayment.offAmazonPayments});
|
|
let setOrderReferenceDetails = Bluebird.promisify(amzPayment.offAmazonPayments.setOrderReferenceDetails, {context: amzPayment.offAmazonPayments});
|
|
let confirmOrderReference = Bluebird.promisify(amzPayment.offAmazonPayments.confirmOrderReference, {context: amzPayment.offAmazonPayments});
|
|
let closeOrderReference = Bluebird.promisify(amzPayment.offAmazonPayments.closeOrderReference, {context: amzPayment.offAmazonPayments});
|
|
let setBillingAgreementDetails = Bluebird.promisify(amzPayment.offAmazonPayments.setBillingAgreementDetails, {context: amzPayment.offAmazonPayments});
|
|
let getBillingAgreementDetails = Bluebird.promisify(amzPayment.offAmazonPayments.getBillingAgreementDetails, {context: amzPayment.offAmazonPayments});
|
|
let confirmBillingAgreement = Bluebird.promisify(amzPayment.offAmazonPayments.confirmBillingAgreement, {context: amzPayment.offAmazonPayments});
|
|
let closeBillingAgreement = Bluebird.promisify(amzPayment.offAmazonPayments.closeBillingAgreement, {context: amzPayment.offAmazonPayments});
|
|
|
|
let authorizeOnBillingAgreement = (inputSet) => {
|
|
return new Promise((resolve, reject) => {
|
|
amzPayment.offAmazonPayments.authorizeOnBillingAgreement(inputSet, (err, response) => {
|
|
if (err) return reject(err);
|
|
if (response.AuthorizationDetails.AuthorizationStatus.State === 'Declined') return reject(new BadRequest(i18n.t('paymentNotSuccessful')));
|
|
return resolve(response);
|
|
});
|
|
});
|
|
};
|
|
|
|
let authorize = (inputSet) => {
|
|
return new Promise((resolve, reject) => {
|
|
amzPayment.offAmazonPayments.authorize(inputSet, (err, response) => {
|
|
if (err) return reject(err);
|
|
if (response.AuthorizationDetails.AuthorizationStatus.State === 'Declined') return reject(new BadRequest(i18n.t('paymentNotSuccessful')));
|
|
return resolve(response);
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
getTokenInfo,
|
|
createOrderReferenceId,
|
|
setOrderReferenceDetails,
|
|
confirmOrderReference,
|
|
closeOrderReference,
|
|
confirmBillingAgreement,
|
|
getBillingAgreementDetails,
|
|
setBillingAgreementDetails,
|
|
closeBillingAgreement,
|
|
authorizeOnBillingAgreement,
|
|
authorize,
|
|
};
|