stripe payment details

This commit is contained in:
Phillip Thelen
2025-08-11 21:54:36 +02:00
parent ba99a65bd4
commit c00aaec8e9
3 changed files with 32 additions and 1 deletions

View File

@@ -474,6 +474,13 @@
:href="'https://www.paypal.com/billing/subscriptions/' + paymentDetails.customerId">
PayPal Dashboard
</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>

View File

@@ -12,6 +12,9 @@ import {
import apple from '../../libs/payments/apple';
import google from '../../libs/payments/google';
import paypal from '../../libs/payments/paypal';
import {
getSubscriptionPaymentDetails as getStripeSubscriptionPaymentDetails,
} from '../../libs/payments/stripe/subscriptions';
const api = {};
@@ -221,7 +224,7 @@ api.validateSubscriptionPaymentDetails = {
} else if (user.purchased.plan.paymentMethod === 'Paypal') {
paymentDetails = await paypal.getSubscriptionPaymentDetails({ user });
} 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') {
throw new NotFound(res.t('amazonSubscriptionNotValidated'));
} else if (user.purchased.plan.paymentMethod === 'Gift') {

View File

@@ -17,6 +17,7 @@ import {
BadRequest,
NotFound,
} from '../../errors';
import { payment } from 'paypal-rest-sdk';
export async function checkSubData (sub, isGroup = false, coupon) {
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) {
const { metadata, customer: customerId, subscription: subscriptionId } = session;
const {