@tagadapay/headless-sdk 1.3.1 → 1.4.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 +91 -7
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/modules/checkout.d.ts +71 -8
- package/dist/core/modules/checkout.d.ts.map +1 -1
- package/dist/core/modules/checkout.js +129 -35
- package/dist/core/modules/checkout.js.map +1 -1
- package/dist/core/modules/payment.d.ts +62 -1
- package/dist/core/modules/payment.d.ts.map +1 -1
- package/dist/core/modules/payment.js +225 -0
- package/dist/core/modules/payment.js.map +1 -1
- package/dist/core/types.d.ts +80 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/react/hooks/useCheckout.d.ts.map +1 -1
- package/dist/react/hooks/useCheckout.js +2 -12
- package/dist/react/hooks/useCheckout.js.map +1 -1
- package/dist/react/hooks/usePayment.d.ts +39 -10
- package/dist/react/hooks/usePayment.d.ts.map +1 -1
- package/dist/react/hooks/usePayment.js +116 -8
- package/dist/react/hooks/usePayment.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/tagada-headless-react.min.js +2 -2
- package/dist/tagada-headless-react.min.js.map +3 -3
- package/dist/tagada-headless.js +321 -34
- package/dist/tagada-headless.min.js +2 -2
- package/dist/tagada-headless.min.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,19 +21,40 @@ const tagada = createHeadlessClient({
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
// Load checkout session
|
|
24
|
-
const session = await tagada.checkout.loadSession(checkoutToken);
|
|
24
|
+
const session = await tagada.checkout.loadSession(checkoutToken, sessionToken);
|
|
25
25
|
|
|
26
|
-
//
|
|
26
|
+
// Set customer info (stored in memory, sent with address)
|
|
27
|
+
await tagada.checkout.updateCustomer(session.id, {
|
|
28
|
+
email: 'john@example.com',
|
|
29
|
+
firstName: 'John',
|
|
30
|
+
lastName: 'Doe',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Set address — customer fields are included automatically
|
|
34
|
+
await tagada.checkout.updateAddress(session.id, {
|
|
35
|
+
shippingAddress: { line1: '10 Rue de la Paix', city: 'Paris', postalCode: '75002', country: 'FR' },
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Tokenize card + pay with automatic 3DS / redirect handling
|
|
27
39
|
const { tagadaToken } = await tagada.payment.tokenizeCard({
|
|
28
40
|
cardNumber: '4242424242424242',
|
|
29
41
|
expiryDate: '12/28',
|
|
30
42
|
cvc: '123',
|
|
31
43
|
});
|
|
32
44
|
|
|
33
|
-
const result = await tagada.payment.
|
|
45
|
+
const result = await tagada.payment.processPayment({
|
|
34
46
|
checkoutSessionId: session.id,
|
|
35
47
|
tagadaToken,
|
|
36
48
|
});
|
|
49
|
+
|
|
50
|
+
if (result.status === 'succeeded') {
|
|
51
|
+
console.log('Payment succeeded!', result.order);
|
|
52
|
+
} else if (result.status === 'requires_redirect') {
|
|
53
|
+
// SDK handles this automatically in React; in vanilla JS, redirect manually:
|
|
54
|
+
window.location.href = result.redirectUrl;
|
|
55
|
+
} else if (result.status === 'failed') {
|
|
56
|
+
console.error(result.error);
|
|
57
|
+
}
|
|
37
58
|
```
|
|
38
59
|
|
|
39
60
|
## Quick Start (React)
|
|
@@ -50,19 +71,74 @@ function App() {
|
|
|
50
71
|
}
|
|
51
72
|
|
|
52
73
|
function CheckoutPage() {
|
|
53
|
-
const { session,
|
|
54
|
-
const {
|
|
74
|
+
const { session, updateCustomer, updateAddress } = useCheckout(checkoutToken, sessionToken);
|
|
75
|
+
const { processPayment, isProcessing, tokenizeCard } = usePayment({
|
|
76
|
+
onPaymentSuccess: (result) => router.push('/thank-you'),
|
|
77
|
+
onPaymentFailed: (result) => alert(result.error),
|
|
78
|
+
});
|
|
55
79
|
|
|
56
80
|
const handlePay = async () => {
|
|
81
|
+
// Customer + address (single atomic API call under the hood)
|
|
82
|
+
await updateCustomer({ email, firstName, lastName });
|
|
83
|
+
await updateAddress({ shippingAddress: { line1, city, postalCode, country } });
|
|
84
|
+
|
|
85
|
+
// Tokenize + pay — 3DS redirects and polling are handled automatically
|
|
57
86
|
const { tagadaToken } = await tokenizeCard({ cardNumber, expiryDate, cvc });
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
await processPayment({ checkoutSessionId: session.id, tagadaToken });
|
|
88
|
+
// onPaymentSuccess / onPaymentFailed callbacks fire automatically
|
|
60
89
|
};
|
|
61
90
|
|
|
62
91
|
return <button onClick={handlePay} disabled={isProcessing}>Pay Now</button>;
|
|
63
92
|
}
|
|
64
93
|
```
|
|
65
94
|
|
|
95
|
+
## Payment Flow
|
|
96
|
+
|
|
97
|
+
`processPayment()` handles the full payment lifecycle automatically:
|
|
98
|
+
|
|
99
|
+
1. **Tokenize** → creates a payment instrument from the card
|
|
100
|
+
2. **Pay** → submits payment to the processor
|
|
101
|
+
3. **3DS / Redirect** → if the bank requires authentication, the SDK redirects the user and resumes automatically on return
|
|
102
|
+
4. **Poll** → waits for async processing to complete
|
|
103
|
+
5. **Result** → returns a typed `ProcessPaymentResult`
|
|
104
|
+
|
|
105
|
+
The return type is a discriminated union:
|
|
106
|
+
|
|
107
|
+
| Status | Meaning |
|
|
108
|
+
|--------|---------|
|
|
109
|
+
| `succeeded` | Payment confirmed. Show success screen. |
|
|
110
|
+
| `requires_redirect` | User must visit a URL (3DS, bank auth). Auto-handled in React. |
|
|
111
|
+
| `failed` | Payment declined or errored. `result.error` has details. |
|
|
112
|
+
| `pending` | Still processing (rare — polling timed out). |
|
|
113
|
+
|
|
114
|
+
## Address Handling
|
|
115
|
+
|
|
116
|
+
The SDK handles both **shipped** and **digital** products:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// Shipped product — billing defaults to shipping
|
|
120
|
+
await tagada.checkout.updateAddress(sessionId, {
|
|
121
|
+
shippingAddress: { line1: '...', city: '...', country: 'FR' },
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Digital product — billing only, no shipping needed
|
|
125
|
+
await tagada.checkout.updateAddress(sessionId, {
|
|
126
|
+
billingAddress: { country: 'FR' },
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Separate billing and shipping
|
|
130
|
+
await tagada.checkout.updateAddress(sessionId, {
|
|
131
|
+
shippingAddress: { line1: '...', city: '...', country: 'FR' },
|
|
132
|
+
billingAddress: { line1: '...', city: '...', country: 'DE' },
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Or use the combined method
|
|
136
|
+
await tagada.checkout.updateCustomerAndAddress(sessionId, {
|
|
137
|
+
customer: { email: 'john@example.com', firstName: 'John', lastName: 'Doe' },
|
|
138
|
+
shippingAddress: { line1: '...', city: '...', country: 'FR' },
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
66
142
|
## Modules
|
|
67
143
|
|
|
68
144
|
| Module | What it does |
|
|
@@ -82,6 +158,13 @@ function CheckoutPage() {
|
|
|
82
158
|
</script>
|
|
83
159
|
```
|
|
84
160
|
|
|
161
|
+
## Example
|
|
162
|
+
|
|
163
|
+
A complete React checkout app is available as a live demo and open-source reference:
|
|
164
|
+
|
|
165
|
+
- **Live demo**: [headless-react-eta.vercel.app](https://headless-react-eta.vercel.app)
|
|
166
|
+
- **Source code**: [github.com/TagadaPay/examples/tree/main/headless-react](https://github.com/TagadaPay/examples/tree/main/headless-react)
|
|
167
|
+
|
|
85
168
|
## Architecture
|
|
86
169
|
|
|
87
170
|
- **Zero dependencies** in core — native `fetch`, no axios
|
|
@@ -89,6 +172,7 @@ function CheckoutPage() {
|
|
|
89
172
|
- **Framework-agnostic core** + thin React hooks layer
|
|
90
173
|
- **TypeScript first** — full type coverage, JSDoc on every method
|
|
91
174
|
- **Optional `@tagadapay/core-js`** peer — only needed for client-side card tokenization
|
|
175
|
+
- **Automatic 3DS** — handles redirects, iframe challenges, and polling out of the box
|
|
92
176
|
|
|
93
177
|
## Package Exports
|
|
94
178
|
|
package/dist/core/index.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export { HttpClient } from './http.js';
|
|
|
8
8
|
export { TagadaError, TagadaAuthError, TagadaValidationError, TagadaNotFoundError, TagadaRateLimitError, TagadaPaymentError, TagadaNetworkError, } from './errors.js';
|
|
9
9
|
export { GoogleAutocompleteCore, loadGoogleMapsScript, ISODataCore, AVAILABLE_LANGUAGES, CurrencyUtils, formatMoney, ensureGeoDataLoaded, getCountries, getStatesForCountry, isLanguageLoaded, } from './helpers/index.js';
|
|
10
10
|
export type { GooglePrediction, GooglePlaceDetails, ExtractedAddress, FormattedAddress, SupportedLanguage, ISOCountry, ISORegion, Country, State, Currency, } from './helpers/index.js';
|
|
11
|
-
export type { Environment, HeadlessConfig, HttpRequestOptions, LineItem, CheckoutSession, CheckoutLineItem, CheckoutTotals, CheckoutCustomer, Address, ShippingRate, PaymentMethodConfig, PaymentSetupConfig, ExpressMethod, ExpressMethods, StoreConfig, PayResult, PayOptions, PayDirectOptions, CreateInstrumentOptions, PaymentInstrument, ThreedsSession, PaymentStatus, Offer, OfferLineItem, OfferPreview, OfferPreviewItem, OfferPayResult, Customer, Order, OrderItem, Subscription, CatalogProduct, CatalogVariant, CatalogPrice, CurrencyOption, } from './types.js';
|
|
11
|
+
export type { Environment, HeadlessConfig, HttpRequestOptions, LineItem, CheckoutSession, CheckoutLineItem, CheckoutTotals, CheckoutCustomer, Address, ShippingRate, PaymentMethodConfig, PaymentSetupConfig, ExpressMethod, ExpressMethods, StoreConfig, PayResult, PayOptions, PayDirectOptions, ProcessPaymentOptions, ProcessPaymentResult, CreateInstrumentOptions, PaymentInstrument, ThreedsSession, PaymentStatus, Offer, OfferLineItem, OfferPreview, OfferPreviewItem, OfferPayResult, Customer, Order, OrderItem, Subscription, CatalogProduct, CatalogVariant, CatalogPrice, CurrencyOption, } from './types.js';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,OAAO,EACP,KAAK,EACL,QAAQ,GACT,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,WAAW,EACX,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,KAAK,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,KAAK,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,GACf,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EACL,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,OAAO,EACP,KAAK,EACL,QAAQ,GACT,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,OAAO,EACP,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,WAAW,EACX,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,KAAK,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,KAAK,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,GACf,MAAM,YAAY,CAAC"}
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
import type { HttpClient } from '../http.js';
|
|
2
2
|
import type { CheckoutSession, LineItem, ShippingRate, Address, CheckoutCustomer } from '../types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Manages checkout sessions
|
|
4
|
+
* Manages checkout sessions — load, update cart, apply promo codes, handle shipping.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Works for both **shipped** and **digital** products:
|
|
7
|
+
*
|
|
8
|
+
* **Shipped products** (physical goods):
|
|
9
|
+
* ```
|
|
10
|
+
* updateCustomer(id, { email, firstName, lastName })
|
|
11
|
+
* updateAddress(id, { shippingAddress: { line1, city, ... } })
|
|
12
|
+
* getShippingRates(id)
|
|
13
|
+
* selectShippingRate(id, rateId)
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* **Digital products** (no shipping needed):
|
|
17
|
+
* ```
|
|
18
|
+
* updateCustomer(id, { email, firstName, lastName })
|
|
19
|
+
* updateAddress(id, { billingAddress: { line1, city, country } })
|
|
20
|
+
* // Skip shipping rates — go straight to payment
|
|
21
|
+
* ```
|
|
8
22
|
*/
|
|
9
23
|
export declare class CheckoutModule {
|
|
10
24
|
private readonly http;
|
|
11
25
|
private readonly storeId;
|
|
12
26
|
private readonly onTokenChange?;
|
|
13
27
|
private sessionToken;
|
|
28
|
+
private customerEmail;
|
|
29
|
+
private customerFirstName;
|
|
30
|
+
private customerLastName;
|
|
31
|
+
private customerPhone;
|
|
14
32
|
constructor(http: HttpClient, storeId: string, onTokenChange?: ((token: string) => void) | undefined);
|
|
15
33
|
/**
|
|
16
34
|
* Load an existing checkout session by its checkout token.
|
|
@@ -44,26 +62,71 @@ export declare class CheckoutModule {
|
|
|
44
62
|
/** Replace the cart items for an existing session. */
|
|
45
63
|
updateCart(sessionId: string, items: LineItem[]): Promise<CheckoutSession>;
|
|
46
64
|
/**
|
|
47
|
-
* Update customer
|
|
48
|
-
*
|
|
65
|
+
* Update customer identity (email, name, phone).
|
|
66
|
+
*
|
|
67
|
+
* Call this before `updateAddress()` — the SDK remembers the values and
|
|
68
|
+
* includes them automatically when addresses are submitted.
|
|
69
|
+
*
|
|
70
|
+
* If you prefer a single call, use `updateCustomerAndAddress()` instead.
|
|
49
71
|
*/
|
|
50
72
|
updateCustomer(sessionId: string, customer: Partial<CheckoutCustomer>): Promise<void>;
|
|
51
73
|
/**
|
|
52
74
|
* Update shipping and/or billing address on the session.
|
|
53
75
|
*
|
|
54
|
-
*
|
|
76
|
+
* Automatically includes customer name/phone stored from `updateCustomer()`.
|
|
77
|
+
* Uses the same atomic API call as the production checkout, so email,
|
|
78
|
+
* customer name, and addresses are all persisted together.
|
|
79
|
+
*
|
|
80
|
+
* **Shipped products**: pass `shippingAddress`. If `billingAddress` is omitted,
|
|
81
|
+
* the shipping address is automatically used as billing.
|
|
82
|
+
*
|
|
83
|
+
* **Digital products**: pass only `billingAddress` (no shipping needed).
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Shipped product — billing = shipping automatically
|
|
87
|
+
* await checkout.updateAddress(sessionId, {
|
|
88
|
+
* shippingAddress: { line1: '10 Rue de la Paix', city: 'Paris', postalCode: '75002', country: 'FR' },
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Digital product — billing only
|
|
93
|
+
* await checkout.updateAddress(sessionId, {
|
|
94
|
+
* billingAddress: { country: 'FR' },
|
|
95
|
+
* });
|
|
55
96
|
*/
|
|
56
97
|
updateAddress(sessionId: string, addresses: {
|
|
57
98
|
shippingAddress?: Address;
|
|
58
99
|
billingAddress?: Address;
|
|
59
100
|
}): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Set customer info + addresses in one call (mirrors production checkout).
|
|
103
|
+
*
|
|
104
|
+
* Equivalent to calling `updateCustomer()` then `updateAddress()`, but
|
|
105
|
+
* in a single network request.
|
|
106
|
+
*/
|
|
107
|
+
updateCustomerAndAddress(sessionId: string, data: {
|
|
108
|
+
customer: Partial<CheckoutCustomer>;
|
|
109
|
+
shippingAddress?: Address;
|
|
110
|
+
billingAddress?: Address;
|
|
111
|
+
}): Promise<void>;
|
|
112
|
+
/** Map an SDK Address to the API shape, injecting stored customer fields. */
|
|
113
|
+
private mapAddress;
|
|
60
114
|
/** Apply a promotion code to the session. */
|
|
61
115
|
applyPromoCode(sessionId: string, code: string): Promise<void>;
|
|
62
116
|
/** Remove a promotion from the session by promotion ID. */
|
|
63
117
|
removePromoCode(sessionId: string, promotionId?: string): Promise<void>;
|
|
64
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Fetch available shipping rates for the session's address.
|
|
120
|
+
* Only relevant for **shipped products** — digital products can skip this step.
|
|
121
|
+
*
|
|
122
|
+
* Requires a shipping address to be set first via `updateAddress()`.
|
|
123
|
+
* Returns an empty array if no rates are configured or address is missing.
|
|
124
|
+
*/
|
|
65
125
|
getShippingRates(sessionId: string): Promise<ShippingRate[]>;
|
|
66
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Select a shipping rate for the session.
|
|
128
|
+
* Only relevant for **shipped products** — digital products can skip this step.
|
|
129
|
+
*/
|
|
67
130
|
selectShippingRate(sessionId: string, rateId: string): Promise<void>;
|
|
68
131
|
/**
|
|
69
132
|
* Normalize the raw v2 API response into a cleaner CheckoutSession shape.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../../src/core/modules/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAErB
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../../src/core/modules/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,cAAc;IAQvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC;IATjC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,iBAAiB,CAAqB;IAC9C,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,aAAa,CAAqB;gBAGvB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,aAAA;IAG1D;;;;;;;;OAQG;IACG,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAiBzF;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE;QACxB,KAAK,EAAE,QAAQ,EAAE,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,iBAAiB,CAAC,EAAE,MAAM,CA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CAAC;IAQlE;;;OAGG;IACG,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1E;;;OAGG;IACH,OAAO,CAAC,gBAAgB;CAwDzB"}
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Manages checkout sessions
|
|
2
|
+
* Manages checkout sessions — load, update cart, apply promo codes, handle shipping.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Works for both **shipped** and **digital** products:
|
|
5
|
+
*
|
|
6
|
+
* **Shipped products** (physical goods):
|
|
7
|
+
* ```
|
|
8
|
+
* updateCustomer(id, { email, firstName, lastName })
|
|
9
|
+
* updateAddress(id, { shippingAddress: { line1, city, ... } })
|
|
10
|
+
* getShippingRates(id)
|
|
11
|
+
* selectShippingRate(id, rateId)
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* **Digital products** (no shipping needed):
|
|
15
|
+
* ```
|
|
16
|
+
* updateCustomer(id, { email, firstName, lastName })
|
|
17
|
+
* updateAddress(id, { billingAddress: { line1, city, country } })
|
|
18
|
+
* // Skip shipping rates — go straight to payment
|
|
19
|
+
* ```
|
|
6
20
|
*/
|
|
7
21
|
export class CheckoutModule {
|
|
8
22
|
constructor(http, storeId, onTokenChange) {
|
|
@@ -76,51 +90,109 @@ export class CheckoutModule {
|
|
|
76
90
|
return this.http.post(`/api/v1/checkout-sessions/${sessionId}/line-items`, { items }, { token: this.sessionToken });
|
|
77
91
|
}
|
|
78
92
|
/**
|
|
79
|
-
* Update customer
|
|
80
|
-
*
|
|
93
|
+
* Update customer identity (email, name, phone).
|
|
94
|
+
*
|
|
95
|
+
* Call this before `updateAddress()` — the SDK remembers the values and
|
|
96
|
+
* includes them automatically when addresses are submitted.
|
|
97
|
+
*
|
|
98
|
+
* If you prefer a single call, use `updateCustomerAndAddress()` instead.
|
|
81
99
|
*/
|
|
82
100
|
async updateCustomer(sessionId, customer) {
|
|
101
|
+
if (customer.email)
|
|
102
|
+
this.customerEmail = customer.email;
|
|
103
|
+
if (customer.firstName)
|
|
104
|
+
this.customerFirstName = customer.firstName;
|
|
105
|
+
if (customer.lastName)
|
|
106
|
+
this.customerLastName = customer.lastName;
|
|
107
|
+
if (customer.phone)
|
|
108
|
+
this.customerPhone = customer.phone;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Update shipping and/or billing address on the session.
|
|
112
|
+
*
|
|
113
|
+
* Automatically includes customer name/phone stored from `updateCustomer()`.
|
|
114
|
+
* Uses the same atomic API call as the production checkout, so email,
|
|
115
|
+
* customer name, and addresses are all persisted together.
|
|
116
|
+
*
|
|
117
|
+
* **Shipped products**: pass `shippingAddress`. If `billingAddress` is omitted,
|
|
118
|
+
* the shipping address is automatically used as billing.
|
|
119
|
+
*
|
|
120
|
+
* **Digital products**: pass only `billingAddress` (no shipping needed).
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* // Shipped product — billing = shipping automatically
|
|
124
|
+
* await checkout.updateAddress(sessionId, {
|
|
125
|
+
* shippingAddress: { line1: '10 Rue de la Paix', city: 'Paris', postalCode: '75002', country: 'FR' },
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* // Digital product — billing only
|
|
130
|
+
* await checkout.updateAddress(sessionId, {
|
|
131
|
+
* billingAddress: { country: 'FR' },
|
|
132
|
+
* });
|
|
133
|
+
*/
|
|
134
|
+
async updateAddress(sessionId, addresses) {
|
|
135
|
+
const shipping = this.mapAddress(addresses.shippingAddress);
|
|
136
|
+
const billing = this.mapAddress(addresses.billingAddress);
|
|
137
|
+
const effectiveShipping = shipping ?? billing ?? {};
|
|
138
|
+
const effectiveBilling = billing ?? shipping;
|
|
139
|
+
const differentBilling = !!(addresses.billingAddress && addresses.shippingAddress);
|
|
83
140
|
await this.http.post(`/api/v1/checkout-sessions/${sessionId}/customer-and-session-info`, {
|
|
84
141
|
checkoutSessionId: sessionId,
|
|
85
|
-
partial: true,
|
|
86
142
|
customerData: {
|
|
87
|
-
email:
|
|
88
|
-
},
|
|
89
|
-
shippingAddress: {
|
|
90
|
-
firstName: customer.firstName,
|
|
91
|
-
lastName: customer.lastName,
|
|
92
|
-
phone: customer.phone,
|
|
143
|
+
email: this.customerEmail,
|
|
93
144
|
},
|
|
94
|
-
|
|
95
|
-
|
|
145
|
+
shippingAddress: effectiveShipping,
|
|
146
|
+
billingAddress: effectiveBilling ?? {},
|
|
147
|
+
differentBillingAddress: differentBilling,
|
|
96
148
|
}, { token: this.sessionToken });
|
|
97
149
|
}
|
|
98
150
|
/**
|
|
99
|
-
*
|
|
151
|
+
* Set customer info + addresses in one call (mirrors production checkout).
|
|
100
152
|
*
|
|
101
|
-
*
|
|
153
|
+
* Equivalent to calling `updateCustomer()` then `updateAddress()`, but
|
|
154
|
+
* in a single network request.
|
|
102
155
|
*/
|
|
103
|
-
async
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
156
|
+
async updateCustomerAndAddress(sessionId, data) {
|
|
157
|
+
if (data.customer.email)
|
|
158
|
+
this.customerEmail = data.customer.email;
|
|
159
|
+
if (data.customer.firstName)
|
|
160
|
+
this.customerFirstName = data.customer.firstName;
|
|
161
|
+
if (data.customer.lastName)
|
|
162
|
+
this.customerLastName = data.customer.lastName;
|
|
163
|
+
if (data.customer.phone)
|
|
164
|
+
this.customerPhone = data.customer.phone;
|
|
165
|
+
const shipping = this.mapAddress(data.shippingAddress);
|
|
166
|
+
const billing = this.mapAddress(data.billingAddress);
|
|
167
|
+
const effectiveShipping = shipping ?? billing ?? {};
|
|
168
|
+
const effectiveBilling = billing ?? shipping;
|
|
169
|
+
const differentBilling = !!(data.billingAddress && data.shippingAddress);
|
|
170
|
+
await this.http.post(`/api/v1/checkout-sessions/${sessionId}/customer-and-session-info`, {
|
|
117
171
|
checkoutSessionId: sessionId,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
billingAddress: mapAddress(addresses.billingAddress),
|
|
172
|
+
customerData: {
|
|
173
|
+
email: this.customerEmail,
|
|
121
174
|
},
|
|
175
|
+
shippingAddress: effectiveShipping,
|
|
176
|
+
billingAddress: effectiveBilling ?? {},
|
|
177
|
+
differentBillingAddress: differentBilling,
|
|
122
178
|
}, { token: this.sessionToken });
|
|
123
179
|
}
|
|
180
|
+
/** Map an SDK Address to the API shape, injecting stored customer fields. */
|
|
181
|
+
mapAddress(a) {
|
|
182
|
+
if (!a)
|
|
183
|
+
return undefined;
|
|
184
|
+
return stripEmpty({
|
|
185
|
+
firstName: a.firstName ?? this.customerFirstName,
|
|
186
|
+
lastName: a.lastName ?? this.customerLastName,
|
|
187
|
+
phone: a.phone ?? this.customerPhone,
|
|
188
|
+
address1: a.line1,
|
|
189
|
+
address2: a.line2,
|
|
190
|
+
city: a.city,
|
|
191
|
+
state: a.state,
|
|
192
|
+
postal: a.postalCode,
|
|
193
|
+
country: a.country,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
124
196
|
/** Apply a promotion code to the session. */
|
|
125
197
|
async applyPromoCode(sessionId, code) {
|
|
126
198
|
await this.http.post(`/api/v1/checkout-sessions/${sessionId}/promotions/apply`, { checkoutSessionId: sessionId, code }, { token: this.sessionToken });
|
|
@@ -130,12 +202,21 @@ export class CheckoutModule {
|
|
|
130
202
|
const promoId = promotionId ?? 'default';
|
|
131
203
|
await this.http.delete(`/api/v1/checkout-sessions/${sessionId}/promotions/${promoId}`, { token: this.sessionToken });
|
|
132
204
|
}
|
|
133
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* Fetch available shipping rates for the session's address.
|
|
207
|
+
* Only relevant for **shipped products** — digital products can skip this step.
|
|
208
|
+
*
|
|
209
|
+
* Requires a shipping address to be set first via `updateAddress()`.
|
|
210
|
+
* Returns an empty array if no rates are configured or address is missing.
|
|
211
|
+
*/
|
|
134
212
|
async getShippingRates(sessionId) {
|
|
135
213
|
const res = await this.http.get(`/api/v1/checkout-sessions/${sessionId}/shipping-rates`, { token: this.sessionToken });
|
|
136
214
|
return res.rates ?? [];
|
|
137
215
|
}
|
|
138
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* Select a shipping rate for the session.
|
|
218
|
+
* Only relevant for **shipped products** — digital products can skip this step.
|
|
219
|
+
*/
|
|
139
220
|
async selectShippingRate(sessionId, rateId) {
|
|
140
221
|
await this.http.post(`/api/v1/checkout-sessions/${sessionId}/shipping-rate`, { checkoutSessionId: sessionId, shippingRateId: rateId }, { token: this.sessionToken });
|
|
141
222
|
}
|
|
@@ -197,4 +278,17 @@ export class CheckoutModule {
|
|
|
197
278
|
};
|
|
198
279
|
}
|
|
199
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Remove keys with empty-string / null / undefined values from an object.
|
|
283
|
+
* Prevents sending `""` to APIs that reject empty values (e.g. Stripe `country`).
|
|
284
|
+
*/
|
|
285
|
+
function stripEmpty(obj) {
|
|
286
|
+
const result = {};
|
|
287
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
288
|
+
if (v !== undefined && v !== null && v !== '') {
|
|
289
|
+
result[k] = v;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return (Object.keys(result).length > 0 ? result : undefined);
|
|
293
|
+
}
|
|
200
294
|
//# sourceMappingURL=checkout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../../src/core/modules/checkout.ts"],"names":[],"mappings":"AASA
|
|
1
|
+
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../../src/core/modules/checkout.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,cAAc;IAOzB,YACmB,IAAgB,EAChB,OAAe,EACf,aA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CAAC,CAAC;oBACE,EAAE,EAAE,QAAQ,CAAC,EAAY;oBACzB,KAAK,EAAE,QAAQ,CAAC,KAA2B;oBAC3C,SAAS,EAAE,QAAQ,CAAC,SAA+B;oBACnD,QAAQ,EAAE,QAAQ,CAAC,QAA8B;iBAClD;gBACH,CAAC,CAAC,SAAS;YACb,eAAe,EAAE,EAAE,CAAC,eAAqD;YACzE,cAAc,EAAE,EAAE,CAAC,cAAmD;YACtE,QAAQ,EAAE,EAAE,CAAC,QAAmC;SACjD,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,UAAU,CAAoC,GAAM;IAC3D,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YAC9C,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAM,CAAC;AACpE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HttpClient } from '../http.js';
|
|
2
|
-
import type { Environment, PaymentSetupConfig, ExpressMethods, StoreConfig, PayResult, PayOptions, PayDirectOptions, CreateInstrumentOptions, PaymentInstrument, ThreedsSession, PaymentStatus } from '../types.js';
|
|
2
|
+
import type { Environment, PaymentSetupConfig, ExpressMethods, StoreConfig, PayResult, PayOptions, PayDirectOptions, CreateInstrumentOptions, PaymentInstrument, ThreedsSession, PaymentStatus, ProcessPaymentOptions, ProcessPaymentResult } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Full payment lifecycle -- discover APMs, tokenize, create instruments,
|
|
5
5
|
* process payments, handle 3DS, and poll for status.
|
|
@@ -106,6 +106,44 @@ export declare class PaymentModule {
|
|
|
106
106
|
processorId: string;
|
|
107
107
|
paymentFlowId?: string;
|
|
108
108
|
}): Promise<PayResult>;
|
|
109
|
+
/**
|
|
110
|
+
* Process a payment end-to-end: pay, handle 3DS / redirects, poll until done.
|
|
111
|
+
*
|
|
112
|
+
* This is the **recommended** way to process payments. It wraps `pay()`, detects
|
|
113
|
+
* `requireAction`, runs 3DS challenges (if `@tagadapay/core-js` is installed),
|
|
114
|
+
* and polls until a terminal status.
|
|
115
|
+
*
|
|
116
|
+
* Returns a discriminated union so you can pattern-match on `result.status`:
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const result = await payment.processPayment({
|
|
121
|
+
* checkoutSessionId: session.id,
|
|
122
|
+
* tagadaToken,
|
|
123
|
+
* });
|
|
124
|
+
*
|
|
125
|
+
* switch (result.status) {
|
|
126
|
+
* case 'succeeded':
|
|
127
|
+
* console.log('Paid!', result.payment.id);
|
|
128
|
+
* break;
|
|
129
|
+
* case 'requires_redirect':
|
|
130
|
+
* // In browser: window.location.href = result.redirectUrl
|
|
131
|
+
* // The React hook handles this automatically.
|
|
132
|
+
* break;
|
|
133
|
+
* case 'failed':
|
|
134
|
+
* console.error(result.error);
|
|
135
|
+
* break;
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
processPayment(opts: ProcessPaymentOptions): Promise<ProcessPaymentResult>;
|
|
140
|
+
/**
|
|
141
|
+
* Resume a payment after the user returns from a redirect (3DS, processor auth, APM).
|
|
142
|
+
*
|
|
143
|
+
* Called automatically by `usePayment()` in React when it detects return-URL params.
|
|
144
|
+
* You can also call it manually in non-React apps.
|
|
145
|
+
*/
|
|
146
|
+
resumeAfterRedirect(paymentId: string): Promise<ProcessPaymentResult>;
|
|
109
147
|
/** Get current status of a payment. */
|
|
110
148
|
getPaymentStatus(paymentId: string): Promise<PaymentStatus>;
|
|
111
149
|
/**
|
|
@@ -118,6 +156,29 @@ export declare class PaymentModule {
|
|
|
118
156
|
}): Promise<PaymentStatus>;
|
|
119
157
|
/** Finalize a payment after a 3DS challenge completes. */
|
|
120
158
|
completeAfter3ds(paymentId: string): Promise<PaymentStatus>;
|
|
159
|
+
/** Tell the server this action has been seen / is being processed. */
|
|
160
|
+
markActionProcessed(paymentId: string): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Route a payment action to the appropriate handler.
|
|
163
|
+
* Returns `requires_redirect` for browser-level redirects,
|
|
164
|
+
* or attempts 3DS inline and polls to completion.
|
|
165
|
+
*/
|
|
166
|
+
private handlePaymentAction;
|
|
167
|
+
/**
|
|
168
|
+
* Extract redirect info from actionData.
|
|
169
|
+
* Works for processor_auth (GET or POST), redirect, and any unknown type with a URL.
|
|
170
|
+
*/
|
|
171
|
+
private extractRedirect;
|
|
172
|
+
/**
|
|
173
|
+
* Run a 3DS challenge using @tagadapay/core-js.
|
|
174
|
+
* If core-js is not installed, falls back to redirect.
|
|
175
|
+
*/
|
|
176
|
+
private handleThreedsAuth;
|
|
177
|
+
/**
|
|
178
|
+
* Poll until the payment reaches a terminal status, then return a ProcessPaymentResult.
|
|
179
|
+
* Also handles new requireAction that may appear during polling.
|
|
180
|
+
*/
|
|
181
|
+
private pollUntilDone;
|
|
121
182
|
private loadCoreJs;
|
|
122
183
|
}
|
|
123
184
|
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/core/modules/payment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAElB,cAAc,EACd,WAAW,EACX,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EAC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