@mohasinac/appkit 4.41.17 → 4.42.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.
Files changed (164) hide show
  1. package/dist/_internal/client/features/maintenance/views/MaintenanceDashboardView.js +1 -1
  2. package/dist/_internal/server/features/checkout/actions.d.ts +16 -14
  3. package/dist/_internal/server/features/checkout/actions.js +145 -97
  4. package/dist/_internal/server/features/checkout/bundle-expansion.d.ts +1 -1
  5. package/dist/_internal/server/features/checkout/index.d.ts +1 -1
  6. package/dist/_internal/server/features/checkout/index.js +1 -1
  7. package/dist/_internal/server/features/checkout/locked-lines.js +1 -1
  8. package/dist/_internal/server/features/checkout/source-context.js +2 -2
  9. package/dist/_internal/server/features/maintenance/analyze.js +1 -1
  10. package/dist/_internal/server/features/refunds/actions.d.ts +4 -4
  11. package/dist/_internal/server/features/refunds/actions.js +9 -8
  12. package/dist/_internal/server/functions/scheduled.d.ts +1 -2
  13. package/dist/_internal/server/functions/scheduled.js +1 -9
  14. package/dist/_internal/server/jobs/core/index.d.ts +0 -1
  15. package/dist/_internal/server/jobs/core/index.js +0 -1
  16. package/dist/_internal/server/jobs/handlers/index.d.ts +0 -1
  17. package/dist/_internal/server/jobs/handlers/index.js +0 -1
  18. package/dist/_internal/shared/actions/action-registry.js +2 -2
  19. package/dist/_internal/shared/checkout/order-math.d.ts +1 -1
  20. package/dist/_internal/shared/checkout/order-math.js +1 -1
  21. package/dist/_internal/shared/checkout/rules/prize-draw.rule.js +2 -2
  22. package/dist/_internal/shared/features/blog/schema.d.ts +4 -4
  23. package/dist/_internal/shared/features/cart/schema.d.ts +6 -6
  24. package/dist/_internal/shared/features/orders/refund-copy.d.ts +1 -1
  25. package/dist/_internal/shared/features/orders/refund-copy.js +1 -1
  26. package/dist/_internal/shared/features/orders/schema.d.ts +5 -5
  27. package/dist/_internal/shared/features/orders/schema.js +1 -1
  28. package/dist/_internal/shared/features/products/schema.d.ts +2 -2
  29. package/dist/_internal/shared/features/promotions/schema.d.ts +4 -4
  30. package/dist/_internal/shared/features/reviews/schema.d.ts +1 -1
  31. package/dist/client.d.ts +1 -1
  32. package/dist/client.js +1 -1
  33. package/dist/configs/next.js +2 -2
  34. package/dist/constants/field-names.d.ts +1 -1
  35. package/dist/constants/field-names.js +1 -1
  36. package/dist/contracts/index.d.ts +0 -2
  37. package/dist/contracts/index.js +0 -1
  38. package/dist/contracts/payment.d.ts +13 -2
  39. package/dist/contracts/payment.js +2 -2
  40. package/dist/core/integration-keys.d.ts +7 -3
  41. package/dist/core/integration-keys.js +13 -7
  42. package/dist/core/money.d.ts +11 -0
  43. package/dist/core/money.js +15 -0
  44. package/dist/errors/index.d.ts +1 -1
  45. package/dist/errors/index.js +1 -1
  46. package/dist/errors/messages.d.ts +1 -0
  47. package/dist/errors/messages.js +1 -0
  48. package/dist/errors/{razorpay-unreachable.d.ts → payment-provider-unreachable.d.ts} +1 -1
  49. package/dist/errors/{razorpay-unreachable.js → payment-provider-unreachable.js} +1 -1
  50. package/dist/features/addresses/schemas/address-form.d.ts +20 -20
  51. package/dist/features/addresses/schemas/index.d.ts +2 -2
  52. package/dist/features/admin/components/AdminSiteSettingsView.js +32 -16
  53. package/dist/features/admin/constants/site-settings-tabs.d.ts +1 -1
  54. package/dist/features/admin/schemas/admin-ops-forms.d.ts +10 -10
  55. package/dist/features/admin/schemas/admin-user-form.d.ts +2 -2
  56. package/dist/features/admin/schemas/firestore.d.ts +17 -8
  57. package/dist/features/admin/schemas/firestore.js +1 -1
  58. package/dist/features/admin/schemas/nav-item-form.d.ts +2 -2
  59. package/dist/features/auctions/schemas/index.d.ts +2 -2
  60. package/dist/features/auth/schemas/index.d.ts +2 -2
  61. package/dist/features/before-after/schemas/index.d.ts +2 -2
  62. package/dist/features/blog/actions/blog-actions.d.ts +4 -4
  63. package/dist/features/blog/schemas/blog-form.d.ts +2 -2
  64. package/dist/features/blog/schemas/index.d.ts +4 -4
  65. package/dist/features/cart/schemas/index.d.ts +3 -3
  66. package/dist/features/catalogue/schemas/validation.d.ts +4 -4
  67. package/dist/features/categories/schemas/index.d.ts +2 -2
  68. package/dist/features/checkout/index.d.ts +0 -4
  69. package/dist/features/checkout/index.js +0 -3
  70. package/dist/features/checkout/types/index.d.ts +0 -25
  71. package/dist/features/checkout/types/index.js +1 -2
  72. package/dist/features/collections/schemas/index.d.ts +2 -2
  73. package/dist/features/consultation/schemas/index.d.ts +4 -4
  74. package/dist/features/corporate/schemas/index.d.ts +2 -2
  75. package/dist/features/events/schemas/index.d.ts +4 -4
  76. package/dist/features/grouped/schemas/index.d.ts +2 -2
  77. package/dist/features/homepage/schemas/index.d.ts +2 -2
  78. package/dist/features/lottery/schemas/zod.d.ts +4 -4
  79. package/dist/features/loyalty/schemas/index.d.ts +6 -6
  80. package/dist/features/orders/components/OrderPaymentSummary.d.ts +1 -1
  81. package/dist/features/orders/components/OrderPaymentSummary.js +5 -5
  82. package/dist/features/orders/components/RefundHistoryTable.js +1 -1
  83. package/dist/features/orders/repository/orders.repository.d.ts +10 -1
  84. package/dist/features/orders/repository/orders.repository.js +17 -1
  85. package/dist/features/orders/schemas/firestore.d.ts +11 -12
  86. package/dist/features/orders/schemas/firestore.js +0 -1
  87. package/dist/features/orders/schemas/index.d.ts +48 -48
  88. package/dist/features/orders/schemas/index.js +1 -1
  89. package/dist/features/orders/types/index.d.ts +1 -3
  90. package/dist/features/orders/types/index.js +1 -2
  91. package/dist/features/payments/manifest.js +1 -1
  92. package/dist/features/payments/repository/payout.repository.d.ts +1 -4
  93. package/dist/features/payments/repository/payout.repository.js +0 -29
  94. package/dist/features/payments/schemas/firestore.d.ts +8 -15
  95. package/dist/features/payments/schemas/firestore.js +7 -5
  96. package/dist/features/payments/schemas/index.d.ts +52 -125
  97. package/dist/features/payments/schemas/index.js +0 -58
  98. package/dist/features/payments/types/index.d.ts +2 -4
  99. package/dist/features/payments/types/index.js +1 -2
  100. package/dist/features/products/schemas/index.d.ts +14 -14
  101. package/dist/features/products/schemas/product-features.validators.d.ts +10 -10
  102. package/dist/features/promotions/schemas/index.d.ts +20 -20
  103. package/dist/features/reviews/schemas/index.d.ts +8 -8
  104. package/dist/features/scams/schemas/index.d.ts +10 -10
  105. package/dist/features/search/action-index/settings-entries.js +4 -4
  106. package/dist/features/seller/schemas/index.d.ts +12 -12
  107. package/dist/features/seller/schemas/order-forms.d.ts +4 -4
  108. package/dist/features/shipments/schemas/validation.d.ts +28 -28
  109. package/dist/features/store-extensions/schemas/payout-method-form.d.ts +50 -50
  110. package/dist/features/store-extensions/schemas/report-create-form.d.ts +2 -2
  111. package/dist/features/store-extensions/schemas/shipping-config-form.d.ts +10 -10
  112. package/dist/features/support/schemas/index.d.ts +14 -14
  113. package/dist/features/tester/actions/checklist-item-actions.d.ts +4 -4
  114. package/dist/features/tester/schemas/checklist-item-form.d.ts +2 -2
  115. package/dist/features/tester/seed-data/_money-flows.js +145 -0
  116. package/dist/features/tester/seed-data/authored/admin__site-system.js +38 -0
  117. package/dist/features/tester/seed-data/authored/buying__buying-checkout.js +10 -10
  118. package/dist/features/tester/seed-data/authored/buying__offers.js +11 -10
  119. package/dist/features/tester/seed-data/authored/cta-layout__checkout-bottom-bar.js +1 -1
  120. package/dist/features/tester/seed-data/tester-checklist-seed-data.js +24 -12
  121. package/dist/features/wishlist/schemas/index.d.ts +2 -2
  122. package/dist/index.d.ts +6 -28
  123. package/dist/index.js +8 -51
  124. package/dist/jobs.d.ts +1 -1
  125. package/dist/jobs.js +1 -1
  126. package/dist/providers/payment-phonepe/index.d.ts +117 -0
  127. package/dist/providers/payment-phonepe/index.js +221 -0
  128. package/dist/providers.d.ts +3 -2
  129. package/dist/providers.js +3 -2
  130. package/dist/schemas/registry.d.ts +163 -2623
  131. package/dist/schemas/registry.js +1 -6
  132. package/dist/seed/faq-seed-data.js +5 -5
  133. package/dist/seed/payouts-seed-data.js +3 -3
  134. package/dist/seed/site-settings-seed-data.js +7 -4
  135. package/dist/server-entry.d.ts +1 -2
  136. package/dist/server-entry.js +1 -3
  137. package/dist/server.d.ts +3 -9
  138. package/dist/server.js +5 -23
  139. package/dist/validation/schemas.d.ts +2 -2
  140. package/package.json +5 -4
  141. package/dist/_internal/server/features/payments/actions.d.ts +0 -30
  142. package/dist/_internal/server/features/payments/actions.js +0 -45
  143. package/dist/_internal/server/features/payments/data.d.ts +0 -13
  144. package/dist/_internal/server/features/payments/data.js +0 -20
  145. package/dist/_internal/server/features/payments/index.d.ts +0 -3
  146. package/dist/_internal/server/features/payments/index.js +0 -3
  147. package/dist/_internal/server/jobs/core/payoutBatch.d.ts +0 -2
  148. package/dist/_internal/server/jobs/core/payoutBatch.js +0 -120
  149. package/dist/_internal/server/jobs/handlers/payoutBatch.d.ts +0 -2
  150. package/dist/_internal/server/jobs/handlers/payoutBatch.js +0 -2
  151. package/dist/_internal/shared/features/payments/config.d.ts +0 -3
  152. package/dist/_internal/shared/features/payments/config.js +0 -3
  153. package/dist/contracts/client-payment-gateway.d.ts +0 -64
  154. package/dist/contracts/client-payment-gateway.js +0 -25
  155. package/dist/features/checkout/hooks/useCheckout.d.ts +0 -9
  156. package/dist/features/checkout/hooks/useCheckout.js +0 -24
  157. package/dist/features/checkout/hooks/useCheckoutApi.d.ts +0 -72
  158. package/dist/features/checkout/hooks/useCheckoutApi.js +0 -47
  159. package/dist/features/checkout/hooks/usePaymentCheckout.d.ts +0 -77
  160. package/dist/features/checkout/hooks/usePaymentCheckout.js +0 -192
  161. package/dist/providers/payment-razorpay/index.d.ts +0 -115
  162. package/dist/providers/payment-razorpay/index.js +0 -208
  163. package/dist/schemas/webhooks/razorpay.d.ts +0 -2634
  164. package/dist/schemas/webhooks/razorpay.js +0 -104
@@ -1,9 +0,0 @@
1
- import type { CheckoutState, CheckoutStep, UserAddress, ShippingOption, PaymentGateway } from "../types";
2
- export declare function useCheckout(initial?: Partial<CheckoutState>): {
3
- state: CheckoutState;
4
- setStep: (step: CheckoutStep) => void;
5
- setAddress: (address: UserAddress) => void;
6
- setShipping: (option: ShippingOption) => void;
7
- setPayment: (gateway: PaymentGateway) => void;
8
- setCoupon: (code: string) => void;
9
- };
@@ -1,24 +0,0 @@
1
- "use client";
2
- import { useState, useCallback } from "react";
3
- export function useCheckout(initial) {
4
- const [state, setState] = useState({
5
- step: "address",
6
- ...initial,
7
- });
8
- const setStep = useCallback((step) => {
9
- setState((s) => ({ ...s, step }));
10
- }, []);
11
- const setAddress = useCallback((address) => {
12
- setState((s) => ({ ...s, address, step: "shipping" }));
13
- }, []);
14
- const setShipping = useCallback((option) => {
15
- setState((s) => ({ ...s, shippingOption: option, step: "payment" }));
16
- }, []);
17
- const setPayment = useCallback((gateway) => {
18
- setState((s) => ({ ...s, paymentGateway: gateway, step: "review" }));
19
- }, []);
20
- const setCoupon = useCallback((code) => {
21
- setState((s) => ({ ...s, couponCode: code }));
22
- }, []);
23
- return { state, setStep, setAddress, setShipping, setPayment, setCoupon };
24
- }
@@ -1,72 +0,0 @@
1
- export interface AddressListResponse<TAddress = any> {
2
- data: TAddress[];
3
- }
4
- export interface CartApiResponse<TCart = any> {
5
- cart: TCart;
6
- itemCount: number;
7
- subtotal: number;
8
- }
9
- export interface PlaceOrderResponse {
10
- orderIds: string[];
11
- total: number;
12
- itemCount: number;
13
- unavailableItems?: UnavailableItem[];
14
- }
15
- export interface UnavailableItem {
16
- productId: string;
17
- productTitle: string;
18
- requestedQty: number;
19
- availableQty: number;
20
- }
21
- export interface PreflightResponse {
22
- available: any[];
23
- unavailable: UnavailableItem[];
24
- }
25
- export interface CreatePaymentOrderResponse {
26
- gatewayOrderId: string;
27
- amount: number;
28
- currency: string;
29
- keyId: string;
30
- platformFee?: number;
31
- }
32
- interface PlaceOrderPayload {
33
- addressId: string;
34
- paymentMethod: "cod" | "online" | "upi_manual";
35
- notes?: string;
36
- excludedProductIds?: string[];
37
- }
38
- interface CreatePaymentOrderPayload {
39
- amount: number;
40
- currency?: string;
41
- receipt?: string;
42
- }
43
- interface VerifyPaymentPayload {
44
- gateway_order_id: string;
45
- gateway_payment_id: string;
46
- gateway_signature: string;
47
- addressId: string;
48
- notes?: string;
49
- excludedProductIds?: string[];
50
- }
51
- interface UseCheckoutOptions<TAddress = any, TCart = any> {
52
- addressesEndpoint?: string;
53
- cartEndpoint?: string;
54
- preflightEndpoint?: string;
55
- placeOrderEndpoint?: string;
56
- paymentCreateOrderEndpoint?: string;
57
- paymentVerifyEndpoint?: string;
58
- onPlaceCodOrderSuccess?: (result: PlaceOrderResponse) => void;
59
- onPlaceCodOrderError?: () => void;
60
- enabled?: boolean;
61
- initialAddresses?: TAddress[];
62
- initialCart?: CartApiResponse<TCart>;
63
- }
64
- export declare function useCheckout<TAddress = any, TCart = any>(options?: UseCheckoutOptions<TAddress, TCart>): {
65
- addressQuery: import("@tanstack/react-query").UseQueryResult<TAddress[], Error>;
66
- cartQuery: import("@tanstack/react-query").UseQueryResult<CartApiResponse<TCart>, Error>;
67
- preflightMutation: import("@tanstack/react-query").UseMutationResult<PreflightResponse, Error, string, unknown>;
68
- placeCodOrderMutation: import("@tanstack/react-query").UseMutationResult<PlaceOrderResponse, Error, PlaceOrderPayload, unknown>;
69
- createPaymentOrderMutation: import("@tanstack/react-query").UseMutationResult<CreatePaymentOrderResponse, Error, CreatePaymentOrderPayload, unknown>;
70
- verifyPaymentMutation: import("@tanstack/react-query").UseMutationResult<PlaceOrderResponse, Error, VerifyPaymentPayload, unknown>;
71
- };
72
- export {};
@@ -1,47 +0,0 @@
1
- import { useMutation, useQueryClient } from "@tanstack/react-query";
2
- import { apiClient } from "../../../http";
3
- import { useCheckoutReadQueries } from "../../cart";
4
- import { ACCOUNT_ENDPOINTS, CART_ENDPOINTS, CHECKOUT_ENDPOINTS, PAYMENT_ENDPOINTS, } from "../../../constants/api-endpoints";
5
- export function useCheckout(options) {
6
- const queryClient = useQueryClient();
7
- const { addressesEndpoint = ACCOUNT_ENDPOINTS.ADDRESSES, cartEndpoint = CART_ENDPOINTS.GET, preflightEndpoint = CHECKOUT_ENDPOINTS.PREFLIGHT, placeOrderEndpoint = CHECKOUT_ENDPOINTS.PLACE_ORDER, paymentCreateOrderEndpoint = PAYMENT_ENDPOINTS.CREATE_ORDER, paymentVerifyEndpoint = PAYMENT_ENDPOINTS.VERIFY, } = options ?? {};
8
- const { addressQuery, cartQuery } = useCheckoutReadQueries({
9
- addressesEndpoint,
10
- cartEndpoint,
11
- addressesQueryKey: ["addresses"],
12
- cartQueryKey: ["cart"],
13
- enabled: options?.enabled,
14
- initialAddresses: options?.initialAddresses,
15
- initialCart: options?.initialCart,
16
- });
17
- const preflightMutation = useMutation({
18
- mutationFn: (addressId) => apiClient.post(preflightEndpoint, { addressId }),
19
- });
20
- const placeCodOrderMutation = useMutation({
21
- mutationFn: (data) => apiClient.post(placeOrderEndpoint, data),
22
- onSuccess: async (result) => {
23
- await queryClient.invalidateQueries({ queryKey: ["cart"] });
24
- await queryClient.invalidateQueries({ queryKey: ["orders"] });
25
- options?.onPlaceCodOrderSuccess?.(result);
26
- },
27
- onError: options?.onPlaceCodOrderError,
28
- });
29
- const createPaymentOrderMutation = useMutation({
30
- mutationFn: (data) => apiClient.post(paymentCreateOrderEndpoint, data),
31
- });
32
- const verifyPaymentMutation = useMutation({
33
- mutationFn: (data) => apiClient.post(paymentVerifyEndpoint, data),
34
- onSuccess: async () => {
35
- await queryClient.invalidateQueries({ queryKey: ["cart"] });
36
- await queryClient.invalidateQueries({ queryKey: ["orders"] });
37
- },
38
- });
39
- return {
40
- addressQuery,
41
- cartQuery,
42
- preflightMutation,
43
- placeCodOrderMutation,
44
- createPaymentOrderMutation,
45
- verifyPaymentMutation,
46
- };
47
- }
@@ -1,77 +0,0 @@
1
- import type { IClientPaymentGateway, OpenGatewayOptions } from "../../../contracts/client-payment-gateway";
2
- import type { PlaceOrderResponse } from "../hooks/useCheckoutApi";
3
- import { useCheckout as useCheckoutApi } from "../hooks/useCheckoutApi";
4
- import { usePaymentEvent, type UsePaymentEventOptions } from "../../payments/hooks/usePaymentEvent";
5
- import type { PaymentGateway } from "../../payments/schemas";
6
- export type PaymentCheckoutStep = "idle" | "preflight" | "creating_order" | "awaiting_payment" | "verifying" | "success" | "error" | "cancelled";
7
- export interface PaymentCheckoutState {
8
- step: PaymentCheckoutStep;
9
- error: string | null;
10
- orderIds: string[] | null;
11
- total: number | null;
12
- itemCount: number | null;
13
- }
14
- export interface UsePaymentCheckoutOptions {
15
- /** Payment gateway to use. Consumer registers the adapter via `registerClientPaymentGateway`. */
16
- gateway: PaymentGateway;
17
- /** Override the gateway adapter instance (skips registry lookup). */
18
- gatewayAdapter?: IClientPaymentGateway;
19
- /** Merchant display name for the payment modal. */
20
- merchantName?: string;
21
- /** Logo URL for the payment modal. */
22
- logoUrl?: string;
23
- /** Theme color for the payment modal. */
24
- themeColor?: string;
25
- /** Realtime event options for tracking payment completion via RTDB. */
26
- realtimeEventOptions?: UsePaymentEventOptions;
27
- /** Custom API endpoints (passed to useCheckoutApi). */
28
- endpoints?: {
29
- addresses?: string;
30
- cart?: string;
31
- preflight?: string;
32
- placeOrder?: string;
33
- paymentCreateOrder?: string;
34
- paymentVerify?: string;
35
- };
36
- /** Called after successful order placement (COD or online). */
37
- onSuccess?: (result: PlaceOrderResponse) => void;
38
- /** Called on any checkout error. */
39
- onError?: (error: Error) => void;
40
- /** Called when user cancels payment modal. */
41
- onCancel?: () => void;
42
- }
43
- export interface UsePaymentCheckoutReturn {
44
- /** Current checkout step/state. */
45
- state: PaymentCheckoutState;
46
- /** Address and cart query results from useCheckoutApi. */
47
- addressQuery: ReturnType<typeof useCheckoutApi>["addressQuery"];
48
- cartQuery: ReturnType<typeof useCheckoutApi>["cartQuery"];
49
- /** Run preflight stock check. */
50
- preflight: (addressId: string) => Promise<boolean>;
51
- /** Place a COD / UPI-manual order (no gateway interaction). */
52
- placeCodOrder: (params: {
53
- addressId: string;
54
- paymentMethod: "cod" | "upi_manual";
55
- notes?: string;
56
- excludedProductIds?: string[];
57
- }) => Promise<PlaceOrderResponse | null>;
58
- /**
59
- * Full online payment flow:
60
- * 1. Create payment order on server
61
- * 2. Open gateway modal
62
- * 3. Verify payment on server
63
- */
64
- payOnline: (params: {
65
- addressId: string;
66
- amount: number;
67
- currency?: string;
68
- notes?: string;
69
- excludedProductIds?: string[];
70
- prefill?: OpenGatewayOptions["prefill"];
71
- }) => Promise<PlaceOrderResponse | null>;
72
- /** Payment event tracking (RTDB). */
73
- paymentEvent: ReturnType<typeof usePaymentEvent>;
74
- /** Reset checkout state back to idle. */
75
- reset: () => void;
76
- }
77
- export declare function usePaymentCheckout(options: UsePaymentCheckoutOptions): UsePaymentCheckoutReturn;
@@ -1,192 +0,0 @@
1
- "use client";
2
- import { normalizeError } from "../../../errors/normalize";
3
- import { useCallback, useRef, useState } from "react";
4
- import { getClientPaymentGateway } from "../../../contracts/client-payment-gateway";
5
- import { useCheckout as useCheckoutApi } from "../hooks/useCheckoutApi";
6
- import { usePaymentEvent, } from "../../payments/hooks/usePaymentEvent";
7
- // --- Helpers ---------------------------------------------------------------
8
- async function openGatewayStep(adapter, orderResponse, params) {
9
- try {
10
- await adapter.loadScript();
11
- const response = await adapter.openPayment({
12
- gatewayOrderId: orderResponse.gatewayOrderId,
13
- publicKey: orderResponse.keyId,
14
- amount: orderResponse.amount,
15
- currency: orderResponse.currency,
16
- merchantName: params.merchantName,
17
- logoUrl: params.logoUrl,
18
- prefill: params.prefill,
19
- theme: params.themeColor ? { color: params.themeColor } : undefined,
20
- });
21
- return { response, cancelled: false, error: null };
22
- }
23
- catch (err) {
24
- void normalizeError(err);
25
- if (err instanceof Error && err.message.toLowerCase().includes("cancel")) {
26
- return { response: null, cancelled: true, error: null };
27
- }
28
- return { response: null, cancelled: false, error: err instanceof Error ? err : new Error("Payment gateway error") };
29
- }
30
- }
31
- // --- Hook ------------------------------------------------------------------
32
- const INITIAL_STATE = {
33
- step: "idle",
34
- error: null,
35
- orderIds: null,
36
- total: null,
37
- itemCount: null,
38
- };
39
- export function usePaymentCheckout(options) {
40
- const [state, setState] = useState(INITIAL_STATE);
41
- const abortRef = useRef(false);
42
- const { gateway, gatewayAdapter, merchantName, logoUrl, themeColor, endpoints, onSuccess, onError, onCancel, } = options;
43
- const checkout = useCheckoutApi({
44
- addressesEndpoint: endpoints?.addresses,
45
- cartEndpoint: endpoints?.cart,
46
- preflightEndpoint: endpoints?.preflight,
47
- placeOrderEndpoint: endpoints?.placeOrder,
48
- paymentCreateOrderEndpoint: endpoints?.paymentCreateOrder,
49
- paymentVerifyEndpoint: endpoints?.paymentVerify,
50
- });
51
- const paymentEvent = usePaymentEvent(options.realtimeEventOptions);
52
- const getAdapter = useCallback(() => {
53
- return gatewayAdapter ?? getClientPaymentGateway(gateway);
54
- }, [gateway, gatewayAdapter]);
55
- const setError = useCallback((error) => {
56
- setState((s) => ({ ...s, step: "error", error: error.message }));
57
- onError?.(error);
58
- }, [onError]);
59
- const reset = useCallback(() => {
60
- setState(INITIAL_STATE);
61
- abortRef.current = false;
62
- paymentEvent.reset();
63
- }, [paymentEvent]);
64
- const preflight = useCallback(async (addressId) => {
65
- setState((s) => ({ ...s, step: "preflight", error: null }));
66
- try {
67
- const result = await checkout.preflightMutation.mutateAsync(addressId);
68
- if (result.unavailable.length > 0) {
69
- setState((s) => ({
70
- ...s,
71
- step: "error",
72
- error: `${result.unavailable.length} item(s) unavailable`,
73
- }));
74
- return false;
75
- }
76
- setState((s) => ({ ...s, step: "idle" }));
77
- return true;
78
- }
79
- catch (err) {
80
- void normalizeError(err);
81
- setError(err instanceof Error ? err : new Error("Preflight check failed"));
82
- return false;
83
- }
84
- }, [checkout.preflightMutation, setError]);
85
- const placeCodOrder = useCallback(async (params) => {
86
- setState((s) => ({ ...s, step: "verifying", error: null }));
87
- try {
88
- const result = await checkout.placeCodOrderMutation.mutateAsync({
89
- addressId: params.addressId,
90
- paymentMethod: params.paymentMethod,
91
- notes: params.notes,
92
- excludedProductIds: params.excludedProductIds,
93
- });
94
- setState({
95
- step: "success",
96
- error: null,
97
- orderIds: result.orderIds,
98
- total: result.total,
99
- itemCount: result.itemCount,
100
- });
101
- onSuccess?.(result);
102
- return result;
103
- }
104
- catch (err) {
105
- void normalizeError(err);
106
- setError(err instanceof Error ? err : new Error("Order placement failed"));
107
- return null;
108
- }
109
- }, [checkout.placeCodOrderMutation, onSuccess, setError]);
110
- const payOnline = useCallback(async (params) => {
111
- abortRef.current = false;
112
- // Step 1: Create payment order on server
113
- setState((s) => ({ ...s, step: "creating_order", error: null }));
114
- let orderResponse;
115
- try {
116
- orderResponse = await checkout.createPaymentOrderMutation.mutateAsync({
117
- amount: params.amount,
118
- currency: params.currency,
119
- });
120
- }
121
- catch (err) {
122
- void normalizeError(err);
123
- setError(err instanceof Error
124
- ? err
125
- : new Error("Failed to create payment order"));
126
- return null;
127
- }
128
- if (abortRef.current)
129
- return null;
130
- // Step 2: Open gateway modal
131
- setState((s) => ({ ...s, step: "awaiting_payment" }));
132
- const gatewayResult = await openGatewayStep(getAdapter(), orderResponse, { prefill: params.prefill, merchantName, logoUrl, themeColor });
133
- if (gatewayResult.cancelled) {
134
- setState((s) => ({ ...s, step: "cancelled", error: null }));
135
- onCancel?.();
136
- return null;
137
- }
138
- if (gatewayResult.error || !gatewayResult.response) {
139
- setError(gatewayResult.error ?? new Error("Payment gateway error"));
140
- return null;
141
- }
142
- const gatewayResponse = gatewayResult.response;
143
- if (abortRef.current)
144
- return null;
145
- // Step 3: Verify payment on server
146
- setState((s) => ({ ...s, step: "verifying" }));
147
- try {
148
- const result = await checkout.verifyPaymentMutation.mutateAsync({
149
- gateway_order_id: gatewayResponse.gatewayOrderId,
150
- gateway_payment_id: gatewayResponse.gatewayPaymentId,
151
- gateway_signature: gatewayResponse.gatewaySignature ?? "",
152
- addressId: params.addressId,
153
- notes: params.notes,
154
- excludedProductIds: params.excludedProductIds,
155
- });
156
- setState({
157
- step: "success",
158
- error: null,
159
- orderIds: result.orderIds,
160
- total: result.total,
161
- itemCount: result.itemCount,
162
- });
163
- onSuccess?.(result);
164
- return result;
165
- }
166
- catch (err) {
167
- void normalizeError(err);
168
- setError(err instanceof Error ? err : new Error("Payment verification failed"));
169
- return null;
170
- }
171
- }, [
172
- checkout.createPaymentOrderMutation,
173
- checkout.verifyPaymentMutation,
174
- getAdapter,
175
- merchantName,
176
- logoUrl,
177
- themeColor,
178
- onSuccess,
179
- onCancel,
180
- setError,
181
- ]);
182
- return {
183
- state,
184
- addressQuery: checkout.addressQuery,
185
- cartQuery: checkout.cartQuery,
186
- preflight,
187
- placeCodOrder,
188
- payOnline,
189
- paymentEvent,
190
- reset,
191
- };
192
- }
@@ -1,115 +0,0 @@
1
- /**
2
- * @mohasinac/payment-razorpay — Razorpay IPaymentProvider implementation
3
- *
4
- * Implements the @mohasinac/contracts IPaymentProvider interface.
5
- * Accepts credentials via constructor — no Firestore or DB dependency.
6
- *
7
- * @example
8
- * ```ts
9
- * import { RazorpayProvider } from "@mohasinac/payment-razorpay";
10
- * import { registerProviders } from "../../contracts";
11
- *
12
- * registerProviders({
13
- * payment: new RazorpayProvider({
14
- * keyId: process.env.RAZORPAY_KEY_ID!,
15
- * keySecret: process.env.RAZORPAY_KEY_SECRET!,
16
- * webhookSecret: process.env.RAZORPAY_WEBHOOK_SECRET,
17
- * }),
18
- * });
19
- * ```
20
- */
21
- import type { JsonValue } from "@mohasinac/appkit";
22
- import { IPaymentProvider } from "../../contracts";
23
- import type { PaymentOrder, PaymentCapture, Refund } from "../../contracts";
24
- export interface RazorpayConfig {
25
- keyId: string;
26
- keySecret: string;
27
- webhookSecret?: string;
28
- }
29
- export declare class RazorpayProvider extends IPaymentProvider {
30
- readonly name = "razorpay";
31
- private readonly razorpay;
32
- private readonly webhookSecret?;
33
- constructor(config: RazorpayConfig);
34
- createOrder(amount: number, currency?: string, metadata?: Record<string, JsonValue>): Promise<PaymentOrder>;
35
- /**
36
- * Verify Razorpay webhook signature (HMAC-SHA256 over raw body).
37
- * Requires webhookSecret to be set in the constructor.
38
- */
39
- verifyWebhook(payload: string, signature: string): boolean;
40
- capturePayment(paymentId: string): Promise<PaymentCapture>;
41
- refund(paymentId: string, amount?: number): Promise<Refund>;
42
- getOrder(orderId: string): Promise<PaymentOrder>;
43
- }
44
- /** Convert rupees (float) → paise (integer) for Razorpay amount field */
45
- export declare function rupeesToPaise(rupees: number): number;
46
- /** Convert paise (integer) → rupees (float) */
47
- export declare function paiseToRupees(paise: number): number;
48
- export interface RazorpayPaymentResult {
49
- razorpay_order_id: string;
50
- razorpay_payment_id: string;
51
- razorpay_signature: string;
52
- }
53
- /**
54
- * Verify Razorpay payment signature.
55
- * Uses HMAC-SHA256 over `{orderId}|{paymentId}` with the key secret.
56
- */
57
- export declare function verifyPaymentSignature(params: RazorpayPaymentResult, keySecret: string): boolean;
58
- export interface RazorpayOrderOptions {
59
- /** Amount in paise (smallest currency unit). E.g. ₹500 → 50000 */
60
- amount: number;
61
- currency?: string;
62
- receipt?: string;
63
- notes?: Record<string, string>;
64
- }
65
- export interface RazorpayOrder {
66
- id: string;
67
- entity: string;
68
- amount: number;
69
- amount_paid: number;
70
- amount_due: number;
71
- currency: string;
72
- receipt: string | null;
73
- status: string;
74
- attempts: number;
75
- created_at: number;
76
- }
77
- export interface RazorpayRefundResult {
78
- id: string;
79
- payment_id: string;
80
- amount: number;
81
- currency: string;
82
- status: string;
83
- }
84
- /**
85
- * Create a Razorpay order. Credentials resolved from Firestore → env.
86
- * @deprecated Use `getProviders().payment.createOrder()` via `IPaymentProvider` instead.
87
- * @internal Will be removed in a future version.
88
- */
89
- export declare function createRazorpayOrder(opts: RazorpayOrderOptions): Promise<RazorpayOrder>;
90
- /**
91
- * Fetch an existing Razorpay order by ID.
92
- * @deprecated Use `getProviders().payment.getOrder()` via `IPaymentProvider` instead.
93
- * @internal Will be removed in a future version.
94
- */
95
- export declare function fetchRazorpayOrder(orderId: string): Promise<RazorpayOrder>;
96
- /**
97
- * Verify Razorpay payment signature — auto-resolves key secret.
98
- * Returns false if credentials are unavailable.
99
- * @deprecated Use `getProviders().payment.verifyWebhook()` via `IPaymentProvider` instead.
100
- * @internal Will be removed in a future version.
101
- */
102
- export declare function verifyPaymentSignatureWithKeys(params: RazorpayPaymentResult): Promise<boolean>;
103
- /**
104
- * Verify Razorpay webhook signature — auto-resolves webhook secret.
105
- * Uses HMAC-SHA256 over raw body.
106
- * @deprecated Use `getProviders().payment.verifyWebhook()` via `IPaymentProvider` instead.
107
- * @internal Will be removed in a future version.
108
- */
109
- export declare function verifyWebhookSignature(rawBody: string, receivedSignature: string): Promise<boolean>;
110
- /**
111
- * Create a full or partial refund for a Razorpay payment.
112
- * @deprecated Use `getProviders().payment.refund()` via `IPaymentProvider` instead.
113
- * @internal Will be removed in a future version.
114
- */
115
- export declare function createRazorpayRefund(paymentId: string, amountPaise?: number): Promise<RazorpayRefundResult>;