adata-ui 3.1.50 → 3.1.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +14 -1
  3. package/dist/runtime/components/SidePanel.vue +370 -0
  4. package/dist/runtime/components/SidePanel.vue.d.ts +68 -0
  5. package/dist/runtime/components/forms/input/standard/InputStandard.vue +1 -1
  6. package/dist/runtime/components/payment/process/PaymentKaspiQrSidePanel.vue +148 -0
  7. package/dist/runtime/components/payment/process/PaymentKaspiQrSidePanel.vue.d.ts +21 -0
  8. package/dist/runtime/components/payment/process/PaymentKaspiRedirectSidePanel.vue +97 -0
  9. package/dist/runtime/components/payment/process/PaymentKaspiRedirectSidePanel.vue.d.ts +20 -0
  10. package/dist/runtime/components/payment/process/PaymentMethodSidePanel.vue +106 -0
  11. package/dist/runtime/components/payment/process/PaymentMethodSidePanel.vue.d.ts +21 -0
  12. package/dist/runtime/components/payment/process/PaymentProcess.vue +112 -0
  13. package/dist/runtime/components/payment/process/PaymentProcess.vue.d.ts +2 -0
  14. package/dist/runtime/components/payment/process/PaymentTopUpSidePanel.vue +117 -0
  15. package/dist/runtime/components/payment/process/PaymentTopUpSidePanel.vue.d.ts +15 -0
  16. package/dist/runtime/composables/useAdaptive.d.ts +8 -0
  17. package/dist/runtime/composables/useAdaptive.js +27 -0
  18. package/dist/runtime/composables/usePayment.d.ts +8 -0
  19. package/dist/runtime/composables/usePayment.js +66 -0
  20. package/dist/runtime/i18n/i18n.config.d.ts +120 -0
  21. package/dist/runtime/icons/chevron/chevron-down.vue +16 -0
  22. package/dist/runtime/icons/chevron/chevron-down.vue.d.ts +2 -0
  23. package/dist/runtime/icons/chevron/chevron-left.vue +5 -0
  24. package/dist/runtime/icons/chevron/chevron-left.vue.d.ts +2 -0
  25. package/dist/runtime/icons/chevron/chevron-right.vue +5 -0
  26. package/dist/runtime/icons/chevron/chevron-right.vue.d.ts +2 -0
  27. package/dist/runtime/icons/chevron/chevron-up.vue +5 -0
  28. package/dist/runtime/icons/chevron/chevron-up.vue.d.ts +2 -0
  29. package/dist/runtime/icons/chevron/double-chevron-right.vue +12 -0
  30. package/dist/runtime/icons/chevron/double-chevron-right.vue.d.ts +2 -0
  31. package/dist/runtime/icons/kaspi-qr.vue +13 -0
  32. package/dist/runtime/icons/kaspi-qr.vue.d.ts +2 -0
  33. package/dist/runtime/icons/payment/payment-card.vue +6 -0
  34. package/dist/runtime/icons/payment/payment-card.vue.d.ts +2 -0
  35. package/dist/runtime/icons/payment/payment-kaspi.vue +11 -0
  36. package/dist/runtime/icons/payment/payment-kaspi.vue.d.ts +2 -0
  37. package/dist/runtime/lang/en.js +40 -0
  38. package/dist/runtime/lang/kk.js +40 -0
  39. package/dist/runtime/lang/ru.d.ts +40 -0
  40. package/dist/runtime/lang/ru.js +40 -0
  41. package/dist/runtime/plugins/toast.d.ts +24 -24
  42. package/dist/runtime/public/kaspi/logo.svg +4 -0
  43. package/package.json +4 -2
@@ -0,0 +1,97 @@
1
+ <script setup>
2
+ import { removeTrailingSlash } from "#adata-ui/utils/removeTrailingSlash";
3
+ import { watch, ref } from "vue";
4
+ import { useAppConfig, useLocalePath, useCookie, useI18n } from "#imports";
5
+ const props = defineProps({
6
+ requestId: { type: Number, required: true }
7
+ });
8
+ const emit = defineEmits(["back", "updateUserRate"]);
9
+ const isOpen = defineModel({ default: false });
10
+ const { commonAuth } = useAppConfig();
11
+ const { t, locale } = useI18n();
12
+ const localePath = useLocalePath();
13
+ const accessToken = useCookie("accessToken");
14
+ const userApiURL = commonAuth.userApiURL;
15
+ const paymentSuccess = ref(false);
16
+ let intervalId = null;
17
+ async function checkPayment() {
18
+ try {
19
+ const { data } = await $fetch(`${removeTrailingSlash(userApiURL)}/user/kaspi-balance/invoice-status`, {
20
+ method: "GET",
21
+ credentials: "include",
22
+ headers: {
23
+ Authorization: `Bearer ${accessToken.value}`,
24
+ lang: locale.value
25
+ },
26
+ params: {
27
+ request_id: props.requestId,
28
+ initial: 0
29
+ }
30
+ });
31
+ if (data.status === "completed") {
32
+ paymentSuccess.value = true;
33
+ }
34
+ } catch (e) {
35
+ console.error(e);
36
+ }
37
+ }
38
+ function goKaspi() {
39
+ window.open(localePath(`https://kaspi.kz/pay/adata?service_id=5964&9507=${props.requestId}`), "_blank");
40
+ }
41
+ function onBack() {
42
+ emit("back", "kaspi");
43
+ }
44
+ watch(isOpen, async (value) => {
45
+ if (!value) {
46
+ if (intervalId) {
47
+ clearInterval(intervalId);
48
+ }
49
+ return;
50
+ }
51
+ intervalId = setInterval(() => {
52
+ if (paymentSuccess.value && intervalId) {
53
+ clearInterval(intervalId);
54
+ emit("updateUserRate");
55
+ return;
56
+ }
57
+ checkPayment();
58
+ }, 1e3);
59
+ });
60
+ </script>
61
+
62
+ <template>
63
+ <adt-side-panel
64
+ v-model="isOpen"
65
+ width="484px"
66
+ >
67
+ <div class="flex flex-col gap-5">
68
+ <p class="text-center text-2xl font-bold whitespace-pre-wrap">
69
+ {{ t("payment.redirect.title") }}
70
+ </p>
71
+ <adt-button
72
+ block
73
+ @click="goKaspi"
74
+ >
75
+ {{ t("payment.redirect.goKaspi") }}
76
+ </adt-button>
77
+ <div class="flex flex-col gap-2">
78
+ <p class="text-center text-sm">
79
+ {{ t("payment.redirect.paymentId") }}
80
+ </p>
81
+ <p class="text-center text-xl font-semibold">
82
+ {{ requestId }}
83
+ </p>
84
+ </div>
85
+ <p class="text-center text-sm">
86
+ {{ t("payment.redirect.description") }}
87
+ </p>
88
+ <adt-button
89
+ view="outline"
90
+ block
91
+ @click="onBack"
92
+ >
93
+ {{ t("payment.redirect.changeMethod") }}
94
+ </adt-button>
95
+ </div>
96
+ </adt-side-panel>
97
+ </template>
@@ -0,0 +1,20 @@
1
+ type __VLS_Props = {
2
+ requestId: number;
3
+ };
4
+ declare const __VLS_defaults: {
5
+ modelValue: boolean;
6
+ };
7
+ type __VLS_PublicProps = __VLS_Props & {
8
+ modelValue?: typeof __VLS_defaults['modelValue'];
9
+ };
10
+ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
11
+ "update:modelValue": (value: boolean) => any;
12
+ } & {
13
+ back: (type: "kaspi") => any;
14
+ updateUserRate: () => any;
15
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
16
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
17
+ onBack?: ((type: "kaspi") => any) | undefined;
18
+ onUpdateUserRate?: (() => any) | undefined;
19
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
20
+ export default _default;
@@ -0,0 +1,106 @@
1
+ <script setup>
2
+ import { IPaymentCard, IPaymentKaspi } from "#components";
3
+ import { ref } from "vue";
4
+ import { useI18n } from "#imports";
5
+ const props = defineProps({
6
+ sum: { type: Number, required: true }
7
+ });
8
+ const emit = defineEmits(["nextBank", "back"]);
9
+ const isOpen = defineModel({ default: false });
10
+ const { t } = useI18n();
11
+ const checkbox = ref("kaspi");
12
+ const cards = [
13
+ {
14
+ id: "kaspi",
15
+ name: "payment.method.kaspi",
16
+ sum: 1e4,
17
+ img: IPaymentKaspi
18
+ },
19
+ {
20
+ id: "other",
21
+ name: "payment.method.other",
22
+ sum: 1e4,
23
+ img: IPaymentCard
24
+ }
25
+ ];
26
+ function confirm() {
27
+ emit("nextBank", checkbox.value, props.sum);
28
+ }
29
+ function cancel() {
30
+ isOpen.value = false;
31
+ }
32
+ function onBack() {
33
+ emit("back", "method");
34
+ }
35
+ </script>
36
+
37
+ <template>
38
+ <adt-side-panel
39
+ v-model="isOpen"
40
+ width="484px"
41
+ >
42
+ <template #header>
43
+ <div class="flex items-center gap-2">
44
+ <button @click="onBack">
45
+ <i-chevron-left class="size-6" />
46
+ </button>
47
+ <p class="text-xl font-semibold">
48
+ {{ t("payment.method.title") }}
49
+ </p>
50
+ </div>
51
+ </template>
52
+
53
+ <div class="flex flex-col gap-6">
54
+ <div class="flex flex-col items-center gap-4">
55
+ <ill-phone-check class="size-[120px]" />
56
+ <p class="text-center text-sm font-semibold">
57
+ {{ t("payment.method.description") }}
58
+ </p>
59
+ </div>
60
+
61
+ <div class="font-semibold">
62
+ {{ t("payment.method.note") }}
63
+ </div>
64
+
65
+ <div class="flex flex-col gap-2">
66
+ <adt-radio-button
67
+ v-for="(item) in cards"
68
+ :key="item.id"
69
+ v-model="checkbox"
70
+ :name="`${item.name}`"
71
+ side="right"
72
+ size="lg"
73
+ :value="item.id"
74
+ class="flex items-center justify-between gap-2 rounded-md bg-gray-50 p-[10px_16px] dark:bg-[#393D40]"
75
+ >
76
+ <div class="flex w-full items-center gap-2">
77
+ <component :is="item.img" />
78
+ <div class="flex w-full items-center justify-between">
79
+ {{ t(item.name) }}
80
+ <p class="body-600">
81
+ {{ Math.round(sum).toLocaleString("RU-ru") }} ₸
82
+ </p>
83
+ </div>
84
+ </div>
85
+ </adt-radio-button>
86
+ </div>
87
+
88
+ <div class="flex flex-col gap-2 ">
89
+ <adt-button
90
+ :disabled="!checkbox"
91
+ block
92
+ @click="confirm"
93
+ >
94
+ {{ t("actions.topUp") }}
95
+ </adt-button>
96
+ <adt-button
97
+ view="outline"
98
+ block
99
+ @click="cancel"
100
+ >
101
+ {{ t("actions.close") }}
102
+ </adt-button>
103
+ </div>
104
+ </div>
105
+ </adt-side-panel>
106
+ </template>
@@ -0,0 +1,21 @@
1
+ type IBank = 'kaspi' | 'other';
2
+ type __VLS_Props = {
3
+ sum: number;
4
+ };
5
+ declare const __VLS_defaults: {
6
+ modelValue: boolean;
7
+ };
8
+ type __VLS_PublicProps = __VLS_Props & {
9
+ modelValue?: typeof __VLS_defaults['modelValue'];
10
+ };
11
+ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
12
+ "update:modelValue": (value: boolean) => any;
13
+ } & {
14
+ back: (type: "method") => any;
15
+ nextBank: (bank: IBank, sum: number) => any;
16
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
17
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
18
+ onBack?: ((type: "method") => any) | undefined;
19
+ onNextBank?: ((bank: IBank, sum: number) => any) | undefined;
20
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
21
+ export default _default;
@@ -0,0 +1,112 @@
1
+ <script setup>
2
+ import { removeTrailingSlash } from "#adata-ui/utils/removeTrailingSlash";
3
+ import { ref } from "vue";
4
+ import { useAppConfig, useCookie, useI18n, useNuxtApp } from "#imports";
5
+ import PaymentKaspiQrSidePanel from "#adata-ui/components/payment/process/PaymentKaspiQrSidePanel.vue";
6
+ import PaymentMethodSidePanel from "#adata-ui/components/payment/process/PaymentMethodSidePanel.vue";
7
+ import PaymentTopUpSidePanel from "#adata-ui/components/payment/process/PaymentTopUpSidePanel.vue";
8
+ import PaymentKaspiRedirectSidePanel from "#adata-ui/components/payment/process/PaymentKaspiRedirectSidePanel.vue";
9
+ import { usePayment } from "#adata-ui/composables/usePayment";
10
+ const { $toast } = useNuxtApp();
11
+ const { locale } = useI18n();
12
+ const { commonAuth } = useAppConfig();
13
+ const accessToken = useCookie("accessToken");
14
+ const {
15
+ rateId,
16
+ topUpSidePanel,
17
+ methodSidePanel,
18
+ kaspiQRSidePanel,
19
+ kaspiRedirectSidePanel,
20
+ payByCard
21
+ } = usePayment();
22
+ const userApiURL = commonAuth.userApiURL;
23
+ const paymentSum = ref(0);
24
+ const requestUrl = ref("");
25
+ const requestId = ref(null);
26
+ function actionPayment(num) {
27
+ paymentSum.value = num;
28
+ topUpSidePanel.value = false;
29
+ methodSidePanel.value = true;
30
+ }
31
+ function toggleKaspiSidePanel(state) {
32
+ if (window.innerWidth >= 1024) {
33
+ kaspiQRSidePanel.value = state;
34
+ } else {
35
+ kaspiRedirectSidePanel.value = state;
36
+ }
37
+ }
38
+ function onBack(type) {
39
+ if (type === "method") {
40
+ topUpSidePanel.value = true;
41
+ methodSidePanel.value = false;
42
+ } else if (type === "kaspi") {
43
+ toggleKaspiSidePanel(false);
44
+ methodSidePanel.value = true;
45
+ }
46
+ }
47
+ async function directionsBanks(bank, sum) {
48
+ methodSidePanel.value = false;
49
+ if (bank === "kaspi") {
50
+ try {
51
+ const { data } = await $fetch(`${removeTrailingSlash(userApiURL)}/user/kaspi-balance/request`, {
52
+ method: "POST",
53
+ credentials: "include",
54
+ headers: {
55
+ Authorization: `Bearer ${accessToken.value}`,
56
+ lang: locale.value
57
+ },
58
+ params: {
59
+ amount: sum,
60
+ initial: 1,
61
+ rate_id: rateId.value ?? void 0
62
+ }
63
+ });
64
+ requestId.value = data.request_id;
65
+ requestUrl.value = `https://kaspi.kz/pay/adata?service_id=5964&9507=${data.request_id}`;
66
+ toggleKaspiSidePanel(true);
67
+ } catch (error) {
68
+ console.error(error);
69
+ $toast.error(error.data.message);
70
+ }
71
+ } else if (bank === "other") {
72
+ await payByCard(sum);
73
+ }
74
+ }
75
+ async function updateUserRate() {
76
+ try {
77
+ window.location.reload();
78
+ } catch (error) {
79
+ $toast.error(error.data.message);
80
+ toggleKaspiSidePanel(false);
81
+ }
82
+ }
83
+ </script>
84
+
85
+ <template>
86
+ <payment-top-up-side-panel
87
+ v-model="topUpSidePanel"
88
+ @next="actionPayment"
89
+ />
90
+
91
+ <payment-method-side-panel
92
+ v-model="methodSidePanel"
93
+ :sum="paymentSum"
94
+ @back="onBack"
95
+ @next-bank="directionsBanks"
96
+ />
97
+
98
+ <payment-kaspi-qr-side-panel
99
+ v-model="kaspiQRSidePanel"
100
+ :request-url="requestUrl"
101
+ :request-id="requestId"
102
+ @back="onBack"
103
+ @update-user-rate="updateUserRate"
104
+ />
105
+
106
+ <payment-kaspi-redirect-side-panel
107
+ v-model="kaspiRedirectSidePanel"
108
+ :request-id="requestId"
109
+ @back="onBack"
110
+ @update-user-rate="updateUserRate"
111
+ />
112
+ </template>
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ export default _default;
@@ -0,0 +1,117 @@
1
+ <script setup>
2
+ import { ref, computed } from "vue";
3
+ import { useI18n } from "#imports";
4
+ const emit = defineEmits(["next"]);
5
+ const isOpen = defineModel({ default: false });
6
+ const { t } = useI18n();
7
+ const money = ref(0);
8
+ const errorAlert = ref(false);
9
+ const sumArr = ref([
10
+ {
11
+ id: 1,
12
+ value: 2e3,
13
+ label: "2 000 \u20B8"
14
+ },
15
+ {
16
+ id: 2,
17
+ value: 5e3,
18
+ label: "5 000 \u20B8"
19
+ },
20
+ {
21
+ id: 3,
22
+ value: 1e4,
23
+ label: "10 000 \u20B8"
24
+ },
25
+ {
26
+ id: 4,
27
+ value: 2e4,
28
+ label: "20 000 \u20B8"
29
+ }
30
+ ]);
31
+ const filterMoney = computed(() => {
32
+ return money.value >= 1;
33
+ });
34
+ function onSelectAmount(value) {
35
+ money.value = value;
36
+ errorAlert.value = false;
37
+ }
38
+ function onClose() {
39
+ isOpen.value = false;
40
+ errorAlert.value = false;
41
+ }
42
+ function handlePayment() {
43
+ if (money.value <= 1e6) {
44
+ emit("next", money.value);
45
+ errorAlert.value = false;
46
+ } else {
47
+ errorAlert.value = true;
48
+ }
49
+ }
50
+ </script>
51
+
52
+ <template>
53
+ <adt-side-panel
54
+ v-model="isOpen"
55
+ width="484px"
56
+ >
57
+ <template #header>
58
+ <div class="text-xl font-semibold">
59
+ {{ t("payment.topUp.title") }}
60
+ </div>
61
+ </template>
62
+
63
+ <div class="flex flex-col gap-6">
64
+ <div class="flex flex-col items-center gap-4 ">
65
+ <ill-bill class="size-[120px]" />
66
+ <p class="text-center text-sm font-semibold">
67
+ {{ t("payment.topUp.info") }}
68
+ </p>
69
+ </div>
70
+
71
+ <div class="flex flex-col gap-4">
72
+ <adt-forms-input-standard
73
+ v-model="money"
74
+ :label="`${t('payment.topUp.enterAmount')}`"
75
+ type="number"
76
+ pattern="[0-9]*"
77
+ clearable
78
+ />
79
+ <adt-alert
80
+ v-if="errorAlert"
81
+ color="red"
82
+ >
83
+ {{ t("modals.replenish_modal.error") }}
84
+ </adt-alert>
85
+ <div class="flex gap-4">
86
+ <adt-chip
87
+ v-for="item in sumArr"
88
+ :key="item.id"
89
+ view="standard"
90
+ size="lg"
91
+ :class="[
92
+ money === item.value ? 'bg-blue-700 text-white hover:bg-blue-700 dark:border-blue-500 dark:bg-transparent dark:text-blue-500 dark:hover:bg-transparent' : ''
93
+ ]"
94
+ @click.stop="onSelectAmount(item.value)"
95
+ >
96
+ <span>{{ item.label }}</span>
97
+ </adt-chip>
98
+ </div>
99
+ </div>
100
+
101
+ <div class="flex flex-col gap-2">
102
+ <adt-button
103
+ :disabled="!filterMoney"
104
+ @click="handlePayment"
105
+ >
106
+ {{ t("actions.topUp") }}
107
+ </adt-button>
108
+ <adt-button
109
+ view="outline"
110
+ @click="onClose"
111
+ >
112
+ {{ t("actions.back") }}
113
+ </adt-button>
114
+ </div>
115
+ </div>
116
+ </adt-side-panel>
117
+ </template>
@@ -0,0 +1,15 @@
1
+ declare const __VLS_defaults: {
2
+ modelValue: boolean;
3
+ };
4
+ type __VLS_PublicProps = {
5
+ modelValue?: typeof __VLS_defaults['modelValue'];
6
+ };
7
+ declare const _default: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
8
+ "update:modelValue": (value: boolean) => any;
9
+ } & {
10
+ next: (sum: number) => any;
11
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
12
+ "onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
13
+ onNext?: ((sum: number) => any) | undefined;
14
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
15
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import type { Ref } from 'vue';
2
+ export type AdaptiveContext = {
3
+ isMobile: boolean;
4
+ isTablet: boolean;
5
+ isSmallTablet: boolean;
6
+ isDesktop: boolean;
7
+ };
8
+ export declare const useAdaptive: () => Ref<AdaptiveContext>;
@@ -0,0 +1,27 @@
1
+ import { ref, onMounted, onUnmounted } from "vue";
2
+ const isBrowser = typeof window !== void 0 && import.meta.client;
3
+ const computeIsMobile = () => isBrowser ? window.matchMedia("(max-width: 560px)").matches : false;
4
+ const computeIsSmallTablet = () => isBrowser ? window.matchMedia("(max-width: 767px)").matches : false;
5
+ const computeIsTablet = () => isBrowser ? window.innerWidth >= 768 && window.innerWidth < 1024 : false;
6
+ const computeIsDesktop = () => isBrowser ? window.innerWidth >= 1024 : false;
7
+ export const useAdaptive = () => {
8
+ const ctx = ref({
9
+ isDesktop: computeIsDesktop(),
10
+ isMobile: computeIsMobile(),
11
+ isTablet: computeIsTablet(),
12
+ isSmallTablet: computeIsSmallTablet()
13
+ });
14
+ const setValues = () => ctx.value = {
15
+ isDesktop: computeIsDesktop(),
16
+ isMobile: computeIsMobile(),
17
+ isTablet: computeIsTablet(),
18
+ isSmallTablet: computeIsSmallTablet()
19
+ };
20
+ onMounted(
21
+ () => {
22
+ window.addEventListener("resize", setValues, { passive: true });
23
+ }
24
+ );
25
+ onUnmounted(() => window.removeEventListener("resize", setValues));
26
+ return ctx;
27
+ };
@@ -0,0 +1,8 @@
1
+ export declare function usePayment(): {
2
+ rateId: import("vue").Ref<string, string>;
3
+ topUpSidePanel: import("vue").Ref<boolean, boolean>;
4
+ methodSidePanel: import("vue").Ref<boolean, boolean>;
5
+ kaspiQRSidePanel: import("vue").Ref<boolean, boolean>;
6
+ kaspiRedirectSidePanel: import("vue").Ref<boolean, boolean>;
7
+ payByCard: (sum: number, rate?: any) => Promise<void>;
8
+ };
@@ -0,0 +1,66 @@
1
+ import { removeTrailingSlash } from "#adata-ui/utils/removeTrailingSlash";
2
+ import { useState, useNuxtApp, useAppConfig, useCookie } from "#imports";
3
+ export function usePayment() {
4
+ const topUpSidePanel = useState("top-up-side-panel", () => false);
5
+ const methodSidePanel = useState("method-side-panel", () => false);
6
+ const kaspiQRSidePanel = useState("kaspi-qr-side-panel", () => false);
7
+ const kaspiRedirectSidePanel = useState("kaspi-redirect-side-panel", () => false);
8
+ const rateId = useState("use-rate-id");
9
+ async function payByCard(sum, rate) {
10
+ const { $toast, $i18n } = useNuxtApp();
11
+ const { adataUI, commonAuth } = useAppConfig();
12
+ const accessToken = useCookie("accessToken");
13
+ const t = $i18n.t;
14
+ const publicId = adataUI.cloudPayments;
15
+ const userApiURL = commonAuth.userApiURL;
16
+ try {
17
+ const { data } = await $fetch(`${removeTrailingSlash(userApiURL)}/top_ups`, {
18
+ method: "POST",
19
+ headers: {
20
+ Authorization: `Bearer ${accessToken.value}`
21
+ },
22
+ params: {
23
+ amount: sum
24
+ }
25
+ });
26
+ if (data) {
27
+ const { amount, id, user_id } = data;
28
+ const widget = new tiptop.Widget();
29
+ widget.pay(
30
+ "charge",
31
+ {
32
+ publicId,
33
+ description: t("payment.bank.description"),
34
+ amount: Number.parseInt(amount),
35
+ currency: "KZT",
36
+ invoiceId: id.toString(),
37
+ accountId: user_id.toString(),
38
+ skin: "modern",
39
+ data: {
40
+ myProp: "myProp value",
41
+ rate
42
+ }
43
+ },
44
+ {
45
+ onSuccess() {
46
+ $toast.success(t("payment.bank.paySuccess"));
47
+ },
48
+ onFail() {
49
+ $toast.error(t("payment.bank.payError"));
50
+ }
51
+ }
52
+ );
53
+ }
54
+ } catch (error) {
55
+ throw new Error(error.data.message);
56
+ }
57
+ }
58
+ return {
59
+ rateId,
60
+ topUpSidePanel,
61
+ methodSidePanel,
62
+ kaspiQRSidePanel,
63
+ kaspiRedirectSidePanel,
64
+ payByCard
65
+ };
66
+ }