swell-js 5.9.4 → 5.10.0

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 CHANGED
@@ -15,6 +15,48 @@ Universal JavaScript client for Swell's Frontend API, providing client-safe acce
15
15
 
16
16
  [Swell](https://www.swell.is) is an ecommerce platform with subscriptions and B2B pricing built in. Run your store on a Swell theme, or [go headless](https://www.swell.is/headless-commerce) with its APIs.
17
17
 
18
+ ## Checkout payments
19
+
20
+ Besides `createElements`, `tokenize` and `handleRedirect` (see the documentation), `swell.payment` offers helpers a checkout page needs:
21
+
22
+ - `tokenize({ card: { createIntent: false } })` stores a Stripe card without authorizing it now. `tokenize({ card: { paymentMethod: 'pm_…' } })` authorizes a Stripe card the shopper already has (a saved card, a wallet's payment method) with an intent and 3-D Secure, like a new card, before the order is submitted. Both reuse the cart's intent while it still matches the card and amount.
23
+ - Saferpay card and TWINT (`twint`) redirect to the Saferpay payment page from `tokenize` and come back through `handleRedirect`; iDEAL returns through `handleRedirect({ ideal })` too.
24
+ - Stripe iDEAL needs no element: `tokenize({ ideal: {} })` without `createElements` redirects to the iDEAL page, where the shopper picks the bank, and returns through `handleRedirect({ ideal })`.
25
+ - `handleAsyncRedirect(order)` sends the shopper to the gateway when a submitted order waits for an asynchronous payment.
26
+ - Stripe card and iDEAL can render through the Stripe [Payment Element](https://docs.stripe.com/payments/payment-element) instead of the split elements: pass `paymentElement: true` to both `createElements` and `tokenize`. Stripe draws the whole form (fields, labels, errors) and takes its look from `appearance` ([Appearance API](https://docs.stripe.com/elements/appearance-api)). The element mounts into `#payment-element` unless `elementId` is set; `options` go to `elements.create('payment')` over the defaults `layout: 'tabs'`, `fields.billingDetails: 'never'` (billing details come from the cart) and no Apple Pay / Google Pay. `tokenize` re-reads the cart and updates the amount before `elements.submit()`, so a changed cart total needs no extra call.
27
+
28
+ ```js
29
+ const card = {
30
+ paymentElement: true,
31
+ appearance: {
32
+ theme: 'stripe',
33
+ labels: 'floating',
34
+ variables: { colorPrimary: '#111' },
35
+ },
36
+ elementId: 'card-payment-element',
37
+ onChange: (event) => setComplete(event.complete),
38
+ onSuccess: () => submitOrder(),
39
+ onError: (error) => showError(error.message),
40
+ };
41
+
42
+ await swell.payment.createElements({ card });
43
+ // on "Pay": validates, creates the PaymentMethod and the intent, stores them on the cart
44
+ await swell.payment.tokenize({ card });
45
+
46
+ // iDEAL: the same flag; tokenize redirects to the bank and returns through handleRedirect({ ideal })
47
+ await swell.payment.createElements({
48
+ ideal: {
49
+ paymentElement: true,
50
+ appearance,
51
+ elementId: 'ideal-payment-element',
52
+ },
53
+ });
54
+ ```
55
+
56
+ ## Deprecated
57
+
58
+ - `swell.app` (app components rendered by swell-js) is deprecated and will be removed in the next major version. Apps render their components through [`@swell/apps-sdk/components`](https://www.npmjs.com/package/@swell/apps-sdk) instead; hosted checkout mounts payment components at the place `checkout.payment.methods`.
59
+
18
60
  ## Documentation
19
61
 
20
62
  📖 [**View Swell.js Documentation**](https://developers.swell.is/frontend-api/)
package/dist/api.mjs CHANGED
@@ -122,6 +122,10 @@ class AppComponent {
122
122
  }
123
123
  }
124
124
 
125
+ /**
126
+ * @deprecated Payment components are mounted by `@swell/apps-sdk/components`
127
+ * at the host place `checkout.payment.methods`.
128
+ */
125
129
  class AppPaymentComponent extends AppComponent {
126
130
  constructor(app, component, api, options) {
127
131
  super(app, component, api, options);
@@ -171,6 +175,7 @@ class AppPaymentComponent extends AppComponent {
171
175
  }
172
176
  }
173
177
 
178
+ /** @deprecated Use `@swell/apps-sdk/components` instead. */
174
179
  class App {
175
180
  constructor(app, api, options) {
176
181
  this.app = app;
@@ -279,6 +284,13 @@ class App {
279
284
  }
280
285
  }
281
286
 
287
+ let deprecationWarned = false;
288
+
289
+ /**
290
+ * @deprecated App components are rendered by `@swell/apps-sdk/components`
291
+ * (`createComponents().mount()`); this module will be removed in the next
292
+ * major version.
293
+ */
282
294
  class AppController {
283
295
  #apps = new Map();
284
296
 
@@ -287,7 +299,15 @@ class AppController {
287
299
  this.options = options;
288
300
  }
289
301
 
302
+ /** @deprecated Use `@swell/apps-sdk/components` instead. */
290
303
  async load(appId) {
304
+ if (!deprecationWarned) {
305
+ deprecationWarned = true;
306
+ console.warn(
307
+ 'swell.app is deprecated: render app components with @swell/apps-sdk/components',
308
+ );
309
+ }
310
+
291
311
  const loadedApp = this.#apps.get(appId);
292
312
 
293
313
  if (loadedApp) {
@@ -534,7 +554,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
534
554
  const api = {};
535
555
 
536
556
  Object.assign(api, {
537
- version: '5.9.4',
557
+ version: '5.10.0',
538
558
  options,
539
559
  request,
540
560