mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
stripe payment details
This commit is contained in:
@@ -474,6 +474,13 @@
|
|||||||
:href="'https://www.paypal.com/billing/subscriptions/' + paymentDetails.customerId">
|
:href="'https://www.paypal.com/billing/subscriptions/' + paymentDetails.customerId">
|
||||||
PayPal Dashboard
|
PayPal Dashboard
|
||||||
</a>
|
</a>
|
||||||
|
<a
|
||||||
|
v-else-if="hero.purchased.plan.paymentMethod === 'Stripe'"
|
||||||
|
class="btn btn-primary btn-sm"
|
||||||
|
target="_blank"
|
||||||
|
:href="'https://dashboard.stripe.com/customers/' + paymentDetails.customerId">
|
||||||
|
Stripe Dashboard
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import {
|
|||||||
import apple from '../../libs/payments/apple';
|
import apple from '../../libs/payments/apple';
|
||||||
import google from '../../libs/payments/google';
|
import google from '../../libs/payments/google';
|
||||||
import paypal from '../../libs/payments/paypal';
|
import paypal from '../../libs/payments/paypal';
|
||||||
|
import {
|
||||||
|
getSubscriptionPaymentDetails as getStripeSubscriptionPaymentDetails,
|
||||||
|
} from '../../libs/payments/stripe/subscriptions';
|
||||||
|
|
||||||
const api = {};
|
const api = {};
|
||||||
|
|
||||||
@@ -221,7 +224,7 @@ api.validateSubscriptionPaymentDetails = {
|
|||||||
} else if (user.purchased.plan.paymentMethod === 'Paypal') {
|
} else if (user.purchased.plan.paymentMethod === 'Paypal') {
|
||||||
paymentDetails = await paypal.getSubscriptionPaymentDetails({ user });
|
paymentDetails = await paypal.getSubscriptionPaymentDetails({ user });
|
||||||
} else if (user.purchased.plan.paymentMethod === 'Stripe') {
|
} else if (user.purchased.plan.paymentMethod === 'Stripe') {
|
||||||
throw new NotFound(res.t('stripeSubscriptionNotValidated'));
|
paymentDetails = await getStripeSubscriptionPaymentDetails(user);
|
||||||
} else if (user.purchased.plan.paymentMethod === 'Amazon Payments') {
|
} else if (user.purchased.plan.paymentMethod === 'Amazon Payments') {
|
||||||
throw new NotFound(res.t('amazonSubscriptionNotValidated'));
|
throw new NotFound(res.t('amazonSubscriptionNotValidated'));
|
||||||
} else if (user.purchased.plan.paymentMethod === 'Gift') {
|
} else if (user.purchased.plan.paymentMethod === 'Gift') {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
BadRequest,
|
BadRequest,
|
||||||
NotFound,
|
NotFound,
|
||||||
} from '../../errors';
|
} from '../../errors';
|
||||||
|
import { payment } from 'paypal-rest-sdk';
|
||||||
|
|
||||||
export async function checkSubData (sub, isGroup = false, coupon) {
|
export async function checkSubData (sub, isGroup = false, coupon) {
|
||||||
if (!sub || !sub.canSubscribe) throw new BadRequest(shared.i18n.t('missingSubscriptionCode'));
|
if (!sub || !sub.canSubscribe) throw new BadRequest(shared.i18n.t('missingSubscriptionCode'));
|
||||||
@@ -33,6 +34,26 @@ export async function checkSubData (sub, isGroup = false, coupon) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getSubscriptionPaymentDetails (user) {
|
||||||
|
const stripeApi = getStripeApi();
|
||||||
|
|
||||||
|
const { plan } = user.purchased;
|
||||||
|
const customer = await stripeApi.customers.retrieve(plan.customerId);
|
||||||
|
const paymentIntents = await stripeApi.paymentIntents.search({
|
||||||
|
query: `customer:'${plan.customerId}'`,
|
||||||
|
});
|
||||||
|
const lastPayment = paymentIntents.data.length > 0
|
||||||
|
? paymentIntents.data[0]
|
||||||
|
: null;
|
||||||
|
console.log(paymentIntents.data);
|
||||||
|
console.log(customer);
|
||||||
|
return {
|
||||||
|
customerId: customer.id,
|
||||||
|
originalPurchaseDate: new Date(Number(customer.created) * 1000),
|
||||||
|
lastPaymentDate: new Date(Number(lastPayment.created) * 1000),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function applySubscription (session) {
|
export async function applySubscription (session) {
|
||||||
const { metadata, customer: customerId, subscription: subscriptionId } = session;
|
const { metadata, customer: customerId, subscription: subscriptionId } = session;
|
||||||
const {
|
const {
|
||||||
|
|||||||
Reference in New Issue
Block a user