aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/buy/+page.server.js
diff options
context:
space:
mode:
authorJohn Barratt <[email protected]>2023-03-07 10:29:49 -0800
committerJohn Barratt <[email protected]>2023-03-07 10:29:49 -0800
commit8ef9568cd1bd822495ce005d4e4cfaa6cb0d92ce (patch)
tree4ea5530cc2b7e5d970dc8a84cacfecfe2cce46b7 /src/routes/(app)/buy/+page.server.js
parentc97fb43abba375920fff361ec5fa4eb64a5a0d3f (diff)
parent0f44e3283c25c9783a52cf20957661da49d2f90b (diff)
downloadcoinos-ui-notifications.tar.gz
coinos-ui-notifications.zip
Merge branch 'master' of https://github.com/coinos/coinos-ui into notificationsnotifications
Diffstat (limited to 'src/routes/(app)/buy/+page.server.js')
-rw-r--r--src/routes/(app)/buy/+page.server.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/routes/(app)/buy/+page.server.js b/src/routes/(app)/buy/+page.server.js
new file mode 100644
index 00000000..fc7ae473
--- /dev/null
+++ b/src/routes/(app)/buy/+page.server.js
@@ -0,0 +1,27 @@
+import { env } from '$env/dynamic/private';
+import { error, fail, redirect } from '@sveltejs/kit';
+import { post, auth } from '$lib/utils';
+import { createTicket } from '$lib/ticket';
+
+export const actions = {
+ default: async ({ cookies, request }) => {
+ let form = await request.formData();
+
+ let amount = parseFloat(form.get('amount'));
+ if (!amount || amount < 0 || amount > 500) return fail(400, { message: 'Invalid amount' });
+
+ await post(
+ '/buy',
+ {
+ amount: form.get('amount'),
+ number: form.get('number').replace(/\s+/g, ''),
+ month: form.get('expiry').slice(0, 2),
+ year: form.get('expiry').slice(-2),
+ cvc: form.get('cvc')
+ },
+ auth(cookies)
+ );
+
+ throw redirect(307, `/${form.get('username')}/payments`);
+ }
+};