-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfoxy-signer.js
59 lines (55 loc) · 1.64 KB
/
foxy-signer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as FoxySDK from "@foxy.io/sdk";
const signer = new FoxySDK.Backend.Signer(process.env.FOXY_STORE_SECRET);
export function getFoxyForm(product) {
const formHtml = `
<form
action="https://${
process.env.NEXT_PUBLIC_FOXY_SUBDOMAIN
}.foxycart.com/cart"
method="POST"
class="mt-10 grid grid-cols-1 gap-x-6 gap-y-3 sm:grid-cols-2"
>
<input
type="hidden"
name="name"
value="${product.Name.title[0].plain_text}"
/>
<input type="hidden" name="price" value="${product.Price.number}" />
<input
type="hidden"
name="quantity_max"
value="${product.Inventory.number}"
/>
<input
type="hidden"
name="image"
value="${
product["Image URL"].url
? product["Image URL"].url
: product.Image.files[0].file.url
}"
/>
<input
type="hidden"
name="code"
value="${product.Slug.rich_text[0].plain_text}"
/>
<input
type="number"
name="quantity"
value=""
min="1"
max="${product.Inventory.number}"
placeholder="Quantity"
class="border rounded-md py-3 px-6"
/>
<button
type="submit"
class="w-full bg-gray-900 border border-transparent rounded-md py-3 px-8 flex items-center justify-center text-base font-medium text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-50 focus:ring-gray-500"
>
Add to Bag
</button>
</form>
`;
return process.env.FOXY_STORE_SECRET ? signer.signHtml(formHtml) : formHtml;
}