@artaio/arta-browser 2.22.0 → 2.23.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 CHANGED
@@ -1,9 +1,10 @@
1
1
  # arta-browser
2
2
 
3
- arta-browser is a TypeScript SDK providing easy setup for Arta's Estimates and Tracking widgets.
3
+ arta-browser is a TypeScript SDK providing easy setup for Arta's Estimates and Tracking widgets and the Arta Pay checkout.
4
4
 
5
5
  * Use [Arta Estimates](https://manual.arta.io/guides/solutions/no-code/estimates/estimates-widget) to dynamically generate shipping estimates (non-bookable) on your own website.
6
6
  * Use [Arta Tracking](https://manual.arta.io/guides/solutions/no-code/post-sale/tracking) to easily present clear and up-to-date tracking information on your own website.
7
+ * Use [Arta Pay](#arta-pay-checkout) to let buyers pay a deposit and finance the rest with their Arta credit line, in a modal on your checkout page.
7
8
 
8
9
  ## Installation
9
10
 
@@ -11,12 +12,18 @@ arta-browser is a TypeScript SDK providing easy setup for Arta's Estimates and T
11
12
 
12
13
  Copy and paste the following snippet before the closing `</body>` HTML tag wherever you want the Estimates widget available for your users (typically on your product pages):
13
14
 
14
- ```
15
- <script src="https://cdn.jsdelivr.net/npm/@artaio/arta-browser@latest/dist/bundle.js"></script>
15
+ ```html
16
+ <script
17
+ src="https://cdn.jsdelivr.net/npm/@artaio/arta-browser@2.23.1/dist/bundle.js"
18
+ integrity="sha384-Z3euTa2mVIbuvRrH9S3yGX3I3w3BlmrlMRpJGvrIIy5SCX6XLcfwVoVlKzTsTsCL"
19
+ crossorigin="anonymous"
20
+ ></script>
16
21
  ```
17
22
 
18
23
  And once the above script is loaded the `Arta` object should be available.
19
24
 
25
+ The snippet pins the latest published version and verifies it with [Subresource Integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity); the version and `integrity` hash above are updated automatically on every release.
26
+
20
27
  ### With `npm`
21
28
 
22
29
  In your project run
@@ -134,6 +141,34 @@ tracking.isReady && <Button onClick={() => tracking.open()}>Track</Button>;
134
141
 
135
142
  The Arta Tracking widget has many configuration options to customize the look and feel of the widget. You can view the full list of options in [/lib/trackingConfig.ts](/lib/trackingConfig.ts).
136
143
 
144
+ ### Arta Pay checkout
145
+
146
+ Arta Pay lets a buyer pay a deposit on your order and finance the rest with their Arta credit line, in an Arta-hosted modal on your page. It has a server half and a page half:
147
+
148
+ 1. **Your server** creates a purchase request with your **private** API key (`POST https://api.arta.io/purchase_requests`, with the order amounts, buyer email and line items) and gets back an `id` and a short-lived `client_token`. Pass only `{ purchaseRequestId, clientToken }` to the page — the private key never leaves your server.
149
+ 2. **Your page** initializes with your **public** key and opens the checkout:
150
+
151
+ ```js
152
+ Arta.init('<PUBLIC_KEY>');
153
+
154
+ const checkout = Arta.pay(
155
+ { purchaseRequestId, clientToken },
156
+ {
157
+ onReady: () => (payButton.disabled = false),
158
+ onComplete: ({ purchaseRequestId, purchaseId, status }) => {
159
+ // status: 'confirmed' | 'processing' | 'declined' — confirm server-side
160
+ },
161
+ onClose: ({ reason }) => {}, // 'customer' | 'complete' | 'error'
162
+ onError: ({ code, message, recoverable }) => {},
163
+ },
164
+ { position: 'center' }
165
+ );
166
+
167
+ payButton.addEventListener('click', () => checkout.open());
168
+ ```
169
+
170
+ The widget mounts hidden and validates the purchase request, so `onReady` means "ready to open". `open()` shows the modal, `close()` hides it (reopening resumes) and `destroy()` removes it. `onComplete` fires once when the outcome is known; the callbacks are advisory, so confirm the order server-side with `GET /purchase_requests/:id`. `position` accepts `'center'` (default), `'left'`, `'right'` or `'full_screen'`. The `PayCompletion`, `PayCloseEvent` and `PayError` types are exported from the package.
171
+
137
172
  ## Contributing
138
173
 
139
174
  Please ensure that all the examples available on [github.com/artaio/arta-browser-examples](https://github.com/artaio/arta-browser-examples) are still working before opening a PR.
package/dist/arta.d.ts CHANGED
@@ -2,9 +2,15 @@ import { type EstimateBody, type PartialEstimateConfig } from './estimateConfig'
2
2
  import { type PartialTrackingConfig } from './trackingConfig';
3
3
  import Estimate from './estimate';
4
4
  import Tracking from './tracking';
5
+ import Pay from './pay';
6
+ import InfoModal from './infoModal';
7
+ import { type PartialPayConfig, type PayCallbacks, type PayInput } from './payConfig';
8
+ import { type InfoInput } from './infoConfig';
9
+ import { type MonthlyEstimate, type MonthlyEstimateInput } from './monthlyEstimate';
5
10
  export interface ArtaJsConfig {
6
11
  host: string;
7
12
  httpSchema?: 'http' | 'https';
13
+ payOrigin?: string;
8
14
  }
9
15
  export interface ArtaJsFullConfig extends ArtaJsConfig {
10
16
  apiKey: string;
@@ -14,5 +20,8 @@ export default class Arta {
14
20
  private config;
15
21
  init(apiKey: string, config?: Partial<ArtaJsConfig>): void;
16
22
  estimate(estimateBody: EstimateBody, estimateConfig?: PartialEstimateConfig): Estimate;
23
+ pay(payInput: PayInput, payCallbacks?: PayCallbacks, payConfig?: PartialPayConfig): Pay;
24
+ getArtaPayMonthlyEstimate(input: MonthlyEstimateInput): Promise<MonthlyEstimate>;
25
+ openArtaPayInfoModal(input?: InfoInput): InfoModal;
17
26
  tracking(shipmentId: string, trackingConfig?: PartialTrackingConfig): Tracking;
18
27
  }
package/dist/arta.js CHANGED
@@ -6,15 +6,24 @@ var estimateConfig = require('./estimateConfig.js');
6
6
  var trackingConfig = require('./trackingConfig.js');
7
7
  var estimate = require('./estimate.js');
8
8
  var tracking = require('./tracking.js');
9
+ var pay = require('./pay.js');
10
+ var infoModal = require('./infoModal.js');
11
+ var payConfig = require('./payConfig.js');
12
+ var infoConfig = require('./infoConfig.js');
13
+ var monthlyEstimate = require('./monthlyEstimate.js');
9
14
 
10
15
  const defaultConfig = {
11
16
  host: 'api.arta.io',
12
17
  httpSchema: 'https',
18
+ payOrigin: 'https://collectors.arta.io',
13
19
  };
14
20
  class Arta {
15
21
  el;
16
22
  config;
17
23
  init(apiKey, config) {
24
+ if (!apiKey || !apiKey.trim()) {
25
+ throw new Error('Please provide your Arta public API key to Arta.init');
26
+ }
18
27
  this.config = Object.assign({ ...defaultConfig, apiKey }, config);
19
28
  if (document.querySelectorAll('#arta-widget').length) {
20
29
  return;
@@ -32,6 +41,38 @@ class Arta {
32
41
  throw new Error('Please initialize the SDK with Arta.init before creating estimates');
33
42
  }
34
43
  }
44
+ // Creates an Arta Pay checkout for a purchase request the seller's server
45
+ // created with its private key. The widget iframe mounts immediately
46
+ // (hidden) and validates the purchase request; `onReady` is the signal to
47
+ // enable the "Pay with Arta" button, and `open()` shows the modal.
48
+ pay(payInput, payCallbacks = {}, payConfig$1 = {}) {
49
+ if (this.config) {
50
+ return new pay.default(payInput, payCallbacks, payConfig.getFullPayConfig(this.config, payConfig$1));
51
+ }
52
+ else {
53
+ throw new Error('Please initialize the SDK with Arta.init before creating Arta Pay checkouts');
54
+ }
55
+ }
56
+ // A "from $X/mo" Arta Pay estimate for a price, for placements and CTAs (e.g.
57
+ // "From $1,246/mo with Arta Pay"). The checkout shows the buyer's exact,
58
+ // quoted schedule. Resolves from local math today; it returns a promise so
59
+ // that computing it server-side later does not change this signature.
60
+ getArtaPayMonthlyEstimate(input) {
61
+ return monthlyEstimate.monthlyEstimate(input);
62
+ }
63
+ // Opens the login-free Arta Pay info modal: a marketing modal explaining
64
+ // Arta Pay, optionally showing a financing estimate when `totalPrice` is
65
+ // given. It only needs the public key from `Arta.init` — no purchase request.
66
+ openArtaPayInfoModal(input = {}) {
67
+ if (this.config) {
68
+ const modal = new infoModal.default(input, infoConfig.getFullInfoConfig(this.config));
69
+ modal.open();
70
+ return modal;
71
+ }
72
+ else {
73
+ throw new Error('Please initialize the SDK with Arta.init before opening the Arta Pay info modal');
74
+ }
75
+ }
35
76
  tracking(shipmentId, trackingConfig$1 = {}) {
36
77
  if (this.config && this.el) {
37
78
  const fullTrackingConfig = trackingConfig.getFullTrackingConfig(this.config, trackingConfig$1);