@sunbay/checkout-sdk-js 0.0.2 → 0.0.3

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 ADDED
@@ -0,0 +1,72 @@
1
+ # @sunbay/checkout-sdk-js
2
+
3
+ Browser JS SDK for embedding **Sunbay Checkout** into merchant web pages. It
4
+ renders payment UI — card fields and Apple Pay / Google Pay express buttons —
5
+ inside secure, Sunbay-hosted iframes, so **card data never touches the merchant
6
+ page**.
7
+
8
+ `createCheckout` is the single entry point: you create a checkout session
9
+ server-side, hand the resulting `sessionId` to the browser, mount Elements into
10
+ your DOM, and confirm the payment.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install @sunbay/checkout-sdk-js
16
+ ```
17
+
18
+ The protocol contract ([`@sunbay/checkout-sdk-protocol`](https://www.npmjs.com/package/@sunbay/checkout-sdk-protocol))
19
+ comes in transitively — you do not need to install it separately.
20
+
21
+ ## Quick start
22
+
23
+ A checkout session is created **server-side** by your backend (it holds the
24
+ merchant API key). The browser only ever receives a `sessionId`.
25
+
26
+ ```ts
27
+ import { createCheckout } from '@sunbay/checkout-sdk-js';
28
+
29
+ // 1. Create the checkout instance from a server-created session.
30
+ const checkout = await createCheckout({
31
+ sessionId, // from your backend
32
+ env: 'prod',
33
+ });
34
+
35
+ // 2. Mount Elements into your DOM.
36
+ await checkout.create('cardNumber').mount('#card-number');
37
+ await checkout.create('cardExpiry').mount('#card-expiry');
38
+ await checkout.create('cardCvc').mount('#card-cvc');
39
+
40
+ // Express wallets (Apple Pay / Google Pay) render their own buttons.
41
+ const express = checkout.create('expressCheckout');
42
+ express.on('expressAvailabilityChange', (evt) => {
43
+ console.log('available wallets:', evt.availableWallets);
44
+ });
45
+ await express.mount('#express');
46
+
47
+ // 3. Confirm a card payment; the result arrives as a PaymentOutcome.
48
+ checkout.on('paymentResult', (evt) => console.log(evt));
49
+ const outcome = await checkout.confirm();
50
+ ```
51
+
52
+ ## Public API
53
+
54
+ | Export | Description |
55
+ | --- | --- |
56
+ | `createCheckout(options)` | Creates a `CheckoutInstance` from a server-created session. Options include `sessionId` and `env` (`'test' \| 'prod'`). |
57
+ | `CheckoutInstance` | The checkout handle: `create(elementType)`, `confirm()`, `on(event, handler)`, `update(...)`, `destroy()`. |
58
+ | `CheckoutElement` | A mounted UI element handle: `mount(selector)`, `update(...)`, `on(...)`, `destroy()`. |
59
+ | `version` | The SDK version string. |
60
+ | Protocol types | Public TS types re-exported from `@sunbay/checkout-sdk-protocol` (`PaymentOutcome`, `PublicSessionView`, `Appearance`, `ElementType`, `ElementOptions`, `CheckoutError`, …). |
61
+
62
+ ## Security model
63
+
64
+ Card data is entered only inside Sunbay-hosted iframes and is encrypted and sent
65
+ directly to Sunbay — it is never exposed to the merchant page or passed across
66
+ the SDK boundary. This keeps the merchant integration out of PCI card-data
67
+ scope.
68
+
69
+ ## Versioning
70
+
71
+ The JS SDK and the protocol contract are released **in lockstep** and always
72
+ share the same version number.