@commercengine/storefront-sdk 0.10.2 → 0.11.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/dist/{index.d.ts → index.d.mts} +1242 -382
- package/dist/index.iife.js +249 -44
- package/dist/index.iife.js.map +1 -1
- package/dist/{index.js → index.mjs} +234 -28
- package/dist/index.mjs.map +1 -0
- package/package.json +14 -14
- package/dist/index.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import createClient from "openapi-fetch";
|
|
2
2
|
import { decodeJwt } from "jose";
|
|
3
3
|
|
|
4
|
-
//#region ../sdk-core/dist/index.
|
|
4
|
+
//#region ../sdk-core/dist/index.mjs
|
|
5
5
|
/**
|
|
6
6
|
* Response utilities for debugging and working with Response objects
|
|
7
7
|
*/
|
|
@@ -308,6 +308,10 @@ async function executeRequest(apiCall) {
|
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
/**
|
|
311
|
+
* Base API client for Commerce Engine SDKs
|
|
312
|
+
* Provides common functionality without token management
|
|
313
|
+
*/
|
|
314
|
+
/**
|
|
311
315
|
* Generic base API client that all Commerce Engine SDKs can extend
|
|
312
316
|
* Handles common functionality like middleware setup, request execution, and header management
|
|
313
317
|
* Does NOT include token management - that's SDK-specific
|
|
@@ -2875,27 +2879,80 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
2875
2879
|
* @returns Promise with order details
|
|
2876
2880
|
* @example
|
|
2877
2881
|
* ```typescript
|
|
2878
|
-
* //
|
|
2882
|
+
* // Juspay Hyper Checkout - Redirects to hosted payment page
|
|
2879
2883
|
* const { data, error } = await sdk.order.createOrder({
|
|
2880
2884
|
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
2881
|
-
*
|
|
2882
|
-
*
|
|
2883
|
-
*
|
|
2884
|
-
*
|
|
2885
|
-
*
|
|
2885
|
+
* payment_method: {
|
|
2886
|
+
* payment_provider_slug: "juspay",
|
|
2887
|
+
* integration_type: "hyper-checkout",
|
|
2888
|
+
* gateway_reference_id: "gateway_ref_123",
|
|
2889
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
2890
|
+
* action: "paymentPage"
|
|
2886
2891
|
* }
|
|
2887
2892
|
* });
|
|
2888
2893
|
*
|
|
2889
|
-
* //
|
|
2894
|
+
* // Juspay Express Checkout - New Card
|
|
2890
2895
|
* const { data, error } = await sdk.order.createOrder({
|
|
2891
2896
|
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
2892
|
-
*
|
|
2893
|
-
*
|
|
2894
|
-
*
|
|
2895
|
-
*
|
|
2896
|
-
*
|
|
2897
|
+
* payment_method: {
|
|
2898
|
+
* payment_provider_slug: "juspay",
|
|
2899
|
+
* integration_type: "express-checkout",
|
|
2900
|
+
* gateway_reference_id: "gateway_ref_123",
|
|
2901
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
2902
|
+
* payment_method_type: "CARD",
|
|
2903
|
+
* payment_method: "VISA",
|
|
2904
|
+
* auth_type: "OTP",
|
|
2905
|
+
* save_to_locker: true,
|
|
2906
|
+
* card_number: "4111111111111111",
|
|
2907
|
+
* card_exp_month: "12",
|
|
2908
|
+
* card_exp_year: "2025",
|
|
2909
|
+
* name_on_card: "John Doe",
|
|
2910
|
+
* card_security_code: "123"
|
|
2911
|
+
* }
|
|
2912
|
+
* });
|
|
2913
|
+
*
|
|
2914
|
+
* // Juspay Express Checkout - Saved Card Token
|
|
2915
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
2916
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
2917
|
+
* payment_method: {
|
|
2918
|
+
* payment_provider_slug: "juspay",
|
|
2919
|
+
* integration_type: "express-checkout",
|
|
2920
|
+
* gateway_reference_id: "gateway_ref_123",
|
|
2921
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
2922
|
+
* get_client_auth_token: true,
|
|
2923
|
+
* payment_method_type: "CARD",
|
|
2924
|
+
* payment_method: "VISA",
|
|
2925
|
+
* auth_type: "OTP",
|
|
2926
|
+
* save_to_locker: false,
|
|
2927
|
+
* card_token: "token_abc123",
|
|
2928
|
+
* card_security_code: "123"
|
|
2929
|
+
* }
|
|
2930
|
+
* });
|
|
2931
|
+
*
|
|
2932
|
+
* // Juspay Express Checkout - UPI Collect
|
|
2933
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
2934
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
2935
|
+
* payment_method: {
|
|
2936
|
+
* payment_provider_slug: "juspay",
|
|
2937
|
+
* integration_type: "express-checkout",
|
|
2938
|
+
* gateway_reference_id: "gateway_ref_123",
|
|
2939
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
2940
|
+
* payment_method_type: "UPI",
|
|
2941
|
+
* payment_method: "UPI_COLLECT",
|
|
2942
|
+
* upi_vpa: "user@upi"
|
|
2943
|
+
* }
|
|
2944
|
+
* });
|
|
2945
|
+
*
|
|
2946
|
+
* // Juspay Express Checkout - Net Banking
|
|
2947
|
+
* const { data, error } = await sdk.order.createOrder({
|
|
2948
|
+
* cart_id: "cart_01H9XYZ12345ABCDE",
|
|
2949
|
+
* payment_method: {
|
|
2950
|
+
* payment_provider_slug: "juspay",
|
|
2951
|
+
* integration_type: "express-checkout",
|
|
2952
|
+
* gateway_reference_id: "gateway_ref_123",
|
|
2897
2953
|
* return_url: "https://yourapp.com/payment/return",
|
|
2898
|
-
*
|
|
2954
|
+
* payment_method_type: "NB",
|
|
2955
|
+
* payment_method: "NB_HDFC"
|
|
2899
2956
|
* }
|
|
2900
2957
|
* });
|
|
2901
2958
|
*
|
|
@@ -2905,6 +2962,17 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
2905
2962
|
* console.log("Order created:", data.order.id);
|
|
2906
2963
|
* console.log("Payment required:", data.payment_required);
|
|
2907
2964
|
* console.log("Payment info:", data.payment_info);
|
|
2965
|
+
*
|
|
2966
|
+
* // For hyper-checkout, redirect to payment page
|
|
2967
|
+
* if ("payment_links" in data.payment_info) {
|
|
2968
|
+
* window.location.href = data.payment_info.payment_links?.web;
|
|
2969
|
+
* }
|
|
2970
|
+
*
|
|
2971
|
+
* // For express-checkout with OTP authentication
|
|
2972
|
+
* if ("payment" in data.payment_info && data.payment_info.payment?.authentication?.params) {
|
|
2973
|
+
* const { id: txn_id, challenge_id } = data.payment_info.payment.authentication.params;
|
|
2974
|
+
* // Use txn_id and challenge_id with sdk.payments.authenticateDirectOtp()
|
|
2975
|
+
* }
|
|
2908
2976
|
* }
|
|
2909
2977
|
* ```
|
|
2910
2978
|
*/
|
|
@@ -3092,28 +3160,32 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3092
3160
|
* @returns Promise with payment information
|
|
3093
3161
|
* @example
|
|
3094
3162
|
* ```typescript
|
|
3095
|
-
* //
|
|
3163
|
+
* // Juspay Hyper Checkout - Redirects to hosted payment page
|
|
3096
3164
|
* const { data, error } = await sdk.order.retryOrderPayment(
|
|
3097
3165
|
* { order_number: "ORD-2024-001" },
|
|
3098
3166
|
* {
|
|
3099
|
-
*
|
|
3100
|
-
*
|
|
3101
|
-
*
|
|
3102
|
-
*
|
|
3167
|
+
* payment_method: {
|
|
3168
|
+
* payment_provider_slug: "juspay",
|
|
3169
|
+
* integration_type: "hyper-checkout",
|
|
3170
|
+
* gateway_reference_id: "gateway_ref_123",
|
|
3171
|
+
* return_url: "https://yourapp.com/payment/return",
|
|
3172
|
+
* action: "paymentPage"
|
|
3103
3173
|
* }
|
|
3104
3174
|
* }
|
|
3105
3175
|
* );
|
|
3106
3176
|
*
|
|
3107
|
-
* //
|
|
3177
|
+
* // Juspay Express Checkout - UPI Collect
|
|
3108
3178
|
* const { data, error } = await sdk.order.retryOrderPayment(
|
|
3109
3179
|
* { order_number: "ORD-2024-001" },
|
|
3110
3180
|
* {
|
|
3111
|
-
*
|
|
3112
|
-
*
|
|
3113
|
-
*
|
|
3114
|
-
*
|
|
3181
|
+
* payment_method: {
|
|
3182
|
+
* payment_provider_slug: "juspay",
|
|
3183
|
+
* integration_type: "express-checkout",
|
|
3184
|
+
* gateway_reference_id: "gateway_ref_123",
|
|
3115
3185
|
* return_url: "https://yourapp.com/payment/return",
|
|
3116
|
-
*
|
|
3186
|
+
* payment_method_type: "UPI",
|
|
3187
|
+
* payment_method: "UPI_COLLECT",
|
|
3188
|
+
* upi_vpa: "user@upi"
|
|
3117
3189
|
* }
|
|
3118
3190
|
* }
|
|
3119
3191
|
* );
|
|
@@ -3123,7 +3195,11 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3123
3195
|
* } else {
|
|
3124
3196
|
* console.log("Payment retry initiated");
|
|
3125
3197
|
* console.log("Payment info:", data.payment_info);
|
|
3126
|
-
*
|
|
3198
|
+
*
|
|
3199
|
+
* // For hyper-checkout, redirect to payment page
|
|
3200
|
+
* if ("payment_links" in data.payment_info) {
|
|
3201
|
+
* window.location.href = data.payment_info.payment_links?.web;
|
|
3202
|
+
* }
|
|
3127
3203
|
* }
|
|
3128
3204
|
* ```
|
|
3129
3205
|
*/
|
|
@@ -3135,6 +3211,126 @@ var OrderClient = class extends StorefrontAPIClient {
|
|
|
3135
3211
|
}
|
|
3136
3212
|
};
|
|
3137
3213
|
|
|
3214
|
+
//#endregion
|
|
3215
|
+
//#region src/lib/payments.ts
|
|
3216
|
+
/**
|
|
3217
|
+
* Client for interacting with payment endpoints
|
|
3218
|
+
*/
|
|
3219
|
+
var PaymentsClient = class extends StorefrontAPIClient {
|
|
3220
|
+
/**
|
|
3221
|
+
* List all available payment methods
|
|
3222
|
+
*
|
|
3223
|
+
* @returns Promise with list of payment methods
|
|
3224
|
+
* @example
|
|
3225
|
+
* ```typescript
|
|
3226
|
+
* const { data, error } = await sdk.payments.listPaymentMethods();
|
|
3227
|
+
*
|
|
3228
|
+
* if (error) {
|
|
3229
|
+
* console.error("Failed to list payment methods:", error.message);
|
|
3230
|
+
* } else {
|
|
3231
|
+
* console.log("Payment methods:", data.payment_methods);
|
|
3232
|
+
*
|
|
3233
|
+
* data.payment_methods?.forEach(method => {
|
|
3234
|
+
* console.log("Payment method:", method.name);
|
|
3235
|
+
* console.log("Gateway:", method.payment_gateway);
|
|
3236
|
+
* });
|
|
3237
|
+
* }
|
|
3238
|
+
* ```
|
|
3239
|
+
*/
|
|
3240
|
+
async listPaymentMethods() {
|
|
3241
|
+
return this.executeRequest(() => this.client.GET("/payments/payment-methods", {}));
|
|
3242
|
+
}
|
|
3243
|
+
/**
|
|
3244
|
+
* Verify a UPI Virtual Payment Address (VPA)
|
|
3245
|
+
*
|
|
3246
|
+
* @description The Virtual Payment Address or VPA is a unique ID given to an individual
|
|
3247
|
+
* using the Unified Payment Interface (UPI) service to send or receive money.
|
|
3248
|
+
* Validating the VPA helps reduce payment failure rates due to incorrect VPA.
|
|
3249
|
+
*
|
|
3250
|
+
* @param queryParams - Query parameters containing the VPA to verify
|
|
3251
|
+
* @returns Promise with VPA verification result
|
|
3252
|
+
* @example
|
|
3253
|
+
* ```typescript
|
|
3254
|
+
* const { data, error } = await sdk.payments.verifyVpa({
|
|
3255
|
+
* vpa: "user@upi"
|
|
3256
|
+
* });
|
|
3257
|
+
*
|
|
3258
|
+
* if (error) {
|
|
3259
|
+
* console.error("Failed to verify VPA:", error.message);
|
|
3260
|
+
* } else {
|
|
3261
|
+
* console.log("VPA:", data.vpa);
|
|
3262
|
+
* console.log("Status:", data.status);
|
|
3263
|
+
*
|
|
3264
|
+
* if (data.status === "VALID") {
|
|
3265
|
+
* console.log("VPA is valid and can be used for UPI payments");
|
|
3266
|
+
* } else {
|
|
3267
|
+
* console.log("VPA is invalid, please check and try again");
|
|
3268
|
+
* }
|
|
3269
|
+
* }
|
|
3270
|
+
* ```
|
|
3271
|
+
*/
|
|
3272
|
+
async verifyVpa(queryParams) {
|
|
3273
|
+
return this.executeRequest(() => this.client.GET("/payments/verify-vpa", { params: { query: queryParams } }));
|
|
3274
|
+
}
|
|
3275
|
+
/**
|
|
3276
|
+
* Authenticate a direct OTP for payment verification
|
|
3277
|
+
*
|
|
3278
|
+
* @description Used to authenticate OTP during payment flows that require 2FA verification.
|
|
3279
|
+
* The txn_id and challenge_id can be obtained from the create order API response
|
|
3280
|
+
* under the payment_info.authentication.params object.
|
|
3281
|
+
*
|
|
3282
|
+
* @param body - OTP authentication request body
|
|
3283
|
+
* @returns Promise with authentication result
|
|
3284
|
+
* @example
|
|
3285
|
+
* ```typescript
|
|
3286
|
+
* // After creating an order, if OTP authentication is required:
|
|
3287
|
+
* const { data, error } = await sdk.payments.authenticateDirectOtp({
|
|
3288
|
+
* txn_id: "txn_01H9XYZ12345ABCDE",
|
|
3289
|
+
* challenge_id: "challenge_01H9XYZ12345ABCDE",
|
|
3290
|
+
* otp: "123456"
|
|
3291
|
+
* });
|
|
3292
|
+
*
|
|
3293
|
+
* if (error) {
|
|
3294
|
+
* console.error("OTP authentication failed:", error.message);
|
|
3295
|
+
* } else {
|
|
3296
|
+
* console.log("Authentication success:", data.success);
|
|
3297
|
+
* console.log("Message:", data.message);
|
|
3298
|
+
* }
|
|
3299
|
+
* ```
|
|
3300
|
+
*/
|
|
3301
|
+
async authenticateDirectOtp(body) {
|
|
3302
|
+
return this.executeRequest(() => this.client.POST("/payments/authenticate-direct-otp", { body }));
|
|
3303
|
+
}
|
|
3304
|
+
/**
|
|
3305
|
+
* Resend a direct OTP for payment verification
|
|
3306
|
+
*
|
|
3307
|
+
* @description Used to resend OTP during payment flows that require 2FA verification.
|
|
3308
|
+
* The txn_id and challenge_id can be obtained from the create order API response
|
|
3309
|
+
* under the payment_info.authentication.params object.
|
|
3310
|
+
*
|
|
3311
|
+
* @param body - OTP resend request body
|
|
3312
|
+
* @returns Promise with new payment info containing updated OTP challenge
|
|
3313
|
+
* @example
|
|
3314
|
+
* ```typescript
|
|
3315
|
+
* // If user didn't receive OTP or it expired:
|
|
3316
|
+
* const { data, error } = await sdk.payments.resendDirectOtp({
|
|
3317
|
+
* txn_id: "txn_01H9XYZ12345ABCDE",
|
|
3318
|
+
* challenge_id: "challenge_01H9XYZ12345ABCDE"
|
|
3319
|
+
* });
|
|
3320
|
+
*
|
|
3321
|
+
* if (error) {
|
|
3322
|
+
* console.error("Failed to resend OTP:", error.message);
|
|
3323
|
+
* } else {
|
|
3324
|
+
* console.log("OTP resent successfully");
|
|
3325
|
+
* console.log("New payment info:", data.payment_info);
|
|
3326
|
+
* }
|
|
3327
|
+
* ```
|
|
3328
|
+
*/
|
|
3329
|
+
async resendDirectOtp(body) {
|
|
3330
|
+
return this.executeRequest(() => this.client.POST("/payments/resend-direct-otp", { body }));
|
|
3331
|
+
}
|
|
3332
|
+
};
|
|
3333
|
+
|
|
3138
3334
|
//#endregion
|
|
3139
3335
|
//#region src/lib/shipping.ts
|
|
3140
3336
|
/**
|
|
@@ -3738,6 +3934,10 @@ var StorefrontSDK = class {
|
|
|
3738
3934
|
*/
|
|
3739
3935
|
order;
|
|
3740
3936
|
/**
|
|
3937
|
+
* Client for payment-related endpoints
|
|
3938
|
+
*/
|
|
3939
|
+
payments;
|
|
3940
|
+
/**
|
|
3741
3941
|
* Client for store config-related endpoints
|
|
3742
3942
|
*/
|
|
3743
3943
|
store;
|
|
@@ -3774,6 +3974,7 @@ var StorefrontSDK = class {
|
|
|
3774
3974
|
this.helpers = new HelpersClient(config);
|
|
3775
3975
|
this.shipping = new ShippingClient(config);
|
|
3776
3976
|
this.order = new OrderClient(config);
|
|
3977
|
+
this.payments = new PaymentsClient(config);
|
|
3777
3978
|
this.store = new StoreConfigClient(config);
|
|
3778
3979
|
}
|
|
3779
3980
|
/**
|
|
@@ -3794,6 +3995,7 @@ var StorefrontSDK = class {
|
|
|
3794
3995
|
await this.helpers.setTokens(accessToken, refreshToken);
|
|
3795
3996
|
await this.shipping.setTokens(accessToken, refreshToken);
|
|
3796
3997
|
await this.order.setTokens(accessToken, refreshToken);
|
|
3998
|
+
await this.payments.setTokens(accessToken, refreshToken);
|
|
3797
3999
|
await this.store.setTokens(accessToken, refreshToken);
|
|
3798
4000
|
}
|
|
3799
4001
|
/**
|
|
@@ -3811,6 +4013,7 @@ var StorefrontSDK = class {
|
|
|
3811
4013
|
await this.helpers.clearTokens();
|
|
3812
4014
|
await this.shipping.clearTokens();
|
|
3813
4015
|
await this.order.clearTokens();
|
|
4016
|
+
await this.payments.clearTokens();
|
|
3814
4017
|
await this.store.clearTokens();
|
|
3815
4018
|
}
|
|
3816
4019
|
/**
|
|
@@ -3826,6 +4029,7 @@ var StorefrontSDK = class {
|
|
|
3826
4029
|
this.helpers.setApiKey(apiKey);
|
|
3827
4030
|
this.shipping.setApiKey(apiKey);
|
|
3828
4031
|
this.order.setApiKey(apiKey);
|
|
4032
|
+
this.payments.setApiKey(apiKey);
|
|
3829
4033
|
this.store.setApiKey(apiKey);
|
|
3830
4034
|
}
|
|
3831
4035
|
/**
|
|
@@ -3839,6 +4043,7 @@ var StorefrontSDK = class {
|
|
|
3839
4043
|
this.helpers.clearApiKey();
|
|
3840
4044
|
this.shipping.clearApiKey();
|
|
3841
4045
|
this.order.clearApiKey();
|
|
4046
|
+
this.payments.clearApiKey();
|
|
3842
4047
|
this.store.clearApiKey();
|
|
3843
4048
|
}
|
|
3844
4049
|
/**
|
|
@@ -3917,6 +4122,7 @@ var StorefrontSDK = class {
|
|
|
3917
4122
|
this.helpers.setDefaultHeaders(headers);
|
|
3918
4123
|
this.shipping.setDefaultHeaders(headers);
|
|
3919
4124
|
this.order.setDefaultHeaders(headers);
|
|
4125
|
+
this.payments.setDefaultHeaders(headers);
|
|
3920
4126
|
this.store.setDefaultHeaders(headers);
|
|
3921
4127
|
}
|
|
3922
4128
|
/**
|
|
@@ -3931,5 +4137,5 @@ var StorefrontSDK = class {
|
|
|
3931
4137
|
var src_default = StorefrontSDK;
|
|
3932
4138
|
|
|
3933
4139
|
//#endregion
|
|
3934
|
-
export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, src_default as default };
|
|
3935
|
-
//# sourceMappingURL=index.
|
|
4140
|
+
export { AuthClient, BrowserTokenStorage, CartClient, CatalogClient, CookieTokenStorage, CustomerClient, Environment, HelpersClient, MemoryTokenStorage, OrderClient, PaymentsClient, ResponseUtils, ShippingClient, StoreConfigClient, StorefrontAPIClient, StorefrontSDK, src_default as default };
|
|
4141
|
+
//# sourceMappingURL=index.mjs.map
|