-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
281 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<template> | ||
<UBadge v-if="payment.status === 'processing'" size="xs" label="Processing" color="amber" variant="subtle" /> | ||
<UBadge v-else-if="payment.status === 'paid'" size="xs" label="Paid" color="emerald" variant="subtle" /> | ||
<UBadge v-else-if="payment.status === 'failed'" size="xs" label="Failed" color="rose" variant="subtle" /> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import type { Payment } from '@geprog/gringotts-client'; | ||
defineProps<{ | ||
payment: Payment; | ||
}>(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<div v-if="payment" class="w-full flex flex-col gap-4 max-w-4xl mx-auto"> | ||
<div class="flex justify-between"> | ||
<h1 class="text-xl">Payment: {{ payment._id }}</h1> | ||
|
||
<StatusPayment :payment="payment" /> | ||
</div> | ||
|
||
<UCard> | ||
<div class="flex justify-end mb-2 gap-2 items-center"> | ||
<router-link v-if="payment.invoice" :to="`/invoices/${payment.invoice._id}`"> | ||
<UButton label="Invoice" icon="i-ion-document-text" size="sm" /> | ||
</router-link> | ||
<router-link v-if="payment.customer" :to="`/customers/${payment.customer._id}`"> | ||
<UButton :label="payment.customer.name" icon="i-ion-people" size="sm" /> | ||
</router-link> | ||
<router-link v-if="payment.subscription" :to="`/subscriptions/${payment.subscription._id}`"> | ||
<UButton label="Subscription" icon="i-ion-md-refresh" size="sm" /> | ||
</router-link> | ||
</div> | ||
|
||
<UForm :state="payment" class="flex flex-col gap-4"> | ||
<UFormGroup label="Description" name="description"> | ||
<UInput color="primary" variant="outline" v-model="payment.description" size="lg" disabled /> | ||
</UFormGroup> | ||
|
||
<UFormGroup label="Type" name="type"> | ||
<UInput color="primary" variant="outline" v-model="payment.type" size="lg" disabled /> | ||
</UFormGroup> | ||
|
||
<UFormGroup label="Amount" name="amount"> | ||
<UInput color="primary" variant="outline" v-model="payment._id" size="lg" disabled> | ||
<template #trailing> | ||
<span class="text-gray-500 dark:text-gray-400 text-xs">{{ payment.currency }}</span> | ||
</template> | ||
</UInput> | ||
</UFormGroup> | ||
|
||
<UFormGroup label="Status" name="status"> | ||
<USelectMenu | ||
color="primary" | ||
variant="outline" | ||
v-model="payment.status" | ||
:options="['active', 'error']" | ||
size="lg" | ||
disabled | ||
/> | ||
</UFormGroup> | ||
</UForm> | ||
</UCard> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
const client = await useGringottsClient(); | ||
const route = useRoute(); | ||
const paymentId = route.params.paymentId as string; | ||
const { data: payment } = useAsyncData(async () => { | ||
const { data } = await client.payment.getPayment(paymentId); | ||
return data; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<template> | ||
<div class="w-full"> | ||
<h1 class="text-xl">Payments</h1> | ||
|
||
<UTable :loading="pending" :rows="payments || []" :columns="paymentColumns" @select="selectPayment"> | ||
<template #customer-data="{ row }"> | ||
<span>{{ row.customer.name }}</span> | ||
</template> | ||
|
||
<template #amount-data="{ row }"> | ||
<span>{{ formatCurrency(row.amount, row.currency) }}</span> | ||
</template> | ||
|
||
<template #status-data="{ row }"> | ||
<StatusPayment :payment="row" /> | ||
</template> | ||
</UTable> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import type { Payment } from '@geprog/gringotts-client'; | ||
const router = useRouter(); | ||
const client = await useGringottsClient(); | ||
const paymentColumns = [ | ||
{ | ||
key: '_id', | ||
label: 'ID', | ||
}, | ||
{ | ||
key: 'description', | ||
label: 'Description', | ||
sortable: true, | ||
}, | ||
{ | ||
key: 'status', | ||
label: 'Status', | ||
sortable: true, | ||
}, | ||
{ | ||
key: 'amount', | ||
label: 'Current period', | ||
sortable: true, | ||
}, | ||
]; | ||
async function selectPayment(row: Payment) { | ||
await router.push(`/payments/${row._id}`); | ||
} | ||
const { data: payments, pending } = useAsyncData(async () => { | ||
const { data } = await client.payment.listPayments(); | ||
return data; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Migration } from '@mikro-orm/migrations'; | ||
|
||
type Payment = { | ||
_id: string; | ||
customer__id: string; | ||
project__id: string; | ||
}; | ||
|
||
type Customer = { | ||
_id: string; | ||
project__id: string; | ||
}; | ||
|
||
export class MigrationSetPaymentProject extends Migration { | ||
async up(): Promise<void> { | ||
if (!(await this.ctx?.schema.hasTable('payment')) || (await this.ctx?.schema.hasColumn('payment', 'project__id'))) { | ||
return; | ||
} | ||
|
||
await this.ctx?.schema.alterTable('payment', (table) => { | ||
table.uuid('project__id').nullable(); | ||
}); | ||
|
||
const payments = await this.ctx?.table<Payment>('payment').select<Payment[]>(); | ||
for await (const payment of payments || []) { | ||
const customer = await this.ctx | ||
?.table<Customer>('customer') | ||
.where({ _id: payment.customer__id }) | ||
.first<Customer>(); | ||
|
||
await this.ctx?.table<Payment>('payment').where({ _id: payment._id }).update({ | ||
project__id: customer?.project__id, | ||
}); | ||
} | ||
|
||
await this.ctx?.schema.alterTable('payment', (table) => { | ||
table.dropNullable('project__id'); | ||
}); | ||
} | ||
|
||
async down(): Promise<void> { | ||
if (!(await this.ctx?.schema.hasColumn('payment', 'project__id'))) { | ||
return; | ||
} | ||
|
||
await this.ctx?.schema.alterTable('payment', (table) => { | ||
table.dropColumn('project__id'); | ||
}); | ||
} | ||
} |