Add Donation-button, Need to connect stripe

This commit is contained in:
PascalMarchesseault
2024-08-12 12:46:57 -04:00
parent 9982ef86e0
commit 071b65b89e
4 changed files with 142 additions and 3 deletions

View File

@@ -48,8 +48,20 @@
<div v-if="data && data.description"> <div v-if="data && data.description">
Description: {{ data.description }} Description: {{ data.description }}
</div> </div>
</div>
<div class="flex justify-around py-2">
<v-btn variant="plain" icon @click="likeContent">
<v-icon :color="'#313131'">mdi-thumb-up-outline</v-icon>
</v-btn>
<v-btn variant="plain" icon @click="dislikeContent">
<v-icon :color="'#000000'">mdi-thumb-down-outline</v-icon>
</v-btn>
<v-btn variant="plain" icon @click="donate">
<v-icon :color="'#7D0863'">mdi-gift-outline</v-icon>
</v-btn>
</div>
</div>
<div class="border-b-2 p-6"> <div class="border-b-2 p-6">
<h2 class="font-sans font-semibold">Commentaires</h2> <h2 class="font-sans font-semibold">Commentaires</h2>

View File

@@ -63,7 +63,7 @@
<subscribe-button :creator="creator"></subscribe-button> <subscribe-button :creator="creator"></subscribe-button>
</div> </div>
<donation-button :creator="creator"></donation-button>
<div class="flex flex-row align-center"> <div class="flex flex-row align-center">
@@ -85,6 +85,7 @@
import CreatorAbout from "@/views/creators/CreatorAbout.vue"; import CreatorAbout from "@/views/creators/CreatorAbout.vue";
import SubscribeButton from "@/views/creators/SubscribeButton.vue"; import SubscribeButton from "@/views/creators/SubscribeButton.vue";
import PublishContentButton from "@/views/contents/PublishContentButton.vue"; import PublishContentButton from "@/views/contents/PublishContentButton.vue";
import DonationButton from "@/views/creators/donation-button.vue";
const props = defineProps({ const props = defineProps({
creator: {type: Object, required: true}, creator: {type: Object, required: true},

View File

@@ -0,0 +1,124 @@
<template>
<v-btn variant="text" icon class="text-white" @click="donationModal = true">
<v-icon class="text-2xl">mdi-gift-outline</v-icon>
</v-btn>
<v-dialog v-model="donationModal" max-width="500">
<v-form>
<v-card class="text-center rounded-xl" :style="{ border: `3px solid ${creator.colors.menu}` }">
<div class="py-4 text-2xl font-bold border-b mb-2">
Je Soutiens!
</div>
<div class="flex flex-row align-center px-3">
<img
:src="creator.images.logo"
alt="Profile Image"
class="rounded-full"
width="40"
height="40"
:style="{ border: `2px solid ${creator.colors.accent}` }">
<div class="capitalize px-2 text-2xl">{{ creator.name }}</div>
<v-btn icon @click="donationModal = false" class="ml-auto" variant="text">
<v-icon>mdi-close</v-icon>
</v-btn>
</div>
<v-card-text>
<v-text-field v-model="price"
class="p-2"
label="Montant"
density="comfortable"
variant="outlined"
hide-details
clearable
></v-text-field>
<v-textarea v-model="tipMessage"
label="Message (facultatif)"
class="p-2"
density="comfortable"
variant="outlined"
hide-details
clearable
></v-textarea>
<v-btn variant="outlined" :style="{ borderColor: creator.colors.menu, color: creator.colors.menu }" @click="goPay()" class="w-full mt-5">
Envoyez
</v-btn>
</v-card-text>
</v-card>
</v-form>
</v-dialog>
<v-dialog v-model="isPaymentDialogActive" max-width="720" persistent>
<template v-slot:default>
<v-card>
<div id="checkout">
<!-- Checkout will insert the payment form here -->
</div>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn block class="ma-auto" style="width: 200px;" text @click="closeDialog()">Annuler</v-btn>
</v-card-actions>
</v-card>
</template>
</v-dialog>
</template>
<script setup>
import {useClient} from '@/plugins/api.js';
import {loadStripe} from '@stripe/stripe-js';
import {onMounted, ref} from 'vue';
const donationModal = ref(false);
const isPaymentDialogActive = ref(false); // Ajout de cette ligne
const price = ref(0);
const tipMessage = ref("");
let stripe = null;
let checkout;
const client = useClient();
const props = defineProps({
creator: {type: Object, required: true},
});
onMounted(async () => {
stripe = await loadStripe(import.meta.env.VITE_STRIPE_API_KEY);
});
const fetchClientSecret = async () => {
const clientSecret = await createCheckoutSession();
return clientSecret;
};
async function createCheckoutSession() {
let clientSecret = await client.post('/api/Stripe', {
amount: (price.value * 100),
tipMessage: tipMessage.value,
creatorId: props.creatorId
});
let secret = clientSecret["data"];
return secret;
}
function closeDialog() {
isPaymentDialogActive.value = false;
if (checkout) {
checkout.destroy();
}
}
async function goPay() {
isPaymentDialogActive.value = true;
checkout = await stripe.initEmbeddedCheckout({
fetchClientSecret,
});
await checkout.mount('#checkout');
}
</script>

View File

@@ -23,6 +23,8 @@
</div> </div>
</template> </template>
<script setup> <script setup>
defineProps({ defineProps({
video: { video: {