1
1
<script setup lang="ts">
2
+ import CardBrands from ' ./card-brands.vue'
3
+
2
4
import { useBillable } from ' ../../../../functions/billing/payments'
5
+
3
6
const paymentStore = usePaymentStore ()
4
7
5
8
const stripeLoading = ref (true )
@@ -20,8 +23,14 @@ function cancelPaymentForm() {
20
23
stripeLoading .value = true
21
24
}
22
25
26
+ function isEmpty(defaultPaymentMethod : any ) {
27
+ return ! defaultPaymentMethod // Checks for null or undefined
28
+ || (typeof defaultPaymentMethod === ' object'
29
+ && Object .keys (defaultPaymentMethod ).length === 0 )
30
+ }
31
+
23
32
onMounted (async () => {
24
- await paymentStore .fetchUserPaymentMethods ()
33
+ await paymentStore .fetchDefaultPaymentMethod ()
25
34
})
26
35
</script >
27
36
@@ -31,42 +40,41 @@ onMounted(async () => {
31
40
Payment Info
32
41
</h2 >
33
42
34
- <ul v-if =" stripeLoading || !showStripe" role =" list" class =" grid grid-cols-1 mt-8 gap-6 lg:grid-cols-1 sm:grid-cols-1" >
35
- <li v-for =" (method, index) in paymentStore.getPaymentMethods" :key =" index" class =" col-span-1 border rounded-lg bg-white shadow divide-y divide-gray-200" >
36
- <div class =" w-full p-4" >
37
- <div class =" flex space-x-4" >
38
- <div class =" h-24 w-24" >
39
- <img src =" /images/logos/mastercard.svg" alt =" Mastercard Logo" class =" border" >
40
- </div >
41
- <h2 class =" text-xl text-gray-600" >
42
- {{ method.card.brand }} •••• {{ method.card.last4 }} <br >
43
- <span class =" text-xs text-gray-500 italic" >Expires {{ method.card.exp_month }} / {{ method.card.exp_year }} </span >
44
- </h2 >
43
+ <div v-if =" !isEmpty(paymentStore.getDefaultPaymentMethod)" class =" col-span-1 border rounded-lg bg-white shadow divide-y divide-gray-200" >
44
+ <div class =" w-full p-4" >
45
+ <div class =" flex space-x-4" >
46
+ <CardBrands :brand =" paymentStore.getDefaultPaymentMethod.card.brand" />
47
+ <h2 class =" text-xl text-gray-600" >
48
+ {{ paymentStore.getDefaultPaymentMethod.card.brand }} •••• {{ paymentStore.getDefaultPaymentMethod.card.last4 }}
49
+ <br >
50
+ <span class =" text-xs text-gray-500 italic" >Expires {{ paymentStore.getDefaultPaymentMethod.card.exp_month }} / {{ paymentStore.getDefaultPaymentMethod.card.exp_year }} </span >
51
+ </h2 >
52
+
53
+ <div >
54
+ <span class =" inline-flex items-center rounded-md bg-indigo-50 px-2 py-1 text-sm text-xs text-indigo-700 font-medium ring-1 ring-indigo-700/10 ring-inset" >Default</span >
45
55
</div >
56
+ </div >
46
57
47
- <div class =" flex justify-end space-x-4" >
48
- <button
49
- type =" button"
50
- class =" border rounded-md bg-white px-2 py-1 text-sm text-white font-semibold shadow-sm hover:bg-blue-gray-50 focus-visible:outline-2 focus-visible:outline-blue-600 focus-visible:outline-offset-2 focus-visible:outline"
51
- @click =" handleAddPaymentMethod()"
52
- >
53
- <svg class =" h-4 w-4 text-gray-700" data-slot =" icon" fill =" none" stroke-width =" 1.5" stroke =" currentColor" viewBox =" 0 0 24 24" xmlns =" http://www.w3.org/2000/svg" aria-hidden =" true" >
54
- <path stroke-linecap =" round" stroke-linejoin =" round" d =" m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" />
55
- </svg >
56
- </button >
57
- <button
58
- type =" button"
59
- class =" border rounded-md bg-white px-2 py-1 text-sm text-white font-semibold shadow-sm hover:bg-blue-gray-50 focus-visible:outline-2 focus-visible:outline-blue-600 focus-visible:outline-offset-2 focus-visible:outline"
60
- @click =" handleAddPaymentMethod()"
61
- >
62
- <svg class =" h-4 w-4 text-gray-700" data-slot =" icon" fill =" none" stroke-width =" 1.5" stroke =" currentColor" viewBox =" 0 0 24 24" xmlns =" http://www.w3.org/2000/svg" aria-hidden =" true" >
63
- <path stroke-linecap =" round" stroke-linejoin =" round" d =" m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
64
- </svg >
65
- </button >
66
- </div >
58
+ <div class =" flex justify-end space-x-4" >
59
+ <button
60
+ type =" button"
61
+ class =" border rounded-md bg-white px-2 py-1 text-sm text-white font-semibold shadow-sm hover:bg-blue-gray-50 focus-visible:outline-2 focus-visible:outline-blue-600 focus-visible:outline-offset-2 focus-visible:outline"
62
+ >
63
+ <svg class =" h-4 w-4 text-gray-700" data-slot =" icon" fill =" none" stroke-width =" 1.5" stroke =" currentColor" viewBox =" 0 0 24 24" xmlns =" http://www.w3.org/2000/svg" aria-hidden =" true" >
64
+ <path stroke-linecap =" round" stroke-linejoin =" round" d =" m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" />
65
+ </svg >
66
+ </button >
67
+ <button
68
+ type =" button"
69
+ class =" border rounded-md bg-white px-2 py-1 text-sm text-white font-semibold shadow-sm hover:bg-blue-gray-50 focus-visible:outline-2 focus-visible:outline-blue-600 focus-visible:outline-offset-2 focus-visible:outline"
70
+ >
71
+ <svg class =" h-4 w-4 text-gray-700" data-slot =" icon" fill =" none" stroke-width =" 1.5" stroke =" currentColor" viewBox =" 0 0 24 24" xmlns =" http://www.w3.org/2000/svg" aria-hidden =" true" >
72
+ <path stroke-linecap =" round" stroke-linejoin =" round" d =" m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
73
+ </svg >
74
+ </button >
67
75
</div >
68
- </li >
69
- </ul >
76
+ </div >
77
+ </div >
70
78
71
79
<div v-show =" !stripeLoading || showStripe" >
72
80
<form id =" payment-form" >
0 commit comments