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