@htmlbricks/hb-payment-paypal 0.71.34 → 0.71.36
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 +110 -22
- package/manifest.json +23 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,39 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
# hb-payment-paypal
|
|
2
2
|
|
|
3
|
-
**Category:** commerce
|
|
4
|
-
**Tags:** commerce, payment
|
|
3
|
+
**Category:** commerce · **Tags:** commerce, payment · **Package:** `@htmlbricks/hb-payment-paypal`
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
## Overview
|
|
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
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
```text
|
|
14
|
+
hb-payment-paypal
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Attributes (HTML)
|
|
18
|
+
|
|
19
|
+
All attribute names are **snake_case**. Values from HTML are **strings**; the component coerces `total` to a number when needed.
|
|
20
|
+
|
|
21
|
+
| Attribute | Required | Description |
|
|
22
|
+
|-----------|----------|-------------|
|
|
23
|
+
| `paypalid` | Yes | PayPal **client id** (REST app / “Client ID” in the PayPal Developer Dashboard). Passed to the SDK as `client-id`. |
|
|
24
|
+
| `currency` | Yes | Order currency: **`EUR`** or **`USD`**. Non-empty values are normalized to **uppercase**; if missing, the implementation defaults to **`EUR`**. |
|
|
25
|
+
| `total` | Yes | Order **amount** as a string (e.g. `"40"`, `"12.5"`). Coerced with `Number(...)` for PayPal’s `purchase_units[].amount.value`. Use a decimal string that matches your pricing rules. |
|
|
26
|
+
| `id` | No | Optional string (default empty). Reserved for host/DOM use; does not change PayPal SDK behavior in the current markup. |
|
|
27
|
+
|
|
28
|
+
> **Typings note:** `types/webcomponent.type.d.ts` may list an optional `style` field on the logical `Component` shape. The current Svelte implementation does not read `style` from props, so setting a `style` attribute has no defined effect on this build.
|
|
29
|
+
|
|
30
|
+
## Behavior
|
|
31
|
+
|
|
32
|
+
1. **Script load:** On mount and when `paypalid` / `currency` / `total` change, the component calls `loadScript` from `@paypal/paypal-js` with `client-id` and `currency`.
|
|
33
|
+
2. **Buttons:** Renders PayPal Buttons with `layout: "horizontal"`, `tagline: false`, `height: 40`.
|
|
34
|
+
3. **Order creation:** `createOrder` builds one purchase unit with `intent: "CAPTURE"` and `amount` `{ currency_code, value: String(total) }`.
|
|
35
|
+
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).
|
|
36
|
+
5. **Teardown:** On component destroy, it attempts `paypal.Buttons?.().close?.()` to release the button instance.
|
|
37
|
+
6. **Errors:** SDK load or render failures are logged with `console.error`; they do not emit a dedicated custom event in the current implementation.
|
|
38
|
+
|
|
39
|
+
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.
|
|
40
|
+
|
|
41
|
+
## Events
|
|
42
|
+
|
|
43
|
+
Listen with `addEventListener` or framework bindings on the custom element.
|
|
44
|
+
|
|
45
|
+
| Event | `detail` |
|
|
46
|
+
|-------|----------|
|
|
47
|
+
| `paymentCompleted` | `{ method: "paypal"; total: number }` |
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
## Styling
|
|
15
52
|
|
|
16
|
-
|
|
17
|
-
- `paypalid` (required): string — PayPal client / app id.
|
|
18
|
-
- `currency` (required): `"EUR"` | `"USD"` (string).
|
|
19
|
-
- `total` (required): number as string — order amount.
|
|
53
|
+
The shadow tree forwards Bulma theme setup on `:host`. PayPal’s iframe still controls the inner button pixels.
|
|
20
54
|
|
|
21
|
-
|
|
55
|
+
**CSS custom properties** (documented in `extra/docs.ts`):
|
|
22
56
|
|
|
23
|
-
|
|
57
|
+
| Variable | Role |
|
|
58
|
+
|----------|------|
|
|
59
|
+
| `--bulma-background` | Surface behind the PayPal mount region. |
|
|
60
|
+
| `--bulma-text` | Inline copy or labels beside the SDK (if any). |
|
|
61
|
+
| `--bulma-border` | Dividers next to sibling checkout panels. |
|
|
62
|
+
| `--bulma-radius` | Corner radius for Bulma-framed wrappers. |
|
|
63
|
+
| `--hb-checkout-border` | Legacy divider token for composite checkout layouts (defaults to `--bulma-border`). |
|
|
24
64
|
|
|
25
|
-
|
|
65
|
+
See [Bulma CSS variables](https://bulma.io/documentation/features/css-variables/) for how to set `--bulma-*` on ancestors.
|
|
26
66
|
|
|
27
|
-
|
|
28
|
-
- **CSS parts:** `btn` (PayPal button surface).
|
|
29
|
-
- Ensure CSP and PayPal script loading match your host app; totals are fixed for the rendered session.
|
|
67
|
+
**CSS part**
|
|
30
68
|
|
|
31
|
-
|
|
69
|
+
| Part | Target |
|
|
70
|
+
|------|--------|
|
|
71
|
+
| `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. |
|
|
32
72
|
|
|
33
|
-
|
|
73
|
+
## Integration notes
|
|
34
74
|
|
|
35
|
-
|
|
75
|
+
- **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.
|
|
76
|
+
- **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.
|
|
77
|
+
- **Currencies:** Only **EUR** and **USD** are handled in the type layer; other codes are not part of the declared `Component` contract.
|
|
78
|
+
- **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.
|
|
79
|
+
|
|
80
|
+
## Examples
|
|
81
|
+
|
|
82
|
+
### Minimal markup
|
|
36
83
|
|
|
37
84
|
```html
|
|
38
|
-
<hb-payment-paypal
|
|
85
|
+
<hb-payment-paypal
|
|
86
|
+
paypalid="YOUR_CLIENT_ID"
|
|
87
|
+
currency="EUR"
|
|
88
|
+
total="40"
|
|
89
|
+
></hb-payment-paypal>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### With completion handler
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<hb-payment-paypal
|
|
96
|
+
id="checkout-paypal"
|
|
97
|
+
paypalid="YOUR_CLIENT_ID"
|
|
98
|
+
currency="USD"
|
|
99
|
+
total="12.50"
|
|
100
|
+
></hb-payment-paypal>
|
|
101
|
+
|
|
102
|
+
<script>
|
|
103
|
+
const el = document.getElementById("checkout-paypal");
|
|
104
|
+
el.addEventListener("paymentCompleted", (e) => {
|
|
105
|
+
const { method, total } = e.detail;
|
|
106
|
+
console.log("Captured", method, total);
|
|
107
|
+
});
|
|
108
|
+
</script>
|
|
39
109
|
```
|
|
110
|
+
|
|
111
|
+
### Fractional totals
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<hb-payment-paypal
|
|
115
|
+
paypalid="YOUR_CLIENT_ID"
|
|
116
|
+
currency="EUR"
|
|
117
|
+
total="1499.99"
|
|
118
|
+
></hb-payment-paypal>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Related files
|
|
122
|
+
|
|
123
|
+
| File | Purpose |
|
|
124
|
+
|------|---------|
|
|
125
|
+
| `component.wc.svelte` | PayPal SDK load, buttons, capture, event dispatch. |
|
|
126
|
+
| `types/webcomponent.type.d.ts` | `Component` and `Events` typings for authors and generated declarations. |
|
|
127
|
+
| `extra/docs.ts` | Catalog metadata, `styleSetup` (vars / parts), Storybook args, examples. |
|
package/manifest.json
CHANGED
|
@@ -87,23 +87,41 @@
|
|
|
87
87
|
},
|
|
88
88
|
"styleSetup": {
|
|
89
89
|
"vars": [
|
|
90
|
+
{
|
|
91
|
+
"name": "--bulma-background",
|
|
92
|
+
"valueType": "color",
|
|
93
|
+
"defaultValue": "#ffffff",
|
|
94
|
+
"description": "Host surface behind the PayPal mount region."
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "--bulma-text",
|
|
98
|
+
"valueType": "color",
|
|
99
|
+
"defaultValue": "#363636",
|
|
100
|
+
"description": "Any inline copy or labels rendered beside the SDK mount."
|
|
101
|
+
},
|
|
90
102
|
{
|
|
91
103
|
"name": "--bulma-border",
|
|
92
104
|
"valueType": "color",
|
|
93
105
|
"defaultValue": "#dbdbdb",
|
|
94
|
-
"description": "
|
|
106
|
+
"description": "Dividers when the block sits next to other checkout panels."
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "--bulma-radius",
|
|
110
|
+
"valueType": "number",
|
|
111
|
+
"defaultValue": "0.375rem",
|
|
112
|
+
"description": "Corner radius for any Bulma-framed wrapper around the mount."
|
|
95
113
|
},
|
|
96
114
|
{
|
|
97
115
|
"name": "--hb-checkout-border",
|
|
98
116
|
"valueType": "color",
|
|
99
|
-
"defaultValue": "",
|
|
100
|
-
"description": "Legacy divider
|
|
117
|
+
"defaultValue": "var(--bulma-border)",
|
|
118
|
+
"description": "Legacy divider token for parent checkout layouts (falls back to Bulma border)."
|
|
101
119
|
}
|
|
102
120
|
],
|
|
103
121
|
"parts": [
|
|
104
122
|
{
|
|
105
123
|
"name": "btn",
|
|
106
|
-
"description": "
|
|
124
|
+
"description": "Host wrapper around the PayPal Buttons mount target (`#paypalbtn`)."
|
|
107
125
|
}
|
|
108
126
|
]
|
|
109
127
|
},
|
|
@@ -168,5 +186,5 @@
|
|
|
168
186
|
"size": {},
|
|
169
187
|
"iifePath": "main.iife.js",
|
|
170
188
|
"repoName": "@htmlbricks/hb-payment-paypal",
|
|
171
|
-
"version": "0.71.
|
|
189
|
+
"version": "0.71.36"
|
|
172
190
|
}
|
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.36",
|
|
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": [
|