pay-rehearsal 0.1.0 → 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 +65 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +344 -265
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/styles.css +132 -0
package/README.md
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
# Pay Rehearsal React
|
|
2
2
|
|
|
3
|
-
[한국어](
|
|
3
|
+
[한국어](https://github.com/Librariann/pay-rehearsal/blob/main/README.ko.md)
|
|
4
4
|
|
|
5
|
-
A TypeScript
|
|
5
|
+
A TypeScript Mock checkout UI SDK for React and Next.js that lets you build domestic payment gateway and PayPal-style payment flows before connecting a live payment provider.
|
|
6
6
|
|
|
7
|
-
> The Mock adapter does not perform real authorizations, charges, or card-data collection.
|
|
7
|
+
> The Mock adapter does not perform real authorizations, charges, or card-data collection. For production, replace the simulated authentication UI with the payment provider's official checkout experience and verify every payment on your server.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- Responsive payment modal with baseline accessibility support
|
|
12
|
-
- UI flows for cards, bank transfers, virtual accounts,
|
|
12
|
+
- UI flows for cards, bank transfers, virtual accounts, mobile payments, and PayPal
|
|
13
13
|
- Card issuer selection for KB Kookmin, Shinhan, Samsung, Hyundai, Lotte, Hana, Woori, NH Nonghyup, and BC
|
|
14
14
|
- One-time and installment payment selection with card issuer authentication simulation
|
|
15
15
|
- Major bank selection with bank transfer authentication simulation
|
|
16
16
|
- Virtual account details with a deposit-pending (`pending`) result
|
|
17
|
+
- A PayPal-inspired checkout theme with order creation, buyer approval, and capture stages
|
|
17
18
|
- Success, failure, cancellation, and random test scenarios
|
|
18
19
|
- Promise-based `requestPayment()` API
|
|
19
20
|
- Prebuilt `PaymentButton`
|
|
20
|
-
- A replaceable `PaymentAdapter` interface for
|
|
21
|
+
- A replaceable `PaymentAdapter` interface for custom test and integration experiments
|
|
21
22
|
- Theme configuration for color, border radius, and font family
|
|
22
23
|
- Compatible with React 18/19 and the Next.js App Router
|
|
23
24
|
|
|
@@ -55,7 +56,7 @@ export function AppPaymentProvider({ children }: { children: ReactNode }) {
|
|
|
55
56
|
<MockPaymentProvider
|
|
56
57
|
result="success"
|
|
57
58
|
delayMs={900}
|
|
58
|
-
paymentMethods={["card", "bank-transfer", "virtual-account"]}
|
|
59
|
+
paymentMethods={["card", "bank-transfer", "virtual-account", "paypal"]}
|
|
59
60
|
defaultPaymentMethod="card"
|
|
60
61
|
theme={{ accentColor: "#4f46e5", borderRadius: 24 }}
|
|
61
62
|
>
|
|
@@ -71,7 +72,11 @@ Add the provider to your root layout.
|
|
|
71
72
|
// app/layout.tsx
|
|
72
73
|
import { AppPaymentProvider } from "./payment-provider";
|
|
73
74
|
|
|
74
|
-
export default function RootLayout({
|
|
75
|
+
export default function RootLayout({
|
|
76
|
+
children,
|
|
77
|
+
}: {
|
|
78
|
+
children: React.ReactNode;
|
|
79
|
+
}) {
|
|
75
80
|
return (
|
|
76
81
|
<html lang="en">
|
|
77
82
|
<body>
|
|
@@ -136,7 +141,7 @@ For simpler use cases, you can use `PaymentButton`.
|
|
|
136
141
|
|
|
137
142
|
## Configuring Payment Methods and Their Order
|
|
138
143
|
|
|
139
|
-
Use the provider's `paymentMethods` property to choose which methods appear in the modal and in what order. When omitted, cards, bank transfers, virtual accounts,
|
|
144
|
+
Use the provider's `paymentMethods` property to choose which methods appear in the modal and in what order. When omitted, cards, bank transfers, virtual accounts, mobile payments, and PayPal are all displayed.
|
|
140
145
|
|
|
141
146
|
```tsx
|
|
142
147
|
<MockPaymentProvider
|
|
@@ -165,6 +170,54 @@ requestPayment(order, {
|
|
|
165
170
|
|
|
166
171
|
Configuration precedence is request-level `paymentMethod` → request-level `paymentMethods` → provider-level `paymentMethods`. Array order determines display order. In production, your server must verify that a selected payment method is enabled under your gateway contract regardless of whether the method appears in the UI.
|
|
167
172
|
|
|
173
|
+
## Rehearsing PayPal Checkout
|
|
174
|
+
|
|
175
|
+
Add `paypal` to the provider's payment method list:
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
<MockPaymentProvider
|
|
179
|
+
paymentMethods={["paypal", "card"]}
|
|
180
|
+
defaultPaymentMethod="paypal"
|
|
181
|
+
>
|
|
182
|
+
{children}
|
|
183
|
+
</MockPaymentProvider>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
You can also lock an individual request to PayPal:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
requestPayment(
|
|
190
|
+
{
|
|
191
|
+
orderId: "ORDER-PAYPAL-1001",
|
|
192
|
+
orderName: "Global Pro Plan",
|
|
193
|
+
amount: 29,
|
|
194
|
+
currency: "USD",
|
|
195
|
+
},
|
|
196
|
+
{ paymentMethod: "paypal" },
|
|
197
|
+
);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
When PayPal is active, the modal automatically switches to a PayPal-inspired navy and yellow theme. It returns to the configured provider theme when another payment method is selected.
|
|
201
|
+
|
|
202
|
+
The Mock PayPal flow reproduces these stages:
|
|
203
|
+
|
|
204
|
+
1. **Create order** — displays a short server-order creation state and generates a `PAYPAL-MOCK-*` order ID.
|
|
205
|
+
2. **Buyer approval** — displays the simulated PayPal login and approval step.
|
|
206
|
+
3. **Capture payment** — uses the configured Mock adapter to process the approved order.
|
|
207
|
+
4. **Show result** — returns `success`, `failed`, or `cancelled` according to the selected test scenario.
|
|
208
|
+
|
|
209
|
+
```text
|
|
210
|
+
Select PayPal
|
|
211
|
+
→ Create a Mock order
|
|
212
|
+
→ Simulate buyer approval
|
|
213
|
+
→ Capture and verify
|
|
214
|
+
→ Return the payment result
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The progress indicator and Mock order ID are UI simulation data. The final `PaymentResult` continues to use the adapter-generated `paymentId`.
|
|
218
|
+
|
|
219
|
+
This package does not load the PayPal JavaScript SDK, open a real PayPal window, create a PayPal order, capture funds, or require PayPal credentials. For a live integration, your server must create the order and capture it after buyer approval. Validate supported currencies, buyer country availability, amount, merchant account, and the final capture status on your server.
|
|
220
|
+
|
|
168
221
|
## Test Scenarios
|
|
169
222
|
|
|
170
223
|
```tsx
|
|
@@ -216,12 +269,13 @@ const result = await requestPayment(
|
|
|
216
269
|
- Bank transfer: select withdrawal bank → simulate bank app or BankPay authentication → confirm transfer → `success`
|
|
217
270
|
- Virtual account: select deposit bank → issue account → display account number and deposit deadline → `pending`
|
|
218
271
|
- Mobile payment: simulate authorization → `success`
|
|
272
|
+
- PayPal: simulate server-side order creation → simulate buyer approval → simulate capture and verification → `success`
|
|
219
273
|
|
|
220
274
|
A real virtual account payment is not complete when the account is issued. The order should be marked as paid only after your server verifies the payment gateway's webhook following the deposit. `pay-rehearsal` reproduces this distinction by returning `pending` when a virtual account is issued.
|
|
221
275
|
|
|
222
|
-
##
|
|
276
|
+
## Custom Adapters and Production Boundaries
|
|
223
277
|
|
|
224
|
-
|
|
278
|
+
The adapter interface can be used as a starting point for connecting a payment gateway. The included modal remains a rehearsal UI; a production integration must replace simulated authentication with the provider's official checkout experience and verify the result on the server.
|
|
225
279
|
|
|
226
280
|
```ts
|
|
227
281
|
import type { PaymentAdapter } from "pay-rehearsal";
|
|
@@ -230,10 +284,7 @@ export const realPgAdapter: PaymentAdapter = {
|
|
|
230
284
|
name: "My Payment Gateway",
|
|
231
285
|
testMode: false,
|
|
232
286
|
|
|
233
|
-
async pay(
|
|
234
|
-
{ request, method, cardIssuer, installmentMonths, bank },
|
|
235
|
-
signal,
|
|
236
|
-
) {
|
|
287
|
+
async pay({ request, method, cardIssuer, installmentMonths, bank }, signal) {
|
|
237
288
|
// 1. Open the payment gateway SDK checkout UI.
|
|
238
289
|
// 2. Send paymentKey, orderId, and amount to your application server.
|
|
239
290
|
// 3. Have the server call the gateway's confirmation API and verify the amount.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as react from 'react';
|
|
|
2
2
|
import { ReactNode, ButtonHTMLAttributes } from 'react';
|
|
3
3
|
|
|
4
4
|
type Currency = "KRW" | "USD" | "JPY" | "EUR";
|
|
5
|
-
type PaymentMethod = "card" | "bank-transfer" | "virtual-account" | "mobile";
|
|
5
|
+
type PaymentMethod = "card" | "bank-transfer" | "virtual-account" | "mobile" | "paypal";
|
|
6
6
|
type CardIssuer = "kb-kookmin" | "shinhan" | "samsung" | "hyundai" | "lotte" | "hana" | "woori" | "nh-nonghyup" | "bc";
|
|
7
7
|
type BankCode = "kb-kookmin" | "shinhan" | "woori" | "hana" | "nh-nonghyup" | "ibk" | "kakaobank" | "tossbank";
|
|
8
8
|
type MockPaymentScenario = "success" | "failure" | "cancelled" | "random";
|