|
|
@@ -107,6 +107,7 @@
|
|
|
color="tertiary"
|
|
|
expand="block"
|
|
|
class="mx-4 mt-8 font-bold"
|
|
|
+ @click="onClickPay"
|
|
|
>
|
|
|
${{ plans[selectedPlan].price }} Pay Now
|
|
|
</IonButton>
|
|
|
@@ -129,7 +130,7 @@
|
|
|
<IonContent>
|
|
|
<iframe
|
|
|
class="h-full w-full border-none"
|
|
|
- src="https://shorts.izouma.com/stripe-checkout"
|
|
|
+ :src="payUrl"
|
|
|
></iframe>
|
|
|
</IonContent>
|
|
|
</IonModal>
|
|
|
@@ -166,7 +167,12 @@ import { useElementBounding } from "@vueuse/core";
|
|
|
import { useRoute } from "vue-router";
|
|
|
import http from "@/plugins/http";
|
|
|
import { close, chevronBack } from "ionicons/icons";
|
|
|
+import toast from "@/plugins/toast";
|
|
|
+import { useUserStore } from "@/store/user";
|
|
|
+import { storeToRefs } from "pinia";
|
|
|
+import emitter from "@/events";
|
|
|
|
|
|
+const { user } = storeToRefs(useUserStore());
|
|
|
const el = ref<HTMLElement | null>(null);
|
|
|
const { x, y, top, right, bottom, left, width, height } =
|
|
|
useElementBounding(el);
|
|
|
@@ -238,19 +244,57 @@ const plans = [
|
|
|
title: "7 Days",
|
|
|
desc: "Unlimited",
|
|
|
price: 0.99,
|
|
|
+ value: 7,
|
|
|
},
|
|
|
{
|
|
|
title: "1 Month",
|
|
|
desc: "Unlimited",
|
|
|
price: 19.99,
|
|
|
+ value: 30,
|
|
|
},
|
|
|
{
|
|
|
title: "3 Months",
|
|
|
desc: "Unlimited",
|
|
|
price: 49.99,
|
|
|
+ value: 90,
|
|
|
},
|
|
|
];
|
|
|
const selectedPlan = ref(0);
|
|
|
-const showCheckoutModal = ref(true);
|
|
|
+const showCheckoutModal = ref(false);
|
|
|
+window.addEventListener("message", async (event) => {
|
|
|
+ console.log(event);
|
|
|
+ if (event.data === "success") {
|
|
|
+ await http.post("/memberships", {
|
|
|
+ userId: user.value!.id,
|
|
|
+ expireAt: new Date(
|
|
|
+ new Date().getTime() +
|
|
|
+ plans[selectedPlan.value].value * 24 * 60 * 60 * 1000
|
|
|
+ ),
|
|
|
+ });
|
|
|
+ toast("Payment successful", {
|
|
|
+ type: "success",
|
|
|
+ });
|
|
|
+ showCheckoutModal.value = false;
|
|
|
+ emitter.emit('payment-success')
|
|
|
+ } else if (event.data === "fail") {
|
|
|
+ toast("Payment failed", {
|
|
|
+ type: "error",
|
|
|
+ });
|
|
|
+ showCheckoutModal.value = false;
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+const payUrl = ref("http://192.168.50.202:5174/stripe-checkout/");
|
|
|
+function onClickPay() {
|
|
|
+ showPayModal.value = false;
|
|
|
+ setTimeout(() => {
|
|
|
+ payUrl.value = "http://192.168.50.202:5174/stripe-checkout/";
|
|
|
+ showCheckoutModal.value = true;
|
|
|
+ }, 200);
|
|
|
+}
|
|
|
</script>
|
|
|
-<style lang="less" scoped></style>
|
|
|
+<style lang="less" scoped>
|
|
|
+.pay-modal {
|
|
|
+ --height: 50vh;
|
|
|
+}
|
|
|
+</style>
|