ucashpay-solid 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 U.CASH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # ucashpay-solid
2
+
3
+ SolidJS components and helpers for [U.CASH Pay](https://pay.u.cash): a **Pay-with-U.CASH** button plus a server-side checkout helper. Accept crypto + cards. Non-custodial: funds settle direct to the merchant's wallet.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install ucashpay-solid solid-js
9
+ ```
10
+
11
+ ## Client-side button (no server needed)
12
+
13
+ The Cloud token is publishable, so you can render a pay link straight from the browser:
14
+
15
+ ```tsx
16
+ import { UcashPayButton } from 'ucashpay-solid';
17
+
18
+ export default function Buy() {
19
+ return <UcashPayButton cloud="YOUR_CLOUD_TOKEN" amount="10" currency="USD" title="Pro plan" />;
20
+ }
21
+ ```
22
+
23
+ Or build the URL yourself with `hostedCheckoutUrl({ cloud, amount, currency, title, externalReference, redirectUrl })`.
24
+
25
+ ## Server-side tracked checkout
26
+
27
+ For a transaction record + webhook, create the checkout server-side:
28
+
29
+ ```ts
30
+ import { createUcashCheckout } from 'ucashpay-solid';
31
+ const r = await createUcashCheckout({ cloud: process.env.UCASH_CLOUD_TOKEN!, amount: '10', currency: 'USD', externalReference: 'order-123' });
32
+ if (r.ok) redirect(r.payment_url);
33
+ ```
34
+
35
+ ## Set up your pay.u.cash account
36
+
37
+ You need a free U.CASH Pay account and a store before this can accept payments. Settlement is non-custodial: crypto goes straight to addresses you control.
38
+
39
+ 1. **Sign up** at [pay.u.cash](https://pay.u.cash), then click the verification link in the email.
40
+ 2. **Set receive addresses** under **Settings -> Addresses** (raw address, ENS, Unstoppable Domains, or FIO).
41
+ 3. **Create a store** under **Account -> Stores** and copy its **Store Cloud Token** (use the store-level token, not the account-wide one).
42
+ 4. To also accept fiat cards, connect your own Stripe under **Settings -> Payment processors**.
43
+
44
+ License: MIT.
@@ -0,0 +1,34 @@
1
+ import { JSX } from 'solid-js';
2
+
3
+ interface HostedCheckoutOptions {
4
+ cloud: string;
5
+ amount: string | number;
6
+ currency?: string;
7
+ title?: string;
8
+ externalReference?: string;
9
+ redirectUrl?: string;
10
+ baseUrl?: string;
11
+ }
12
+ /** Build a hosted U.CASH Pay checkout URL (publishable cloud token, no server needed). */
13
+ declare function hostedCheckoutUrl(opts: HostedCheckoutOptions): string;
14
+ interface UcashPayButtonProps extends HostedCheckoutOptions {
15
+ buttonText?: string;
16
+ class?: string;
17
+ style?: JSX.CSSProperties;
18
+ children?: JSX.Element;
19
+ }
20
+ /** A "Pay with U.CASH" button/link that opens the hosted checkout. Pure client-side. */
21
+ declare function UcashPayButton(props: UcashPayButtonProps): JSX.Element;
22
+ interface CreateCheckoutResult {
23
+ ok: boolean;
24
+ payment_url: string;
25
+ transaction_id: number | null;
26
+ message?: string;
27
+ }
28
+ /**
29
+ * Server-side helper: create a transaction-tracked checkout and return the payment URL + id.
30
+ * Call from a server route. Idempotent per externalReference.
31
+ */
32
+ declare function createUcashCheckout(params: HostedCheckoutOptions): Promise<CreateCheckoutResult>;
33
+
34
+ export { type CreateCheckoutResult, type HostedCheckoutOptions, UcashPayButton, type UcashPayButtonProps, createUcashCheckout, hostedCheckoutUrl };
@@ -0,0 +1,34 @@
1
+ import { JSX } from 'solid-js';
2
+
3
+ interface HostedCheckoutOptions {
4
+ cloud: string;
5
+ amount: string | number;
6
+ currency?: string;
7
+ title?: string;
8
+ externalReference?: string;
9
+ redirectUrl?: string;
10
+ baseUrl?: string;
11
+ }
12
+ /** Build a hosted U.CASH Pay checkout URL (publishable cloud token, no server needed). */
13
+ declare function hostedCheckoutUrl(opts: HostedCheckoutOptions): string;
14
+ interface UcashPayButtonProps extends HostedCheckoutOptions {
15
+ buttonText?: string;
16
+ class?: string;
17
+ style?: JSX.CSSProperties;
18
+ children?: JSX.Element;
19
+ }
20
+ /** A "Pay with U.CASH" button/link that opens the hosted checkout. Pure client-side. */
21
+ declare function UcashPayButton(props: UcashPayButtonProps): JSX.Element;
22
+ interface CreateCheckoutResult {
23
+ ok: boolean;
24
+ payment_url: string;
25
+ transaction_id: number | null;
26
+ message?: string;
27
+ }
28
+ /**
29
+ * Server-side helper: create a transaction-tracked checkout and return the payment URL + id.
30
+ * Call from a server route. Idempotent per externalReference.
31
+ */
32
+ declare function createUcashCheckout(params: HostedCheckoutOptions): Promise<CreateCheckoutResult>;
33
+
34
+ export { type CreateCheckoutResult, type HostedCheckoutOptions, UcashPayButton, type UcashPayButtonProps, createUcashCheckout, hostedCheckoutUrl };
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.tsx
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ UcashPayButton: () => UcashPayButton,
24
+ createUcashCheckout: () => createUcashCheckout,
25
+ hostedCheckoutUrl: () => hostedCheckoutUrl
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var DEFAULT_BASE = "https://pay.u.cash";
29
+ function hostedCheckoutUrl(opts) {
30
+ const base = (opts.baseUrl || DEFAULT_BASE).replace(/\/+$/, "");
31
+ const params = new URLSearchParams({ cloud: opts.cloud, amount: String(opts.amount) });
32
+ if (opts.currency) params.set("currency", opts.currency);
33
+ if (opts.title) params.set("title", opts.title);
34
+ if (opts.externalReference) params.set("external_reference", opts.externalReference);
35
+ if (opts.redirectUrl) params.set("redirect", opts.redirectUrl);
36
+ return `${base}/embed.php?${params.toString()}`;
37
+ }
38
+ function UcashPayButton(props) {
39
+ const href = () => hostedCheckoutUrl({
40
+ cloud: props.cloud,
41
+ amount: props.amount,
42
+ currency: props.currency ?? "USD",
43
+ title: props.title,
44
+ externalReference: props.externalReference,
45
+ redirectUrl: props.redirectUrl,
46
+ baseUrl: props.baseUrl
47
+ });
48
+ return /* @__PURE__ */ React.createElement("a", { href: href(), target: "_blank", rel: "noopener noreferrer", class: props.class, style: props.style }, props.children ?? props.buttonText ?? "Pay with U.CASH");
49
+ }
50
+ async function createUcashCheckout(params) {
51
+ const base = (params.baseUrl || DEFAULT_BASE).replace(/\/+$/, "");
52
+ const body = new URLSearchParams({
53
+ function: "create-transaction",
54
+ amount: String(params.amount),
55
+ currency_code: params.currency || "USD",
56
+ cryptocurrency_code: "",
57
+ external_reference: params.externalReference || "",
58
+ title: params.title || "",
59
+ redirect: params.redirectUrl || "",
60
+ cloud: params.cloud,
61
+ idempotent: "1"
62
+ });
63
+ const res = await fetch(`${base}/payment/ajax.php`, {
64
+ method: "POST",
65
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
66
+ body
67
+ });
68
+ const json = await res.json();
69
+ let payment_url = "";
70
+ let transaction_id = null;
71
+ if (Array.isArray(json.response)) {
72
+ for (const v of json.response) {
73
+ if (!payment_url && typeof v === "string" && /^https?:\/\//i.test(v)) payment_url = v;
74
+ if (transaction_id === null && (typeof v === "number" || /^\d+$/.test(String(v)))) {
75
+ const n = Number(v);
76
+ if (n > 0) transaction_id = n;
77
+ }
78
+ }
79
+ }
80
+ return { ok: !!json.success, payment_url, transaction_id, message: json.message };
81
+ }
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ UcashPayButton,
85
+ createUcashCheckout,
86
+ hostedCheckoutUrl
87
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,60 @@
1
+ // src/index.tsx
2
+ var DEFAULT_BASE = "https://pay.u.cash";
3
+ function hostedCheckoutUrl(opts) {
4
+ const base = (opts.baseUrl || DEFAULT_BASE).replace(/\/+$/, "");
5
+ const params = new URLSearchParams({ cloud: opts.cloud, amount: String(opts.amount) });
6
+ if (opts.currency) params.set("currency", opts.currency);
7
+ if (opts.title) params.set("title", opts.title);
8
+ if (opts.externalReference) params.set("external_reference", opts.externalReference);
9
+ if (opts.redirectUrl) params.set("redirect", opts.redirectUrl);
10
+ return `${base}/embed.php?${params.toString()}`;
11
+ }
12
+ function UcashPayButton(props) {
13
+ const href = () => hostedCheckoutUrl({
14
+ cloud: props.cloud,
15
+ amount: props.amount,
16
+ currency: props.currency ?? "USD",
17
+ title: props.title,
18
+ externalReference: props.externalReference,
19
+ redirectUrl: props.redirectUrl,
20
+ baseUrl: props.baseUrl
21
+ });
22
+ return /* @__PURE__ */ React.createElement("a", { href: href(), target: "_blank", rel: "noopener noreferrer", class: props.class, style: props.style }, props.children ?? props.buttonText ?? "Pay with U.CASH");
23
+ }
24
+ async function createUcashCheckout(params) {
25
+ const base = (params.baseUrl || DEFAULT_BASE).replace(/\/+$/, "");
26
+ const body = new URLSearchParams({
27
+ function: "create-transaction",
28
+ amount: String(params.amount),
29
+ currency_code: params.currency || "USD",
30
+ cryptocurrency_code: "",
31
+ external_reference: params.externalReference || "",
32
+ title: params.title || "",
33
+ redirect: params.redirectUrl || "",
34
+ cloud: params.cloud,
35
+ idempotent: "1"
36
+ });
37
+ const res = await fetch(`${base}/payment/ajax.php`, {
38
+ method: "POST",
39
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
40
+ body
41
+ });
42
+ const json = await res.json();
43
+ let payment_url = "";
44
+ let transaction_id = null;
45
+ if (Array.isArray(json.response)) {
46
+ for (const v of json.response) {
47
+ if (!payment_url && typeof v === "string" && /^https?:\/\//i.test(v)) payment_url = v;
48
+ if (transaction_id === null && (typeof v === "number" || /^\d+$/.test(String(v)))) {
49
+ const n = Number(v);
50
+ if (n > 0) transaction_id = n;
51
+ }
52
+ }
53
+ }
54
+ return { ok: !!json.success, payment_url, transaction_id, message: json.message };
55
+ }
56
+ export {
57
+ UcashPayButton,
58
+ createUcashCheckout,
59
+ hostedCheckoutUrl
60
+ };
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "ucashpay-solid",
3
+ "version": "0.1.0",
4
+ "description": "SolidJS components and helpers for U.CASH Pay: a Pay-with-U.CASH button + server-side checkout creation. Non-custodial.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": ["dist"],
9
+ "scripts": { "build": "tsup src/index.tsx --format cjs,esm --dts", "dev": "tsup src/index.tsx --format cjs,esm --dts --watch" },
10
+ "keywords": ["ucash","u.cash","solid","solidjs","payments","crypto","bitcoin","checkout","non-custodial"],
11
+ "peerDependencies": { "solid-js": ">=1.7.0" },
12
+ "devDependencies": { "solid-js": "^1.8.0", "tsup": "^8.0.0", "typescript": "^5.4.0" },
13
+ "license": "MIT"
14
+ }