straumur-web-component 1.1.5-alpha.1 → 1.1.6-alpha.1
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 +129 -0
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1 +1,130 @@
|
|
|
1
1
|
# straumur-web-component
|
|
2
|
+
|
|
3
|
+
An embeddable, PCI-friendly checkout component for accepting card, Google Pay, and Apple Pay
|
|
4
|
+
payments through [Straumur](https://straumur.is). It renders a complete payment UI into an element
|
|
5
|
+
on your page and handles the payment flow (including 3‑D Secure) for you.
|
|
6
|
+
|
|
7
|
+
📚 **Full documentation:** <https://docs.straumur.is> — see
|
|
8
|
+
[Straumur Components](https://docs.straumur.is/category/straumur-components) and the
|
|
9
|
+
[Web Integration](https://docs.straumur.is/payment-gateway/components/straumur-components/web-component)
|
|
10
|
+
guide.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install straumur-web-component
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
The component is driven by a **session**. First, create a session from your backend by calling
|
|
21
|
+
Straumur's [`/embeddedcheckout/session`](https://docs.straumur.is/payment-gateway/components/straumur-components/basic-session-request)
|
|
22
|
+
endpoint — it returns a `sessionId`. Pass that `sessionId` to the component on the client.
|
|
23
|
+
|
|
24
|
+
Add a container element to your page:
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<div id="component-container"></div>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then initialize and mount the component:
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
import { StraumurCheckout } from "straumur-web-component";
|
|
34
|
+
|
|
35
|
+
const paymentConfiguration = {
|
|
36
|
+
environment: "test", // "test" | "live"
|
|
37
|
+
sessionId: "ftsdre3h...e5h5as2q4", // from your /embeddedcheckout/session response
|
|
38
|
+
onPaymentCompleted: (data) => {
|
|
39
|
+
console.info("Payment completed", data.resultCode);
|
|
40
|
+
},
|
|
41
|
+
onPaymentFailed: (data) => {
|
|
42
|
+
console.info("Payment failed", data?.resultCode);
|
|
43
|
+
},
|
|
44
|
+
locale: "en", // "is" | "en"
|
|
45
|
+
instantPayments: ["applepay", "googlepay"],
|
|
46
|
+
placeholders: {
|
|
47
|
+
cardNumber: "1234 5678 9012 3456",
|
|
48
|
+
},
|
|
49
|
+
localizations: {
|
|
50
|
+
"en-US": {
|
|
51
|
+
"cards.title": "Card Information",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const checkout = new StraumurCheckout(paymentConfiguration);
|
|
57
|
+
checkout.mount("#component-container");
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Using the CDN / script tag (no bundler)
|
|
61
|
+
|
|
62
|
+
The package also ships an IIFE build that exposes a global `StraumurWeb`:
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<div id="component-container"></div>
|
|
66
|
+
<script src="https://unpkg.com/straumur-web-component"></script>
|
|
67
|
+
<script>
|
|
68
|
+
const checkout = new StraumurWeb.StraumurCheckout({
|
|
69
|
+
environment: "test",
|
|
70
|
+
sessionId: "ftsdre3h...e5h5as2q4",
|
|
71
|
+
});
|
|
72
|
+
checkout.mount("#component-container");
|
|
73
|
+
</script>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Configuration
|
|
77
|
+
|
|
78
|
+
Passed to the `StraumurCheckout` constructor:
|
|
79
|
+
|
|
80
|
+
| Option | Type | Required | Description |
|
|
81
|
+
| -------------------- | ----------------------------------------- | :------: | --------------------------------------------------------------------------- |
|
|
82
|
+
| `sessionId` | `string` | ✅ | The session id from your `/embeddedcheckout/session` response. |
|
|
83
|
+
| `environment` | `"test" \| "live"` | ✅ | Selects the Straumur staging or production backend. |
|
|
84
|
+
| `locale` | `"is" \| "en"` | | UI language. Defaults to Icelandic (`is`). |
|
|
85
|
+
| `onPaymentCompleted` | `(data: { resultCode }) => void` | | Called when the payment flow completes (see result codes below). |
|
|
86
|
+
| `onPaymentFailed` | `(data?: { resultCode }) => void` | | Called when the payment flow fails. |
|
|
87
|
+
| `instantPayments` | `("googlepay" \| "applepay")[]` | | Renders the listed wallets as express buttons above the standard methods. |
|
|
88
|
+
| `placeholders` | `object` | | Input placeholders — see below. |
|
|
89
|
+
| `localizations` | `object` | | Override built-in copy per language and key. |
|
|
90
|
+
|
|
91
|
+
### `placeholders`
|
|
92
|
+
|
|
93
|
+
Any subset of: `cardNumber`, `expiryDate`, `expiryMonth`, `expiryYear`, `securityCodeThreeDigits`,
|
|
94
|
+
`securityCodeFourDigits`.
|
|
95
|
+
|
|
96
|
+
### `localizations`
|
|
97
|
+
|
|
98
|
+
Override any translation key per locale (`"is-IS"` / `"en-US"`). Provided strings take precedence
|
|
99
|
+
over the built-in translations; missing keys fall back to the defaults.
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
localizations: {
|
|
103
|
+
"en-US": { "cards.title": "Card Information" },
|
|
104
|
+
"is-IS": { "cards.title": "Kortaupplýsingar" },
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Instance methods
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
const checkout = new StraumurCheckout(config);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
| Method | Description |
|
|
115
|
+
| -------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
116
|
+
| `mount(selector)` | Fetches the payment methods and renders the component into a CSS selector or `HTMLElement`. Async. |
|
|
117
|
+
| `setLanguage(locale)` | Switches the UI language at runtime (e.g. `"en-US"`, `"is-IS"`). |
|
|
118
|
+
| `updateConfig(partial)` | Merges new configuration and re-renders. |
|
|
119
|
+
| `submitDetails(result)` | Completes a redirect-based (e.g. 3‑D Secure) flow using the `redirectResult` from the return URL. |
|
|
120
|
+
| `destroy()` | Unmounts the component and cleans up. |
|
|
121
|
+
|
|
122
|
+
## Payment result codes
|
|
123
|
+
|
|
124
|
+
`onPaymentCompleted` / `onPaymentFailed` receive a `resultCode` such as `Authorised`, `Refused`,
|
|
125
|
+
`ChallengeShopper`, `IdentifyShopper`, `Error`, or `Cancelled`. Note that a refused payment is a
|
|
126
|
+
normal completion of the flow — branch on `resultCode`, not on whether a callback fired.
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
MIT
|