@alphadevs_labs/upay-sdk 0.0.1 → 0.0.2
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 +127 -0
- package/package.json +3 -1
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @alphadevs_labs/upay-sdk
|
|
2
|
+
|
|
3
|
+
The official SDK for [UPay](https://tryupay.xyz) — a Stripe-style crypto checkout. Drop a Pay button on any website and let customers pay with whatever tokens they hold, on whatever chain, in one tap. You receive your chosen stablecoin on your chosen chain, powered by [Particle Network Universal Accounts](https://particle.network).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @alphadevs_labs/upay-sdk
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @alphadevs_labs/upay-sdk
|
|
11
|
+
# or
|
|
12
|
+
yarn add @alphadevs_labs/upay-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires React ≥ 18 (only needed if you use `UPayButton`; the imperative `UPay` client has no React dependency).
|
|
16
|
+
|
|
17
|
+
## Quick start — React
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { UPayButton } from "@alphadevs_labs/upay-sdk";
|
|
21
|
+
|
|
22
|
+
export function CheckoutButton() {
|
|
23
|
+
return (
|
|
24
|
+
<UPayButton
|
|
25
|
+
apiKey="pk_live_..."
|
|
26
|
+
amount="40"
|
|
27
|
+
token="USDC"
|
|
28
|
+
chain="base"
|
|
29
|
+
onSuccess={(payment) => console.log("Paid!", payment.txHashes)}
|
|
30
|
+
onError={(err) => console.error(err)}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Clicking the button creates a checkout session against your UPay account and opens it in an embedded modal. On success, `onSuccess` fires with the completed payment.
|
|
37
|
+
|
|
38
|
+
## Quick start — imperative client
|
|
39
|
+
|
|
40
|
+
Use `UPay` directly if you're not in React, or want full control over the checkout flow:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { UPay } from "@alphadevs_labs/upay-sdk";
|
|
44
|
+
|
|
45
|
+
const upay = new UPay({ apiKey: "pk_live_..." });
|
|
46
|
+
|
|
47
|
+
const session = await upay.createCheckout({
|
|
48
|
+
amount: "40",
|
|
49
|
+
token: "USDC",
|
|
50
|
+
chain: "base",
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
upay.openCheckout(session.id);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick start — script tag (no build step)
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<script src="https://tryupay.xyz/sdk.js" defer></script>
|
|
60
|
+
|
|
61
|
+
<div
|
|
62
|
+
data-upay-button
|
|
63
|
+
data-key="pk_live_..."
|
|
64
|
+
data-amount="40"
|
|
65
|
+
data-token="USDC"
|
|
66
|
+
data-chain="base"
|
|
67
|
+
></div>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The script scans the page for `[data-upay-button]` elements on load and mounts a working Pay button into each one.
|
|
71
|
+
|
|
72
|
+
## API reference
|
|
73
|
+
|
|
74
|
+
### `<UPayButton />`
|
|
75
|
+
|
|
76
|
+
| Prop | Type | Required | Description |
|
|
77
|
+
|---|---|---|---|
|
|
78
|
+
| `apiKey` | `string` | ✅ | Your publishable key (`pk_live_...`), safe to expose client-side. |
|
|
79
|
+
| `amount` | `string` | ✅ | Amount to charge, in the settlement token's units. |
|
|
80
|
+
| `baseUrl` | `string` | | Override the UPay API/checkout host. Defaults to the current origin. |
|
|
81
|
+
| `token` | `string` | | Settlement token override (e.g. `"USDC"`). |
|
|
82
|
+
| `chain` | `string` | | Settlement chain override (e.g. `"base"`). |
|
|
83
|
+
| `metadata` | `Record<string, unknown>` | | Arbitrary metadata attached to the session (order id, product id, etc.). |
|
|
84
|
+
| `label` | `string` | | Button text. Defaults to `"Pay with UPay"`. |
|
|
85
|
+
| `className` | `string` | | Use your own styles instead of the built-in gradient button. |
|
|
86
|
+
| `onSuccess` | `(payment: UPayPayment) => void` | | Called once the payment is confirmed. |
|
|
87
|
+
| `onError` | `(err: Error) => void` | | Called if session creation or checkout fails. |
|
|
88
|
+
|
|
89
|
+
### `new UPay(options)`
|
|
90
|
+
|
|
91
|
+
| Option | Type | Required | Description |
|
|
92
|
+
|---|---|---|---|
|
|
93
|
+
| `apiKey` | `string` | ✅ | Your publishable key. |
|
|
94
|
+
| `baseUrl` | `string` | | Override the UPay API/checkout host. |
|
|
95
|
+
|
|
96
|
+
**`upay.createCheckout(options)`** → `Promise<UPayCheckoutSession>`
|
|
97
|
+
|
|
98
|
+
| Option | Type | Required |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| `amount` | `string` | ✅ |
|
|
101
|
+
| `token` | `string` | |
|
|
102
|
+
| `chain` | `string` | |
|
|
103
|
+
| `metadata` | `Record<string, unknown>` | |
|
|
104
|
+
| `successUrl` | `string` | |
|
|
105
|
+
| `cancelUrl` | `string` | |
|
|
106
|
+
|
|
107
|
+
**`upay.openCheckout(sessionId)`** — mounts an embedded checkout modal (iframe) for the given session and handles close/resize/success messaging automatically.
|
|
108
|
+
|
|
109
|
+
## Types
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import type {
|
|
113
|
+
UPayButtonProps,
|
|
114
|
+
UPayPayment,
|
|
115
|
+
UPayCheckoutSession,
|
|
116
|
+
UPayClientOptions,
|
|
117
|
+
CreateCheckoutOptions,
|
|
118
|
+
} from "@alphadevs_labs/upay-sdk";
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Getting API keys
|
|
122
|
+
|
|
123
|
+
Sign up and create a merchant account at [tryupay.xyz/dashboard](https://tryupay.xyz/dashboard) to get your publishable (`pk_live_...`) and secret (`sk_live_...`) keys. Only the publishable key is used by this SDK — never expose your secret key client-side.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alphadevs_labs/upay-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "UPay SDK — UPayButton React component and imperative client",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"homepage": "https://tryupay.xyz",
|
|
6
7
|
"publishConfig": {
|
|
7
8
|
"access": "public"
|
|
8
9
|
},
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
"type": "git",
|
|
11
12
|
"url": "https://github.com/0xyshv/upay"
|
|
12
13
|
},
|
|
14
|
+
"keywords": ["crypto", "checkout", "payments", "web3", "stablecoin", "sdk"],
|
|
13
15
|
"main": "./dist/index.js",
|
|
14
16
|
"module": "./dist/index.mjs",
|
|
15
17
|
"types": "./dist/index.d.ts",
|