@team-oozoo/oozoo-pay 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # @team-oozoo/oozoo-pay
2
+
3
+ OOZOO PAY JavaScript SDK for browser-based crypto payments.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @team-oozoo/oozoo-pay
9
+ # or
10
+ pnpm add @team-oozoo/oozoo-pay
11
+ # or
12
+ yarn add @team-oozoo/oozoo-pay
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ### npm / ES Module
18
+
19
+ ```typescript
20
+ import { loadOozooPay } from '@team-oozoo/oozoo-pay';
21
+
22
+ const client = await loadOozooPay('pk_your_client_key');
23
+
24
+ await client.pay({
25
+ price: 100,
26
+ unit: 'usd',
27
+ onCreateInvoice: async ({ price, chainId, tokenAddress, sender }) => {
28
+ const res = await fetch('/api/create-invoice', {
29
+ method: 'POST',
30
+ headers: { 'Content-Type': 'application/json' },
31
+ body: JSON.stringify({ price, chainId, tokenAddress, sender }),
32
+ });
33
+ const data = await res.json();
34
+ return data.invoiceId;
35
+ },
36
+ successUrl: '/payment/success',
37
+ failUrl: '/payment/fail',
38
+ });
39
+ ```
40
+
41
+ ### Script Tag (Standalone)
42
+
43
+ ```html
44
+ <script src="https://unpkg.com/@team-oozoo/oozoo-pay/dist/standalone.global.js"></script>
45
+ <script>
46
+ async function handlePay() {
47
+ const client = await OozooPay.load('pk_your_client_key');
48
+ await client.pay({
49
+ price: 100,
50
+ unit: 'usd',
51
+ onCreateInvoice: async (params) => {
52
+ const res = await fetch('/api/create-invoice', {
53
+ method: 'POST',
54
+ headers: { 'Content-Type': 'application/json' },
55
+ body: JSON.stringify(params),
56
+ });
57
+ const data = await res.json();
58
+ return data.invoiceId;
59
+ },
60
+ successUrl: '/payment/success',
61
+ failUrl: '/payment/fail',
62
+ });
63
+ }
64
+ </script>
65
+ ```
66
+
67
+ ## API
68
+
69
+ ### `loadOozooPay(clientKey)`
70
+
71
+ SDK 초기화 함수. `OozooPayClient` 인스턴스를 반환합니다.
72
+
73
+ | Parameter | Type | Required | Description |
74
+ | ----------- | -------- | -------- | ------------------------- |
75
+ | `clientKey` | `string` | Yes | API Client Key (`pk_xxx`) |
76
+
77
+ ### `client.pay(options)`
78
+
79
+ 결제 창을 열고 사용자에게 결제를 받습니다.
80
+
81
+ ```typescript
82
+ await client.pay({
83
+ price: 100,
84
+ unit: 'usd',
85
+ onCreateInvoice: async (params) => {
86
+ // 가맹점 서버에서 인보이스 생성 후 invoiceId 반환
87
+ return invoiceId;
88
+ },
89
+ successUrl: '/payment/success',
90
+ failUrl: '/payment/fail',
91
+ });
92
+ ```
93
+
94
+ | Option | Type | Required | Description |
95
+ | ----------------- | ----------------------------- | -------- | ---------------------------------------------------- |
96
+ | `price` | `number` | Yes | 결제 금액 |
97
+ | `unit` | `'usd'` | No | 통화 단위 (기본: `'usd'`) |
98
+ | `onCreateInvoice` | `(params) => Promise<string>` | Yes | 인보이스 생성 콜백 |
99
+ | `successUrl` | `string` | Yes | 결제 성공 시 리다이렉트 URL (`?invoiceId={id}` 추가) |
100
+ | `failUrl` | `string` | Yes | 결제 실패/취소 시 리다이렉트 URL |
101
+
102
+ #### `onCreateInvoice` Parameters
103
+
104
+ | Field | Type | Description |
105
+ | -------------- | -------- | -------------------- |
106
+ | `price` | `number` | 결제 금액 |
107
+ | `unit` | `string` | 통화 단위 |
108
+ | `chainId` | `string` | 블록체인 네트워크 ID |
109
+ | `tokenAddress` | `string` | 토큰 컨트랙트 주소 |
110
+ | `sender` | `string` | 결제자 지갑 주소 |
111
+
112
+ #### `failUrl` Query Parameters
113
+
114
+ | 상황 | Query Parameters | 예시 |
115
+ | ----------- | ------------------------------------- | --------------------------------------- |
116
+ | 사용자 취소 | `?code=CANCELLED` | `/fail?code=CANCELLED` |
117
+ | 결제 에러 | `?code={ERROR_CODE}&message={메시지}` | `/fail?code=PAYMENT_FAILED&message=...` |
118
+
119
+ ### `client.transfer(options)`
120
+
121
+ 출금 창을 열고 사용자에게 출금합니다. `pay()`와 동일한 인터페이스이며, `onCreateInvoice` 파라미터에 `sender` 대신 `receiver`가 전달됩니다.
122
+
123
+ ```typescript
124
+ await client.transfer({
125
+ price: 50,
126
+ unit: 'usd',
127
+ onCreateInvoice: async ({ price, chainId, tokenAddress, receiver }) => {
128
+ const res = await fetch('/api/create-transfer', {
129
+ method: 'POST',
130
+ headers: { 'Content-Type': 'application/json' },
131
+ body: JSON.stringify({ price, chainId, tokenAddress, receiver }),
132
+ });
133
+ const data = await res.json();
134
+ return data.invoiceId;
135
+ },
136
+ successUrl: '/transfer/success',
137
+ failUrl: '/transfer/fail',
138
+ });
139
+ ```