Files
habitica/website/client/mixins/payments.js
Keith Holliday 0233f7b486 More fixes (#8988)
* Links stay white on hover

* Fixed task icon color

* Disabled plus button when needed

* Fixed difficulty color

* Fixed task reward color

* Updated create styles

* Fixed group plan link

* Fixed second group test modal

* Added login incentives

* Fixed group notification clear

* Show baily correctly

* Styled armoire notification

* Fixed contributor achievement styles

* Fixed death

* Fixed drop styles

* Fixed invited friend modal

* Fixed joined challenge achievement style

* Fixed joined guild style

* Fixed level up styles

* Updated low health styles

* Fixed bailey styles

* Updated quest completed

* Added soem conditionals to hide modals

* Added rebirth styles

* Fixed rebirth enable styles

* Fixed streak styles

* Fixed testing modals

* Fixed ultimate gear achievement

* Fixed won challenge

* Set user to welcomed if created on mobile

* Removed old default tasks

* Began adding more options to avatar

* Added change class

* Inbox to messages

* Moved profile to menu

* Added user modal for viewing a user and send message

* Fixed conversations

* Fixed lint

* Fixed challenges sending to server

* Added challenge progress view

* Fixed group sync after pay

* Fixed some group accepting features

* Fixed initial chat loading

* Fixed some exitence errors

* Added user names to assigned

* Added upgrade link

* Began adding new payment flow

* Added default tasks

* Updated avatar styles

* Updated tutorial styles

* Rebuilt notifications and styles

* Updated upload script

* Fixed lint

* Added default tasks back to mobile and added updated tests

* More test fixes
2017-08-25 20:56:21 -06:00

107 lines
3.4 KiB
JavaScript

import axios from 'axios';
const STRIPE_PUB_KEY = process.env.STRIPE_PUB_KEY; // eslint-disable-line
import subscriptionBlocks from '../../common/script/content/subscriptionBlocks';
export default {
methods: {
showStripe (data) {
if (!this.checkGemAmount(data)) return;
let sub = false;
if (data.subscription) {
sub = data.subscription;
} else if (data.gift && data.gift.type === 'subscription') {
sub = data.gift.subscription.key;
}
sub = sub && subscriptionBlocks[sub];
let amount = 500;// 500 = $5
if (sub) amount = sub.price * 100;
if (data.gift && data.gift.type === 'gems') amount = data.gift.gems.amount / 4 * 100;
if (data.group) amount = (sub.price + 3 * (data.group.memberCount - 1)) * 100;
this.StripeCheckout.open({
key: STRIPE_PUB_KEY,
address: false,
amount,
name: 'Habitica',
description: sub ? this.$t('subscribe') : this.$t('checkout'),
image: '/apple-touch-icon-144-precomposed.png',
panelLabel: sub ? this.$t('subscribe') : this.$t('checkout'),
token: async (res) => {
let url = '/stripe/checkout?a=a'; // just so I can concat &x=x below
if (data.groupToCreate) {
url = '/api/v3/groups/create-plan?a=a';
res.groupToCreate = data.groupToCreate;
res.paymentType = 'Stripe';
}
if (data.gift) url += `&gift=${this.encodeGift(data.uuid, data.gift)}`;
if (data.subscription) url += `&sub=${sub.key}`;
if (data.coupon) url += `&coupon=${data.coupon}`;
if (data.groupId) url += `&groupId=${data.groupId}`;
let response = await axios.post(url, res);
let responseStatus = response.status;
if (responseStatus >= 400) {
alert(`Error: ${response.message}`);
return;
}
let newGroup = response.data.data;
if (newGroup && newGroup._id) {
// @TODO: Just append? or $emit?
this.$router.push(`/group-plans/${newGroup._id}/task-information`);
this.user.guilds.push(newGroup._id);
return;
}
window.location.reload(true);
},
});
},
checkGemAmount (data) {
let isGem = data && data.gift && data.gift.type === 'gems';
let notEnoughGem = isGem && (!data.gift.gems.amount || data.gift.gems.amount === 0);
if (notEnoughGem) {
Notification.error(this.$t('badAmountOfGemsToPurchase'), true);
return false;
}
return true;
},
amazonPaymentsInit (data) {
// @TODO: Do we need this? if (!this.isAmazonReady) return;
if (!this.checkGemAmount(data)) return;
if (data.type !== 'single' && data.type !== 'subscription') return;
if (data.gift) {
if (data.gift.gems && data.gift.gems.amount && data.gift.gems.amount <= 0) return;
data.gift.uuid = data.giftedTo;
}
if (data.subscription) {
this.amazonPayments.subscription = data.subscription;
this.amazonPayments.coupon = data.coupon;
}
if (data.groupId) {
this.amazonPayments.groupId = data.groupId;
}
if (data.groupToCreate) {
this.amazonPayments.groupToCreate = data.groupToCreate;
}
this.amazonPayments.gift = data.gift;
this.amazonPayments.type = data.type;
this.$root.$emit('show::modal', 'amazon-payment');
},
},
};