-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOmiseForm.tsx
78 lines (71 loc) · 1.98 KB
/
OmiseForm.tsx
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use client";
// @ts-ignore
import Script from "react-load-script";
import React, { useEffect, useState } from "react";
// @ts-ignore
let OmiseCard;
interface OmiseCreditFormProps {
className?: string;
currency?: string;
frameLabel?: string;
submitLabel?: string;
buttonLabel?: string;
onCreateTokenSuccess: (token: string) => void;
}
export default function OmiseCreditForm(props: OmiseCreditFormProps) {
const handleLoadScript = () => {
// @ts-ignore
OmiseCard = window.OmiseCard;
OmiseCard.configure({
// exposed to public, configured in next.config.js
publicKey: process.env.OMISE_PUBLIC_CLIENT_KEY,
currency: "THB",
frameLabel: "PreceptorAI",
submitLabel: "Pay NOW",
buttonLabel: "Pay with Omise",
});
};
const creditCardConfigure = () => {
// @ts-ignore
OmiseCard.configure({
defaultPaymentMethod: "credit_card",
otherPaymentMethods: [],
});
// @ts-ignore
OmiseCard.configureButton("#credit-card");
// @ts-ignore
OmiseCard.attach();
};
const OmiseCardHandler = () => {
// @ts-ignore
OmiseCard.open({
amount: "30000",
onCreateTokenSuccess: (token: string) => {
props.onCreateTokenSuccess(token);
},
onFormClosed: () => {},
});
};
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
creditCardConfigure();
OmiseCardHandler();
};
return (
<div className="own-form">
<Script url="https://cdn.omise.co/omise.js" onLoad={handleLoadScript} />{" "}
<form>
<button
id="credit-card"
className={
"cursor-pointer px-12 py-4 bg-blue-500 hover:bg-blue-400 text-white font-bold border-b-4 border-blue-700 hover:border-blue-500 rounded" +
props.className
}
onClick={handleClick}
>
ชำระเงินด้วยบัตรเครดิต{" "}
</button>{" "}
</form>{" "}
</div>
);
}