straumur-web-component 1.1.4-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.d.ts +8 -0
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -12
- 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
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,9 @@ type StraumurWebConfiguration = {
|
|
|
83
83
|
locale?: "is" | "en";
|
|
84
84
|
localizations?: Partial<Record<Language, Partial<Record<TranslationKey, string>>>>;
|
|
85
85
|
instantPayments?: UniqueInstantPayments;
|
|
86
|
+
hideSubmitButton?: boolean;
|
|
87
|
+
onCardValidityChanged?: (isValid: boolean, isActive: boolean) => void;
|
|
88
|
+
allowedPaymentMethods?: PaymentMethod[];
|
|
86
89
|
};
|
|
87
90
|
type ResultCode = "AuthenticationFinished" | "AuthenticationNotRequired" | "Authorised" | "Cancelled" | "ChallengeShopper" | "Error" | "IdentifyShopper" | "PartiallyAuthorised" | "Pending" | "PresentToShopper" | "Received" | "RedirectShopper" | "Refused";
|
|
88
91
|
type PaymentCompletedData = {
|
|
@@ -101,6 +104,9 @@ type StraumurCheckoutConfiguration = {
|
|
|
101
104
|
locale: Language;
|
|
102
105
|
customLocalizations?: Partial<Record<Language, Partial<Record<TranslationKey, string>>>>;
|
|
103
106
|
instantPayments?: UniqueInstantPayments;
|
|
107
|
+
hideSubmitButton?: boolean;
|
|
108
|
+
onCardValidityChanged?: (isValid: boolean, isActive: boolean) => void;
|
|
109
|
+
allowedPaymentMethods?: PaymentMethod[];
|
|
104
110
|
};
|
|
105
111
|
type PlaceholderKeys = "cardNumber" | "expiryDate" | "expiryMonth" | "expiryYear" | "securityCodeThreeDigits" | "securityCodeFourDigits";
|
|
106
112
|
type Placeholders = Partial<Record<PlaceholderKeys, string>>;
|
|
@@ -110,6 +116,7 @@ declare class StraumurCheckout {
|
|
|
110
116
|
private paymentMethods;
|
|
111
117
|
private mountElement;
|
|
112
118
|
private i18n;
|
|
119
|
+
private submitApi;
|
|
113
120
|
constructor(config: StraumurWebConfiguration);
|
|
114
121
|
mount(selector: HTMLElement | string): Promise<void>;
|
|
115
122
|
private renderComponent;
|
|
@@ -120,6 +127,7 @@ declare class StraumurCheckout {
|
|
|
120
127
|
updateConfig(newConfig: Partial<StraumurCheckoutConfiguration>): void;
|
|
121
128
|
setLanguage(locale: Language): void;
|
|
122
129
|
destroy(): void;
|
|
130
|
+
submitCard(): boolean;
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
export { StraumurCheckout };
|