@sesamy/sesamy-js 1.43.0 → 1.45.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
@@ -1057,191 +1057,232 @@ Creates a checkout session with Sesamy. This function initializes a checkout pro
1057
1057
  ### Parameters
1058
1058
 
1059
1059
  - params (CreateCheckoutParams): The parameters for creating the checkout session.
1060
- - items (Array of objects): An array of items to be included in the checkout.
1061
- - sku (string): The SKU of the product to be purchased.
1062
- - purchaseOptionsId (string, optional): The ID of the purchase options for the product.
1060
+ - **items** (Array of objects, **required**): An array of items to be included in the checkout.
1061
+ - sku (string, optional): The SKU of the product to be purchased.
1062
+ - url (string, optional): The URL of the item.
1063
+ - purchaseOptionId (string, optional): The ID of the purchase option for the product.
1064
+ - price (number, optional): The price of the item.
1065
+ - currency (string, optional): The currency code (e.g., 'USD').
1066
+ - geoRestrictions (object, optional): Geographic restrictions for the item.
1067
+ - type ('ALLOW' | 'BLOCK'): Type of restriction.
1068
+ - countries (Array of strings): List of country codes.
1069
+ - **redirectUrl** (string, **required**): The URL to redirect to after the checkout process is completed.
1063
1070
  - language (string, optional): The language for the checkout session. If not set, it will be automatically fetched from the HTML element's `lang` attribute.
1064
- - redirectUrl (string): The URL to redirect to after the checkout process is completed.
1065
1071
  - givenName (string, optional): The given name of the customer.
1066
1072
  - familyName (string, optional): The family name of the customer.
1067
1073
  - email (string, optional): The email address of the customer.
1068
1074
  - phoneNumber (string, optional): The phone number of the customer.
1069
- - birthDate (string, optional): The birth date of the customer.
1070
- - country (string, optional): The country of the customer.
1071
- - address (Address, optional): The address for the checkout session.
1075
+ - birthDate (string, optional): The birth date of the customer in ISO format.
1076
+ - country (string, optional): The country of the customer (country code).
1077
+ - address (Address, optional): The billing address for the checkout session.
1072
1078
  - street (string, optional): The street address.
1073
1079
  - city (string, optional): The city.
1074
1080
  - zip (string, optional): The postal code.
1075
- - country (string, optional): The country.
1081
+ - country (string, optional): The country code.
1082
+ - businessAddress (Address, optional): The business address for B2B transactions.
1076
1083
  - isBusiness (boolean, optional): Indicates if the checkout is for a business.
1077
- - paymentMethodsFilter (Array of objects, optional): The payment methods to be available in the checkout. The payment methods are an object with a provider and a method property, where the method is an optional array.
1084
+ - price (number, optional): Override price for the entire order (takes precedence over item prices).
1085
+ - currency (string, optional): Override currency for the entire order.
1086
+ - paymentMethodsFilter (Array of objects, optional): Filter available payment methods in the checkout.
1087
+ - provider (string): The payment provider (e.g., 'stripe', 'klarna').
1088
+ - methods (Array of strings, optional): Specific payment methods for the provider.
1089
+ - requestedDiscountCodes (Array of strings, optional): Discount codes to apply to the checkout.
1090
+ - attribution (object, optional): Attribution and tracking data.
1091
+ - utmSource (string, optional): UTM source parameter.
1092
+ - utmMedium (string, optional): UTM medium parameter.
1093
+ - utmCampaign (string, optional): UTM campaign parameter.
1094
+ - utmTerm (string, optional): UTM term parameter.
1095
+ - utmContent (string, optional): UTM content parameter.
1096
+ - ref (string, optional): Referral identifier.
1097
+ - referrer (string, optional): Referrer URL.
1098
+ - itemSrc (string, optional): Source of the item.
1099
+ - publisherContentId (string, optional): Publisher content ID.
1100
+ - source ('CHECKOUT' | 'PAYWALL' | 'OTHERS', optional): Source of the checkout.
1101
+ - sourceId (string, optional): Source identifier.
1102
+ - \_ga, \_gid, \_fbp, \_fbc (strings, optional): Analytics tracking cookies.
1103
+ - referralEmail (string, optional): Email of the referrer.
1078
1104
 
1079
1105
  ### Returns
1080
1106
 
1081
- Promise\<CheckoutResponse\>: A promise that resolves to the response JSON object from the Sesamy API, which contains details about the created checkout session.
1107
+ Promise\<Checkout\>: A promise that resolves to the response JSON object from the Sesamy API, which contains details about the created checkout session.
1082
1108
 
1083
- ### CheckoutResponse Schema
1109
+ ### Checkout Response Schema
1084
1110
 
1085
1111
  - id (string): The unique identifier of the checkout session.
1086
- - checkoutUrl (string): The URL for the checkout session.
1087
- - status (enum): The status of the checkout session, can be 'PENDING' or 'PAID'.
1088
- - createdAt (string): The creation timestamp of the checkout session.
1089
- - modifiedAt (string): The last modified timestamp of the checkout session.
1090
- - type (enum): The type of checkout session, can be 'RECURRING' or 'SINGLE'.
1091
- - currency (string): The currency used for the checkout session.
1092
- - country (string): The country associated with the checkout session.
1093
- - redirectUrl (string): The URL to redirect to after the checkout process is completed.
1094
- - email (string, optional): The email address for the checkout session.
1095
- - language (string): The language used for the checkout session.
1112
+ - checkoutUrl (string): The URL where the user should be redirected to complete the checkout.
1113
+ - status ('PENDING' | 'PAID'): The status of the checkout session.
1114
+ - type ('RECURRING' | 'SINGLE'): The type of checkout session.
1115
+ - createdAt (string): ISO timestamp of when the checkout was created.
1116
+ - updatedAt (string): ISO timestamp of when the checkout was last updated.
1096
1117
  - items (Array of objects): The items included in the checkout session.
1097
1118
  - sku (string): The SKU of the product.
1098
- - purchaseOptionId (string, optional): The ID of the purchase option for the product.
1119
+ - url (string): The URL of the item.
1120
+ - purchaseOptionId (string, optional): The ID of the purchase option.
1121
+ - price (number, optional): The price of the item.
1122
+ - currency (string, optional): The currency of the item.
1123
+ - itemsOwned (Array of objects): Items already owned by the user.
1124
+ - sku (string): The SKU of the product.
1125
+ - purchaseOptionId (string): The purchase option ID.
1099
1126
  - title (string): The title of the product.
1100
- - cover (string): The cover image URL of the product.
1101
- - itemsOwned (Array of strings): The SKUs of the items already owned by the user.
1102
- - discountCodes (Array of strings): The discount codes applied to the checkout session.
1103
- - paymentOptions (Array of objects): The available payment options.
1127
+ - appliedDiscountCodes (Array of objects): Discount codes applied to the checkout.
1128
+ - name (string): Name of the discount.
1129
+ - description (string): Description of the discount.
1130
+ - id (string): ID of the discount code.
1131
+ - code (string): The discount code.
1132
+ - status ('APPLIED' | 'UNAPPLICABLE'): Status of the discount code.
1133
+ - availablePaymentMethods (Array of objects): Available payment methods for checkout.
1104
1134
  - provider (string): The payment provider.
1105
- - methods (Array of strings): The payment methods supported by the provider.
1135
+ - methods (Array of strings, optional): Available payment methods for the provider.
1136
+ - email (string, optional): The email address for the checkout session.
1137
+ - language (string): The language used for the checkout session.
1138
+ - currency (string): The currency used for the checkout session.
1139
+ - country (string): The country associated with the checkout session.
1140
+ - redirectUrl (string): The redirect URL after completion.
1141
+ - fieldSettings (object, optional): Field visibility and requirement settings.
1106
1142
 
1107
1143
  ### Example
1108
1144
 
1109
1145
  The following example demonstrates how to create a checkout session with Sesamy:
1110
1146
 
1111
1147
  ```javascript
1112
- import { createCheckout } from '@sesamy/sesamy-js';
1148
+ import { init } from '@sesamy/sesamy-js';
1149
+
1150
+ const sesamy = await init({ clientId: 'your-client-id' });
1113
1151
 
1114
- // Create a checkout session with one item
1115
- const checkoutParams = {
1152
+ // Create a simple checkout with one item
1153
+ const checkout = await sesamy.checkouts.create({
1116
1154
  items: [
1117
1155
  {
1118
- sku: 'sid:eUv45QXTrcGNhMJpaCQNe',
1119
- purchaseOptionsId: 'option-id', // optional
1156
+ sku: 'premium_monthly',
1157
+ purchaseOptionId: 'po_123',
1158
+ price: 9.99,
1159
+ currency: 'USD',
1120
1160
  },
1121
1161
  ],
1122
- language: 'en', // optional
1123
- };
1162
+ email: 'customer@example.com',
1163
+ redirectUrl: 'https://yoursite.com/checkout-complete',
1164
+ });
1124
1165
 
1125
- createCheckout(checkoutParams)
1126
- .then((response) => {
1127
- console.log('Checkout session created:', response);
1128
- })
1129
- .catch((error) => {
1130
- console.error('Error creating checkout session:', error);
1131
- });
1166
+ // Redirect to checkout
1167
+ window.location.href = checkout.checkoutUrl;
1132
1168
  ```
1133
1169
 
1134
- In this example, a checkout session is created with a single item specified by its SKU and an optional purchase options ID. The language is set to English (`'en'`), but if not provided, it will default to the language specified in the HTML `lang` attribute.
1170
+ Advanced example with multiple items and tracking:
1135
1171
 
1136
- ### Additional Notes
1172
+ ```javascript
1173
+ const checkout = await sesamy.checkouts.create({
1174
+ items: [
1175
+ {
1176
+ sku: 'premium_annual',
1177
+ purchaseOptionId: 'po_456',
1178
+ price: 99.99,
1179
+ currency: 'USD',
1180
+ },
1181
+ {
1182
+ sku: 'addon_feature',
1183
+ price: 9.99,
1184
+ currency: 'USD',
1185
+ },
1186
+ ],
1187
+ email: 'customer@example.com',
1188
+ givenName: 'John',
1189
+ familyName: 'Doe',
1190
+ phoneNumber: '+1234567890',
1191
+ address: {
1192
+ street: '123 Main St',
1193
+ city: 'San Francisco',
1194
+ zip: '94102',
1195
+ country: 'US',
1196
+ },
1197
+ redirectUrl: 'https://yoursite.com/checkout-complete',
1198
+ language: 'en',
1199
+ attribution: {
1200
+ utmSource: 'email',
1201
+ utmMedium: 'newsletter',
1202
+ utmCampaign: 'summer_sale_2024',
1203
+ },
1204
+ requestedDiscountCodes: ['WELCOME10', 'EARLYBIRD'],
1205
+ paymentMethodsFilter: [{ provider: 'stripe', methods: ['card'] }, { provider: 'klarna' }],
1206
+ });
1137
1207
 
1138
- - The `language` parameter is optional. If it is not provided, the language will be determined using the `getLanguage` function, which fetches the language from the `lang` attribute of the HTML document element.
1139
- - The `items` array must contain at least one item with a valid `sku`.
1208
+ window.location.href = checkout.checkoutUrl;
1209
+ ```
1210
+
1211
+ ### Additional Notes
1140
1212
 
1141
- By using the `createCheckout` function, you can easily initialize a checkout process and handle the response from the Sesamy API to complete the transaction.
1213
+ - The `items` array must contain at least one item.
1214
+ - The `redirectUrl` is required and will be used after the checkout is completed.
1215
+ - The `language` parameter is optional. If not provided, it will be determined from the HTML document's `lang` attribute.
1216
+ - Attribution data is automatically enhanced with tracking cookies (\_ga, \_gid, \_fbp, \_fbc) if available.
1217
+ - Discount codes validation happens on the Sesamy backend; invalid codes will be marked as 'UNAPPLICABLE' in the response.
1142
1218
 
1143
1219
  ## `checkouts.update(id: string, params: Partial<CreateCheckoutParams>)`
1144
1220
 
1145
- Updates a checkout session with Sesamy.
1221
+ Updates an existing checkout session with Sesamy. You can update customer information, items, or other checkout details.
1146
1222
 
1147
1223
  ### Parameters
1148
1224
 
1149
- - params (Partial<CreateCheckoutParams>): The updated parameters for the checkout session.
1150
- - items (Array of objects): An array of items to be included in the checkout.
1151
- - sku (string): The SKU of the product to be purchased.
1152
- - purchaseOptionsId (string, optional): The ID of the purchase options for the product.
1153
- - language (string, optional): The language for the checkout session.
1154
- - redirectUrl (string): The URL to redirect to after the checkout process is completed.
1155
- - givenName (string, optional): The given name of the customer.
1156
- - familyName (string, optional): The family name of the customer.
1157
- - email (string, optional): The email address for the checkout session.
1158
- - phoneNumber (string, optional): The phone number of the customer.
1159
- - birthDate (string, optional): The birth date of the customer.
1160
- - country (string, optional): The country of the customer.
1161
- - address (Address, optional): The address for the checkout session.
1162
- - street (string, optional): The street address.
1163
- - city (string, optional): The city.
1164
- - zip (string, optional): The postal code.
1165
- - country (string, optional): The country.
1166
- - isBusiness (boolean, optional): Indicates if the checkout is for a business.
1225
+ - id (string): The unique identifier of the checkout session to update.
1226
+ - params (Partial<CreateCheckoutParams>): The parameters to update. All fields are optional.
1227
+ - items (Array of objects, optional): Updated array of items.
1228
+ - sku (string, optional): The SKU of the product.
1229
+ - url (string, optional): The URL of the item.
1230
+ - purchaseOptionId (string, optional): The ID of the purchase option.
1231
+ - price (number, optional): The price of the item.
1232
+ - currency (string, optional): The currency code.
1233
+ - redirectUrl (string, optional): Updated redirect URL.
1234
+ - language (string, optional): Updated language for the checkout session.
1235
+ - email (string, optional): Updated email address.
1236
+ - givenName (string, optional): Updated given name.
1237
+ - familyName (string, optional): Updated family name.
1238
+ - phoneNumber (string, optional): Updated phone number.
1239
+ - birthDate (string, optional): Updated birth date.
1240
+ - country (string, optional): Updated country.
1241
+ - address (Address, optional): Updated billing address.
1242
+ - businessAddress (Address, optional): Updated business address.
1243
+ - isBusiness (boolean, optional): Updated business status.
1244
+ - price (number, optional): Updated order price.
1245
+ - currency (string, optional): Updated order currency.
1246
+ - paymentMethodsFilter (Array of objects, optional): Updated payment method filters.
1247
+ - requestedDiscountCodes (Array of strings, optional): Updated discount codes to apply.
1248
+ - attribution (object, optional): Updated attribution and tracking data.
1167
1249
 
1168
1250
  ### Returns
1169
1251
 
1170
- Promise\<CheckoutResponse\>: A promise that resolves to the response JSON object from the Sesamy API, which contains details about the updated checkout session.
1171
-
1172
- ### CheckoutResponse Schema
1173
-
1174
- - id (string): The unique identifier of the checkout session.
1175
- - checkoutUrl (string): The URL for the checkout session.
1176
- - status (enum): The status of the checkout session, can be 'PENDING' or 'PAID'.
1177
- - createdAt (string): The creation timestamp of the checkout session.
1178
- - modifiedAt (string): The last modified timestamp of the checkout session.
1179
- - type (enum): The type of checkout session, can be 'RECURRING' or 'SINGLE'.
1180
- - currency (string): The currency used for the checkout session.
1181
- - country (string): The country associated with the checkout session.
1182
- - language (string): The language used for the checkout session.
1183
- - items (Array of objects): The items included in the checkout session.
1184
- - sku (string): The SKU of the product.
1185
- - purchaseOptionId (string, optional): The ID of the purchase option for the product.
1186
- - title (string): The title of the product.
1187
- - cover (string): The cover image URL of the product.
1188
- - itemsOwned (Array of strings): The SKUs of the items already owned by the user.
1189
- - discountCodes (Array of strings): The discount codes applied to the checkout session.
1190
- - paymentOptions (Array of objects): The available payment options.
1191
- - provider (string): The payment provider.
1192
- - methods (Array of strings): The payment methods supported by the provider.
1252
+ Promise\<Checkout\>: A promise that resolves to the updated checkout session object.
1193
1253
 
1194
1254
  ### Example
1195
1255
 
1196
- The following example demonstrates how to create a checkout session with Sesamy:
1256
+ Basic update example:
1197
1257
 
1198
1258
  ```javascript
1199
- import { updateCheckout } from '@sesamy/sesamy-js';
1200
-
1201
- // Create a checkout session with one item
1202
- const checkoutParams = {
1203
- email: 'test@example.com',
1204
- };
1205
-
1206
- updateCheckout('checkoutId', checkoutParams)
1207
- .then((response) => {
1208
- console.log('Checkout session updated:', response);
1209
- })
1210
- .catch((error) => {
1211
- console.error('Error updating checkout session:', error);
1212
- });
1213
- ```
1214
-
1215
- In this example, a checkout session is created with a single item specified by its SKU and an optional purchase options ID. The language is set to English (`'en'`), but if not provided, it will default to the language specified in the HTML `lang` attribute.
1216
-
1217
- ### Additional Notes
1218
-
1219
- - The `language` parameter is optional. If it is not provided, the language will be determined using the `getLanguage` function, which fetches the language from the `lang` attribute of the HTML document element.
1220
- - The `items` array must contain at least one item with a valid `sku`.
1259
+ import { init } from '@sesamy/sesamy-js';
1221
1260
 
1222
- By using the `createCheckout` function, you can easily initialize a checkout process and handle the response from the Sesamy API to complete the transaction.
1261
+ const sesamy = await init({ clientId: 'your-client-id' });
1223
1262
 
1224
- ## `checkouts.get(id: string)`
1263
+ const updated = await sesamy.checkouts.update('checkout_123', {
1264
+ email: 'newemail@example.com',
1265
+ givenName: 'Jane',
1266
+ });
1225
1267
 
1226
- Retrieves the details of a specific checkout session from Sesamy. This function fetches the checkout session information based on the provided checkout session ID.
1268
+ console.log('Checkout updated:', updated);
1269
+ ```
1227
1270
 
1228
- ### Parameters
1271
+ Update with new discount codes:
1229
1272
 
1230
- - id (string): The unique identifier of the checkout session to retrieve.
1231
-
1232
- ### Returns
1273
+ ```javascript
1274
+ const updated = await sesamy.checkouts.update('checkout_123', {
1275
+ requestedDiscountCodes: ['NEWCODE', 'SUMMER20'],
1276
+ });
1233
1277
 
1234
- Promise\<CheckoutResponse\>: A promise that resolves to the response JSON object from the Sesamy API, which contains details about the requested checkout session.
1278
+ console.log('Applied discount codes:', updated.appliedDiscountCodes);
1279
+ ```
1235
1280
 
1236
- ### CheckoutResponse Schema
1281
+ ### Additional Notes
1237
1282
 
1238
- - id (string): The unique identifier of the checkout session.
1239
- - checkoutUrl (string): The URL for the checkout session.
1240
- - status (enum): The status of the checkout session, can be 'PENDING' or 'PAID'.
1241
- - createdAt (string): The creation timestamp of the checkout session.
1242
- - modifiedAt (string): The last modified timestamp of the checkout session.
1243
- - type (enum): The type of checkout session, can be 'RECURRING' or 'SINGLE'.
1244
- - currency (string): The currency used for the checkout session.
1283
+ - Only provide the fields you want to update; omitted fields will remain unchanged.
1284
+ - Discount codes are validated on the Sesamy backend.
1285
+ - Changes to payment method filters will be reflected in the checkout session immediately.
1245
1286
  - country (string): The country associated with the checkout session.
1246
1287
  - language (string): The language used for the checkout session.
1247
1288
  - items (Array of objects): The items included in the checkout session.
@@ -1255,32 +1296,36 @@ Promise\<CheckoutResponse\>: A promise that resolves to the response JSON object
1255
1296
  - provider (string): The payment provider.
1256
1297
  - methods (Array of strings): The payment methods supported by the provider.
1257
1298
 
1258
- ### Example
1299
+ ## `checkouts.get(id: string)`
1259
1300
 
1260
- The following example demonstrates how to retrieve the details of a specific checkout session with Sesamy:
1301
+ Retrieves the details of a specific checkout session from Sesamy.
1302
+
1303
+ ### Parameters
1304
+
1305
+ - id (string): The unique identifier of the checkout session to retrieve.
1306
+
1307
+ ### Returns
1308
+
1309
+ Promise\<Checkout\>: A promise that resolves to the checkout session object with all details.
1310
+
1311
+ ### Example
1261
1312
 
1262
1313
  ```javascript
1263
- import { getCheckout } from '@sesamy/sesamy-js';
1314
+ import { init } from '@sesamy/sesamy-js';
1264
1315
 
1265
- // Retrieve the details of a checkout session by ID
1266
- const checkoutId = 'checkout-session-id';
1316
+ const sesamy = await init({ clientId: 'your-client-id' });
1267
1317
 
1268
- getCheckout(checkoutId)
1269
- .then((response) => {
1270
- console.log('Checkout session details:', response);
1271
- })
1272
- .catch((error) => {
1273
- console.error('Error retrieving checkout session:', error);
1274
- });
1318
+ const checkout = await sesamy.checkouts.get('checkout_123');
1319
+ console.log('Checkout status:', checkout.status);
1320
+ console.log('Checkout URL:', checkout.checkoutUrl);
1321
+ console.log('Applied discounts:', checkout.appliedDiscountCodes);
1322
+ console.log('Items owned:', checkout.itemsOwned);
1275
1323
  ```
1276
1324
 
1277
- In this example, the details of a specific checkout session are retrieved using its unique ID. The function returns a promise that resolves to the details of the checkout session.
1278
-
1279
1325
  ### Additional Notes
1280
1326
 
1281
1327
  - The `id` parameter is required and must be a valid checkout session identifier.
1282
-
1283
- By using the `getCheckout` function, you can easily fetch the details of a specific checkout session from the Sesamy API to view or process the transaction information.
1328
+ - Returns the complete checkout session data including status, items, and applied discounts.
1284
1329
 
1285
1330
  # Browser API
1286
1331