@htmlbricks/hb-payment-paypal 0.71.35 → 0.71.37
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 +113 -22
- package/manifest.json +24 -8
- package/package.json +1 -1
- package/types/webcomponent.type.d.json +1 -3
- package/types/webcomponent.type.d.ts +6 -6
package/README.md
CHANGED
|
@@ -1,39 +1,130 @@
|
|
|
1
|
-
|
|
1
|
+
# `hb-payment-paypal` — integrator guide
|
|
2
2
|
|
|
3
|
-
**Category:** commerce
|
|
4
|
-
**Tags:** commerce, payment
|
|
3
|
+
**Category:** commerce · **Tags:** commerce, payment · **Package:** `@htmlbricks/hb-payment-paypal`
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
## Summary
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
`hb-payment-paypal` loads the official [PayPal JS SDK](https://developer.paypal.com/docs/checkout/) using your **client id** and **currency**, renders **PayPal Buttons** for a **single fixed order total**, and on buyer approval runs **order capture** (`intent: "CAPTURE"`). When capture succeeds, the element dispatches a **`paymentCompleted`** custom event so your host page can continue checkout, clear a cart, or show a receipt.
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
The visible PayPal button chrome is drawn by PayPal inside the mounted region; this web component owns wiring, totals, and the completion event.
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
## Custom element tag
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
```html
|
|
14
|
+
<hb-payment-paypal …></hb-payment-paypal>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Attributes (HTML / reflected props)
|
|
18
|
+
|
|
19
|
+
All names are **snake_case**. Values from HTML are **strings**; **`total`** is coerced with **`Number(...)`** inside the component.
|
|
20
|
+
|
|
21
|
+
| Attribute | Required | Description |
|
|
22
|
+
|-----------|----------|-------------|
|
|
23
|
+
| `paypalid` | Yes | PayPal **client id** (passed to the SDK as **`client-id`**). |
|
|
24
|
+
| `currency` | No | **`EUR`** or **`USD`** (uppercased when set; defaults to **`EUR`**). |
|
|
25
|
+
| `total` | No | Order amount (string or number after coercion; default **`0`** in the implementation). |
|
|
26
|
+
| `id` | No | Optional host id. |
|
|
27
|
+
| `style` | No | Optional on **`Component`**; normal host **`style`** still applies in the light DOM. |
|
|
28
|
+
|
|
29
|
+
## Behavior
|
|
30
|
+
|
|
31
|
+
1. **Script load:** On mount and when `paypalid` / `currency` / `total` change, the component calls `loadScript` from `@paypal/paypal-js` with `client-id` and `currency`.
|
|
32
|
+
2. **Buttons:** Renders PayPal Buttons with `layout: "horizontal"`, `tagline: false`, `height: 40`.
|
|
33
|
+
3. **Order creation:** `createOrder` builds one purchase unit with `intent: "CAPTURE"` and `amount` `{ currency_code, value: String(total) }`.
|
|
34
|
+
4. **Approval:** `onApprove` calls `actions.order.capture()`. On success it dispatches **`paymentCompleted`** with `{ method: "paypal", total }` where `total` is the **numeric** prop value used for the order (not necessarily re-read from PayPal’s response).
|
|
35
|
+
5. **Teardown:** On component destroy, it attempts `paypal.Buttons?.().close?.()` to release the button instance.
|
|
36
|
+
6. **Errors:** SDK load or render failures are logged with `console.error`; they do not emit a dedicated custom event in the current implementation.
|
|
37
|
+
|
|
38
|
+
Changing **`paypalid`**, **`currency`**, or **`total`** after load can trigger a remount path (existing buttons are closed before a new load). Ensure your host state stays in sync with the amount shown to the buyer.
|
|
39
|
+
|
|
40
|
+
## Events
|
|
41
|
+
|
|
42
|
+
Listen with `addEventListener` or framework bindings on the custom element.
|
|
43
|
+
|
|
44
|
+
| Event | `detail` |
|
|
45
|
+
|-------|----------|
|
|
46
|
+
| `paymentCompleted` | `{ method: "paypal"; total: number }` |
|
|
47
|
+
|
|
48
|
+
Use this event as the signal that **capture completed on the client**; still verify the transaction on your **server** (webhooks or REST) before fulfilling goods or services.
|
|
49
|
+
|
|
50
|
+
## Styling
|
|
51
|
+
|
|
52
|
+
The shadow tree forwards Bulma theme setup on `:host`. PayPal’s iframe still controls the inner button pixels.
|
|
15
53
|
|
|
16
|
-
|
|
17
|
-
- `paypalid` (required): string — PayPal client / app id.
|
|
18
|
-
- `currency` (required): `"EUR"` | `"USD"` (string).
|
|
19
|
-
- `total` (required): number as string — order amount.
|
|
54
|
+
**CSS custom properties** (documented in `extra/docs.ts`):
|
|
20
55
|
|
|
21
|
-
|
|
56
|
+
| Variable | Role |
|
|
57
|
+
|----------|------|
|
|
58
|
+
| `--bulma-background` | Surface behind the PayPal mount region. |
|
|
59
|
+
| `--bulma-text` | Inline copy or labels beside the SDK (if any). |
|
|
60
|
+
| `--bulma-border` | Dividers next to sibling checkout panels. |
|
|
61
|
+
| `--bulma-radius` | Corner radius for Bulma-framed wrappers. |
|
|
62
|
+
| `--hb-checkout-border` | Legacy divider token for composite checkout layouts (defaults to `--bulma-border`). |
|
|
22
63
|
|
|
23
|
-
-
|
|
64
|
+
See [Bulma CSS variables](https://bulma.io/documentation/features/css-variables/) for how to set `--bulma-*` on ancestors.
|
|
24
65
|
|
|
25
|
-
|
|
66
|
+
**CSS part**
|
|
26
67
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
68
|
+
| Part | Target |
|
|
69
|
+
|------|--------|
|
|
70
|
+
| `btn` | Host wrapper around the PayPal Buttons mount (`#paypalbtn`). Use `::part(btn)` for **layout and spacing** around the SDK; do not expect to theme PayPal’s internal button art. |
|
|
30
71
|
|
|
31
|
-
|
|
72
|
+
## TypeScript typings (authoring)
|
|
32
73
|
|
|
33
|
-
|
|
74
|
+
From `types/webcomponent.type.d.ts`: **`Component`** (`paypalid`, optional **`currency`**, **`total`**, **`id`**, **`style`**) and **`Events`** (`paymentCompleted`).
|
|
34
75
|
|
|
35
|
-
|
|
76
|
+
## Integration notes
|
|
77
|
+
|
|
78
|
+
- **Content Security Policy:** Allow PayPal’s script and frame origins required by the JS SDK and Smart Payment Buttons, or the load/render step will fail.
|
|
79
|
+
- **Sandbox vs live:** Use a **sandbox client id** during development and your **live client id** in production; totals and currency must match what you persist for the order.
|
|
80
|
+
- **Currencies:** Only **EUR** and **USD** are handled in the type layer; other codes are not part of the declared `Component` contract.
|
|
81
|
+
- **Card UI:** Older commented markup in `component.wc.svelte` referenced an `hb-form` card flow; that path is **not** active in the shipped template. This component is **PayPal-button only** today.
|
|
82
|
+
|
|
83
|
+
## Examples
|
|
84
|
+
|
|
85
|
+
### Minimal markup
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<hb-payment-paypal
|
|
89
|
+
paypalid="YOUR_CLIENT_ID"
|
|
90
|
+
currency="EUR"
|
|
91
|
+
total="40"
|
|
92
|
+
></hb-payment-paypal>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### With completion handler
|
|
36
96
|
|
|
37
97
|
```html
|
|
38
|
-
<hb-payment-paypal
|
|
98
|
+
<hb-payment-paypal
|
|
99
|
+
id="checkout-paypal"
|
|
100
|
+
paypalid="YOUR_CLIENT_ID"
|
|
101
|
+
currency="USD"
|
|
102
|
+
total="12.50"
|
|
103
|
+
></hb-payment-paypal>
|
|
104
|
+
|
|
105
|
+
<script>
|
|
106
|
+
const el = document.getElementById("checkout-paypal");
|
|
107
|
+
el.addEventListener("paymentCompleted", (e) => {
|
|
108
|
+
const { method, total } = e.detail;
|
|
109
|
+
console.log("Captured", method, total);
|
|
110
|
+
});
|
|
111
|
+
</script>
|
|
39
112
|
```
|
|
113
|
+
|
|
114
|
+
### Fractional totals
|
|
115
|
+
|
|
116
|
+
```html
|
|
117
|
+
<hb-payment-paypal
|
|
118
|
+
paypalid="YOUR_CLIENT_ID"
|
|
119
|
+
currency="EUR"
|
|
120
|
+
total="1499.99"
|
|
121
|
+
></hb-payment-paypal>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Related files
|
|
125
|
+
|
|
126
|
+
| File | Purpose |
|
|
127
|
+
|------|---------|
|
|
128
|
+
| `component.wc.svelte` | PayPal SDK load, buttons, capture, event dispatch. |
|
|
129
|
+
| `types/webcomponent.type.d.ts` | `Component` and `Events` typings for authors and generated declarations. |
|
|
130
|
+
| `extra/docs.ts` | Catalog metadata, `styleSetup` (vars / parts), Storybook args, examples. |
|
package/manifest.json
CHANGED
|
@@ -60,9 +60,7 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"required": [
|
|
63
|
-
"paypalid"
|
|
64
|
-
"currency",
|
|
65
|
-
"total"
|
|
63
|
+
"paypalid"
|
|
66
64
|
],
|
|
67
65
|
"type": "object"
|
|
68
66
|
}
|
|
@@ -87,23 +85,41 @@
|
|
|
87
85
|
},
|
|
88
86
|
"styleSetup": {
|
|
89
87
|
"vars": [
|
|
88
|
+
{
|
|
89
|
+
"name": "--bulma-background",
|
|
90
|
+
"valueType": "color",
|
|
91
|
+
"defaultValue": "#ffffff",
|
|
92
|
+
"description": "Host surface behind the PayPal mount region."
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "--bulma-text",
|
|
96
|
+
"valueType": "color",
|
|
97
|
+
"defaultValue": "#363636",
|
|
98
|
+
"description": "Any inline copy or labels rendered beside the SDK mount."
|
|
99
|
+
},
|
|
90
100
|
{
|
|
91
101
|
"name": "--bulma-border",
|
|
92
102
|
"valueType": "color",
|
|
93
103
|
"defaultValue": "#dbdbdb",
|
|
94
|
-
"description": "
|
|
104
|
+
"description": "Dividers when the block sits next to other checkout panels."
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "--bulma-radius",
|
|
108
|
+
"valueType": "number",
|
|
109
|
+
"defaultValue": "0.375rem",
|
|
110
|
+
"description": "Corner radius for any Bulma-framed wrapper around the mount."
|
|
95
111
|
},
|
|
96
112
|
{
|
|
97
113
|
"name": "--hb-checkout-border",
|
|
98
114
|
"valueType": "color",
|
|
99
|
-
"defaultValue": "",
|
|
100
|
-
"description": "Legacy divider
|
|
115
|
+
"defaultValue": "var(--bulma-border)",
|
|
116
|
+
"description": "Legacy divider token for parent checkout layouts (falls back to Bulma border)."
|
|
101
117
|
}
|
|
102
118
|
],
|
|
103
119
|
"parts": [
|
|
104
120
|
{
|
|
105
121
|
"name": "btn",
|
|
106
|
-
"description": "
|
|
122
|
+
"description": "Host wrapper around the PayPal Buttons mount target (`#paypalbtn`)."
|
|
107
123
|
}
|
|
108
124
|
]
|
|
109
125
|
},
|
|
@@ -168,5 +184,5 @@
|
|
|
168
184
|
"size": {},
|
|
169
185
|
"iifePath": "main.iife.js",
|
|
170
186
|
"repoName": "@htmlbricks/hb-payment-paypal",
|
|
171
|
-
"version": "0.71.
|
|
187
|
+
"version": "0.71.37"
|
|
172
188
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlbricks/hb-payment-paypal",
|
|
3
|
-
"version": "0.71.
|
|
3
|
+
"version": "0.71.37",
|
|
4
4
|
"contributors": [],
|
|
5
5
|
"description": "Loads the PayPal JS SDK with your client id and currency, renders PayPal Buttons for a fixed order total, captures payment on approval, and dispatches paymentCompleted when the order is captured successfully.",
|
|
6
6
|
"licenses": [
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export type Component = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
id?: string;
|
|
3
|
+
style?: string;
|
|
4
|
+
paypalid: string;
|
|
5
|
+
currency?: "EUR" | "USD";
|
|
6
|
+
total?: number;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export type Events = {
|
|
10
|
-
|
|
10
|
+
paymentCompleted: { method: "paypal"; total: number };
|
|
11
11
|
};
|