@zezosoft/react-native-zezopay 1.0.2 → 1.0.3
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 +4 -4
- package/lib/module/ZezoPay/ZezoPay.js +41 -27
- package/lib/module/ZezoPay/ZezoPay.js.map +1 -1
- package/lib/module/ZezoPay/components/PaymentMethod.js.map +1 -1
- package/lib/module/ZezoPay/components/Summary.js.map +1 -1
- package/lib/module/ZezoPay/components/VoucherBox.js +76 -27
- package/lib/module/ZezoPay/components/VoucherBox.js.map +1 -1
- package/lib/module/ZezoPay/http/api-sdk.js +14 -0
- package/lib/module/ZezoPay/http/api-sdk.js.map +1 -0
- package/lib/module/ZezoPay/http/services/baseService.js +28 -0
- package/lib/module/ZezoPay/http/services/baseService.js.map +1 -0
- package/lib/module/ZezoPay/http/services/payments/payments.js +51 -0
- package/lib/module/ZezoPay/http/services/payments/payments.js.map +1 -0
- package/lib/module/ZezoPay/http/services/payments/payments.types.js +2 -0
- package/lib/module/ZezoPay/http/services/payments/payments.types.js.map +1 -0
- package/lib/module/ZezoPay/http/utils/errorFormatter.js +49 -0
- package/lib/module/ZezoPay/http/utils/errorFormatter.js.map +1 -0
- package/lib/module/ZezoPay/utils/hooks/useZezoPay.js +187 -203
- package/lib/module/ZezoPay/utils/hooks/useZezoPay.js.map +1 -1
- package/lib/typescript/src/ZezoPay/ZezoPay.d.ts.map +1 -1
- package/lib/typescript/src/ZezoPay/components/PaymentMethod.d.ts +2 -2
- package/lib/typescript/src/ZezoPay/components/PaymentMethod.d.ts.map +1 -1
- package/lib/typescript/src/ZezoPay/components/Summary.d.ts +1 -1
- package/lib/typescript/src/ZezoPay/components/Summary.d.ts.map +1 -1
- package/lib/typescript/src/ZezoPay/components/VoucherBox.d.ts +6 -3
- package/lib/typescript/src/ZezoPay/components/VoucherBox.d.ts.map +1 -1
- package/lib/typescript/src/ZezoPay/http/api-sdk.d.ts +21 -0
- package/lib/typescript/src/ZezoPay/http/api-sdk.d.ts.map +1 -0
- package/lib/typescript/src/ZezoPay/http/services/baseService.d.ts +9 -0
- package/lib/typescript/src/ZezoPay/http/services/baseService.d.ts.map +1 -0
- package/lib/typescript/src/ZezoPay/http/services/payments/payments.d.ts +25 -0
- package/lib/typescript/src/ZezoPay/http/services/payments/payments.d.ts.map +1 -0
- package/lib/typescript/src/ZezoPay/http/services/payments/payments.types.d.ts +100 -0
- package/lib/typescript/src/ZezoPay/http/services/payments/payments.types.d.ts.map +1 -0
- package/lib/typescript/src/ZezoPay/http/utils/errorFormatter.d.ts +6 -0
- package/lib/typescript/src/ZezoPay/http/utils/errorFormatter.d.ts.map +1 -0
- package/lib/typescript/src/ZezoPay/types/index.d.ts +27 -6
- package/lib/typescript/src/ZezoPay/types/index.d.ts.map +1 -1
- package/lib/typescript/src/ZezoPay/utils/hooks/useZezoPay.d.ts +23 -29
- package/lib/typescript/src/ZezoPay/utils/hooks/useZezoPay.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/ZezoPay/ZezoPay.tsx +49 -28
- package/src/ZezoPay/components/PaymentMethod.tsx +4 -4
- package/src/ZezoPay/components/Summary.tsx +1 -1
- package/src/ZezoPay/components/VoucherBox.tsx +100 -51
- package/src/ZezoPay/http/api-sdk.ts +27 -0
- package/src/ZezoPay/http/services/baseService.ts +37 -0
- package/src/ZezoPay/http/services/payments/payments.ts +66 -0
- package/src/ZezoPay/http/services/payments/payments.types.ts +120 -0
- package/src/ZezoPay/http/utils/errorFormatter.ts +88 -0
- package/src/ZezoPay/types/index.ts +41 -7
- package/src/ZezoPay/utils/hooks/useZezoPay.ts +234 -231
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import PaymentService from './services/payments/payments';
|
|
2
|
+
export interface IOptions {
|
|
3
|
+
publicKey: string;
|
|
4
|
+
}
|
|
5
|
+
export interface APIError {
|
|
6
|
+
type: string;
|
|
7
|
+
status?: number | string;
|
|
8
|
+
message: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
location?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class ZezoPayClient {
|
|
13
|
+
payments: PaymentService;
|
|
14
|
+
/**
|
|
15
|
+
* Constructor for the ZezoPay class.
|
|
16
|
+
* @param options
|
|
17
|
+
*/
|
|
18
|
+
constructor(options: IOptions);
|
|
19
|
+
}
|
|
20
|
+
export * from './services/payments/payments.types';
|
|
21
|
+
//# sourceMappingURL=api-sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-sdk.d.ts","sourceRoot":"","sources":["../../../../../src/ZezoPay/http/api-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,8BAA8B,CAAC;AAE1D,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,aAAa;IACxB,QAAQ,EAAE,cAAc,CAAC;IAEzB;;;OAGG;gBACS,OAAO,EAAE,QAAQ;CAG9B;AAED,cAAc,oCAAoC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios';
|
|
2
|
+
import type { IOptions } from '../api-sdk';
|
|
3
|
+
declare class BaseService {
|
|
4
|
+
protected client: AxiosInstance;
|
|
5
|
+
constructor(options: IOptions);
|
|
6
|
+
protected request<T = any>(config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
|
7
|
+
}
|
|
8
|
+
export default BaseService;
|
|
9
|
+
//# sourceMappingURL=baseService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseService.d.ts","sourceRoot":"","sources":["../../../../../../src/ZezoPay/http/services/baseService.ts"],"names":[],"mappings":"AAAA,OAAc,EACZ,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAY,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGrD,cAAM,WAAW;IACf,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC;gBAEpB,OAAO,EAAE,QAAQ;cAYb,OAAO,CAAC,CAAC,GAAG,GAAG,EAC7B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;CAS7B;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
|
2
|
+
import type { ICheckoutPayload, ICheckoutResult, ICouponResponse, IOptions, PaymentProviderList } from '../../api-sdk';
|
|
3
|
+
import BaseService from '../baseService';
|
|
4
|
+
declare class PaymentService extends BaseService {
|
|
5
|
+
constructor(options: IOptions);
|
|
6
|
+
/**
|
|
7
|
+
* Get available payment providers
|
|
8
|
+
*/
|
|
9
|
+
providers({ platform, }?: {
|
|
10
|
+
platform?: 'web' | 'ios' | 'android';
|
|
11
|
+
}): Promise<AxiosResponse<PaymentProviderList>>;
|
|
12
|
+
/**
|
|
13
|
+
* Create a checkout session
|
|
14
|
+
*/
|
|
15
|
+
checkout(payload: ICheckoutPayload, platform?: 'web' | 'ios' | 'android'): Promise<AxiosResponse<ICheckoutResult>>;
|
|
16
|
+
/**
|
|
17
|
+
* Verify a coupon
|
|
18
|
+
*/
|
|
19
|
+
verifyCoupon(payload: {
|
|
20
|
+
code: string;
|
|
21
|
+
userId: string;
|
|
22
|
+
}): Promise<AxiosResponse<ICouponResponse>>;
|
|
23
|
+
}
|
|
24
|
+
export default PaymentService;
|
|
25
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../../../../../../src/ZezoPay/http/services/payments/payments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,QAAQ,EACR,mBAAmB,EACpB,MAAM,eAAe,CAAC;AACvB,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAEzC,cAAM,cAAe,SAAQ,WAAW;gBAC1B,OAAO,EAAE,QAAQ;IAI7B;;OAEG;IACG,SAAS,CAAC,EACd,QAAgB,GACjB,GAAE;QACD,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;KACjC,GAAG,OAAO,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;IAUpD;;OAEG;IACG,QAAQ,CACZ,OAAO,EAAE,gBAAgB,EACzB,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,GACnC,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IAU1C;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;CAS5C;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported payment providers
|
|
3
|
+
*/
|
|
4
|
+
export type PaymentProvider = 'stripe' | 'razorpay' | 'phonepe' | 'ccavenue' | string;
|
|
5
|
+
/**
|
|
6
|
+
* Payment provider info used in UI
|
|
7
|
+
*/
|
|
8
|
+
export interface IReadyPaymentProvider {
|
|
9
|
+
logo: string;
|
|
10
|
+
provider: PaymentProvider;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Basic user info attached to payments
|
|
14
|
+
*/
|
|
15
|
+
export interface UserInfo {
|
|
16
|
+
_id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
email?: string;
|
|
19
|
+
phone?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extra metadata for payments
|
|
23
|
+
*/
|
|
24
|
+
export interface PaymentMeta {
|
|
25
|
+
isPaymentInitiatedEnabled?: boolean;
|
|
26
|
+
userInfo: UserInfo;
|
|
27
|
+
summary?: Record<string, any>;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Base checkout input shared across types
|
|
32
|
+
*/
|
|
33
|
+
export interface BaseCheckoutInput {
|
|
34
|
+
userId: string;
|
|
35
|
+
provider: PaymentProvider;
|
|
36
|
+
metadata: PaymentMeta;
|
|
37
|
+
currency?: string;
|
|
38
|
+
coupon_code?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checkout payload variations
|
|
42
|
+
*/
|
|
43
|
+
export type ICheckoutPayload = (BaseCheckoutInput & {
|
|
44
|
+
type: 'normal';
|
|
45
|
+
price: number;
|
|
46
|
+
}) | (BaseCheckoutInput & {
|
|
47
|
+
type: 'subscription';
|
|
48
|
+
subscriptionId: string;
|
|
49
|
+
}) | (BaseCheckoutInput & {
|
|
50
|
+
type: 'digital-product';
|
|
51
|
+
digitalProductId: string;
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Checkout API response
|
|
55
|
+
*/
|
|
56
|
+
export interface ICheckoutResult {
|
|
57
|
+
status: boolean;
|
|
58
|
+
price: number;
|
|
59
|
+
currency: 'INR' | 'USD' | 'EUR' | 'GBP' | 'JPY' | 'AUD' | 'CAD' | 'CNY' | 'SGD' | string;
|
|
60
|
+
provider: PaymentProvider;
|
|
61
|
+
real_price: number;
|
|
62
|
+
orderId: string;
|
|
63
|
+
publicKey: string;
|
|
64
|
+
extraData?: Record<string, any>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Verification of payment status
|
|
68
|
+
*/
|
|
69
|
+
export interface IPaymentVerify {
|
|
70
|
+
_id: string;
|
|
71
|
+
userId: string;
|
|
72
|
+
orderId: string;
|
|
73
|
+
status: 'success' | 'failed' | 'pending';
|
|
74
|
+
meta_data: PaymentMeta;
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
}
|
|
77
|
+
export interface IPaymentVerification {
|
|
78
|
+
message: string;
|
|
79
|
+
data: IPaymentVerify;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* List of supported providers
|
|
83
|
+
*/
|
|
84
|
+
export type PaymentProviderList = IReadyPaymentProvider[];
|
|
85
|
+
export interface ICouponValidity {
|
|
86
|
+
start_date: string;
|
|
87
|
+
end_date: string;
|
|
88
|
+
}
|
|
89
|
+
export interface ICouponData {
|
|
90
|
+
_id: string;
|
|
91
|
+
name: string;
|
|
92
|
+
discount: number;
|
|
93
|
+
type: 'percentage' | 'amount';
|
|
94
|
+
validity: ICouponValidity;
|
|
95
|
+
}
|
|
96
|
+
export interface ICouponResponse {
|
|
97
|
+
message: string;
|
|
98
|
+
data: ICouponData;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=payments.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.types.d.ts","sourceRoot":"","sources":["../../../../../../../src/ZezoPay/http/services/payments/payments.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,UAAU,GACV,SAAS,GACT,UAAU,GACV,MAAM,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;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;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;IACzC,SAAS,EAAE,WAAW,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,cAAc,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,qBAAqB,EAAE,CAAC;AAE1D,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC9B,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,WAAW,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorFormatter.d.ts","sourceRoot":"","sources":["../../../../../../src/ZezoPay/http/utils/errorFormatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA6B3C;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,CAqDrD"}
|
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ICheckoutResult, PaymentMeta, PaymentProvider, UserInfo } from '../http/api-sdk';
|
|
2
|
+
export interface ISummaryItem {
|
|
3
|
+
id: string | number;
|
|
4
|
+
name: string;
|
|
5
|
+
price: number;
|
|
6
|
+
duration?: string;
|
|
7
|
+
image?: string;
|
|
8
|
+
discount?: number | {
|
|
9
|
+
amount: number;
|
|
10
|
+
type: 'percentage' | 'fixed';
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export type HandlePayment = ({ provider, subscriptionId, digitalProductId, userInfo, coupon_code, metadata, }: {
|
|
14
|
+
provider: PaymentProvider;
|
|
15
|
+
subscriptionId?: string | null;
|
|
16
|
+
digitalProductId?: string | null;
|
|
17
|
+
userInfo: UserInfo;
|
|
18
|
+
coupon_code?: string | null;
|
|
19
|
+
metadata?: PaymentMeta | null;
|
|
20
|
+
}) => Promise<ICheckoutResult | null>;
|
|
21
|
+
export interface ZezoPayCallbacks {
|
|
22
|
+
onSuccess?: (response: any) => void;
|
|
23
|
+
onFailure?: (error: any) => void;
|
|
24
|
+
onError?: (error: any) => void;
|
|
25
|
+
}
|
|
2
26
|
export type PaymentDetails = {
|
|
3
27
|
userId: string;
|
|
4
28
|
price: number;
|
|
@@ -15,12 +39,9 @@ export type ZezoPayProps = {
|
|
|
15
39
|
userInfo: UserInfo;
|
|
16
40
|
title: string;
|
|
17
41
|
onBack: () => void;
|
|
18
|
-
|
|
42
|
+
callbacks?: ZezoPayCallbacks;
|
|
19
43
|
handlePayment?: HandlePayment;
|
|
20
|
-
|
|
21
|
-
export type ZezoPayCallbacks = {
|
|
22
|
-
onSuccess?: (data: any) => void;
|
|
23
|
-
onFailure?: (error: any) => void;
|
|
44
|
+
voucher?: boolean;
|
|
24
45
|
};
|
|
25
46
|
export type PaymentProviderType = 'razorpay' | 'stripe' | 'ccavenue' | 'phonepe';
|
|
26
47
|
export type ZezoPayHookProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ZezoPay/types/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ZezoPay/types/index.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C,EAAE,WAAW,EAAE,CAAC;IAC7B,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/C,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
|
@@ -1,46 +1,40 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Parameters for the useZezoPay hook
|
|
6
|
-
* @interface UseZezoPayParams
|
|
7
|
-
*/
|
|
2
|
+
import { type PaymentProvider, type IReadyPaymentProvider } from '../../http/api-sdk';
|
|
3
|
+
import type { HandlePayment, ISummaryItem, ZezoPayCallbacks } from '../../types';
|
|
4
|
+
export declare const SUPPORTED_PROVIDERS: PaymentProvider[];
|
|
8
5
|
interface UseZezoPayParams {
|
|
9
6
|
publicKey: string;
|
|
10
|
-
|
|
7
|
+
user: {
|
|
11
8
|
_id: string;
|
|
12
9
|
name: string;
|
|
13
10
|
email?: string;
|
|
14
11
|
phone?: string;
|
|
15
12
|
};
|
|
16
13
|
subscriptionId?: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
productId?: string;
|
|
15
|
+
cart?: ISummaryItem[];
|
|
16
|
+
paymentHandler?: HandlePayment;
|
|
17
|
+
callbacks?: ZezoPayCallbacks;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
voucherCode: string;
|
|
35
|
-
setVoucherCode: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
36
|
-
isProcessing: boolean;
|
|
37
|
-
isSuccess: boolean;
|
|
19
|
+
export declare const useZezoPay: ({ publicKey, user, subscriptionId, productId, cart: initialCart, paymentHandler: customHandler, callbacks, }: UseZezoPayParams) => {
|
|
20
|
+
provider: string | null;
|
|
21
|
+
setProvider: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
22
|
+
cartItems: ISummaryItem[];
|
|
23
|
+
setCartItems: import("react").Dispatch<import("react").SetStateAction<ISummaryItem[]>>;
|
|
24
|
+
totalAmount: number;
|
|
25
|
+
coupon: string;
|
|
26
|
+
setCoupon: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
27
|
+
couponLoading: boolean;
|
|
28
|
+
removeCoupon: () => void;
|
|
29
|
+
loadingPayment: boolean;
|
|
30
|
+
success: boolean;
|
|
38
31
|
error: string;
|
|
39
32
|
providers: IReadyPaymentProvider[];
|
|
40
33
|
loading: boolean;
|
|
41
|
-
|
|
34
|
+
providersError: Error | null;
|
|
42
35
|
removeItem: (id: string | number) => void;
|
|
43
|
-
|
|
36
|
+
payNow: () => Promise<void>;
|
|
37
|
+
applyCoupon: (code: string) => Promise<void>;
|
|
44
38
|
};
|
|
45
39
|
export {};
|
|
46
40
|
//# sourceMappingURL=useZezoPay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useZezoPay.d.ts","sourceRoot":"","sources":["../../../../../../src/ZezoPay/utils/hooks/useZezoPay.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,KAAK,
|
|
1
|
+
{"version":3,"file":"useZezoPay.d.ts","sourceRoot":"","sources":["../../../../../../src/ZezoPay/utils/hooks/useZezoPay.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAG3B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,mBAAmB,EAAE,eAAe,EAAiB,CAAC;AAEnE,UAAU,gBAAgB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACpE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC;IACtB,cAAc,CAAC,EAAE,aAAa,CAAC;IAC/B,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,eAAO,MAAM,UAAU,iHAQpB,gBAAgB;;;;;;;;;;;;;;;;qBA+DV,MAAM,GAAG,MAAM;;wBA0GP,MAAM;CAmHtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zezosoft/react-native-zezopay",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A React Native library for integrating ZezoPay payment gateway seamlessly in iOS and Android apps.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -170,8 +170,7 @@
|
|
|
170
170
|
"version": "0.52.1"
|
|
171
171
|
},
|
|
172
172
|
"dependencies": {
|
|
173
|
-
"
|
|
174
|
-
"axios": "^1.11.0",
|
|
173
|
+
"axios": "^1.12.2",
|
|
175
174
|
"lucide-react-native": "^0.542.0",
|
|
176
175
|
"qs": "^6.14.0",
|
|
177
176
|
"react-native-keyboard-aware-scroll-view": "^0.9.5",
|
package/src/ZezoPay/ZezoPay.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import { Summary } from './components/Summary';
|
|
|
18
18
|
import PayButton from './components/PayButton';
|
|
19
19
|
import { useZezoPay } from './utils/hooks/useZezoPay';
|
|
20
20
|
import { formatCurrency } from './utils';
|
|
21
|
+
import VoucherBox from './components/VoucherBox';
|
|
21
22
|
|
|
22
23
|
const ZezoPay: React.FC<ZezoPayProps> = ({
|
|
23
24
|
title = 'Payments',
|
|
@@ -27,34 +28,40 @@ const ZezoPay: React.FC<ZezoPayProps> = ({
|
|
|
27
28
|
publicKey,
|
|
28
29
|
digitalProductId,
|
|
29
30
|
subscriptionId,
|
|
30
|
-
|
|
31
|
+
callbacks,
|
|
31
32
|
handlePayment,
|
|
33
|
+
voucher = true,
|
|
32
34
|
}) => {
|
|
33
35
|
const {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
provider,
|
|
37
|
+
setProvider,
|
|
38
|
+
cartItems,
|
|
39
|
+
totalAmount,
|
|
40
|
+
success,
|
|
39
41
|
error,
|
|
40
|
-
|
|
42
|
+
loadingPayment,
|
|
41
43
|
providers,
|
|
42
|
-
loading,
|
|
43
|
-
|
|
44
|
+
loading: providersLoading,
|
|
45
|
+
providersError,
|
|
44
46
|
removeItem,
|
|
45
|
-
|
|
47
|
+
payNow,
|
|
48
|
+
applyCoupon,
|
|
49
|
+
coupon,
|
|
50
|
+
couponLoading,
|
|
51
|
+
removeCoupon,
|
|
46
52
|
} = useZezoPay({
|
|
47
|
-
publicKey
|
|
48
|
-
|
|
53
|
+
publicKey,
|
|
54
|
+
user: {
|
|
49
55
|
_id: userInfo._id,
|
|
50
56
|
name: userInfo?.name || '',
|
|
51
57
|
email: userInfo?.email || '',
|
|
58
|
+
phone: userInfo?.phone || '',
|
|
52
59
|
},
|
|
53
|
-
subscriptionId
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
handlePayment,
|
|
60
|
+
subscriptionId,
|
|
61
|
+
productId: digitalProductId,
|
|
62
|
+
cart: summaryItems || [],
|
|
63
|
+
callbacks,
|
|
64
|
+
paymentHandler: handlePayment,
|
|
58
65
|
});
|
|
59
66
|
|
|
60
67
|
return (
|
|
@@ -64,6 +71,8 @@ const ZezoPay: React.FC<ZezoPayProps> = ({
|
|
|
64
71
|
barStyle="dark-content"
|
|
65
72
|
backgroundColor={styles.safeArea.backgroundColor}
|
|
66
73
|
/>
|
|
74
|
+
|
|
75
|
+
{/* Header */}
|
|
67
76
|
<SafeAreaView style={styles.headerSafeArea} edges={['top']}>
|
|
68
77
|
<View style={styles.headerWrapper}>
|
|
69
78
|
<Header
|
|
@@ -74,6 +83,7 @@ const ZezoPay: React.FC<ZezoPayProps> = ({
|
|
|
74
83
|
</View>
|
|
75
84
|
</SafeAreaView>
|
|
76
85
|
|
|
86
|
+
{/* Main content */}
|
|
77
87
|
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
|
|
78
88
|
<View style={styles.container}>
|
|
79
89
|
<KeyboardAwareScrollView
|
|
@@ -86,19 +96,30 @@ const ZezoPay: React.FC<ZezoPayProps> = ({
|
|
|
86
96
|
contentInsetAdjustmentBehavior="never"
|
|
87
97
|
>
|
|
88
98
|
<View style={styles.content}>
|
|
99
|
+
{/* Payment Methods */}
|
|
89
100
|
<PaymentMethod
|
|
90
101
|
providers={providers || []}
|
|
91
|
-
onProviderChange={
|
|
92
|
-
selectedProvider={
|
|
93
|
-
isLoading={
|
|
94
|
-
error={
|
|
102
|
+
onProviderChange={setProvider}
|
|
103
|
+
selectedProvider={provider}
|
|
104
|
+
isLoading={providersLoading}
|
|
105
|
+
error={providersError?.message}
|
|
95
106
|
/>
|
|
96
107
|
|
|
97
|
-
|
|
108
|
+
{/* Summary items */}
|
|
109
|
+
<Summary items={cartItems} onRemoveItem={removeItem} />
|
|
110
|
+
{/* Voucher Box */}
|
|
111
|
+
{voucher && (
|
|
112
|
+
<VoucherBox
|
|
113
|
+
onApply={({ voucherCode }) => applyCoupon(voucherCode)}
|
|
114
|
+
loading={couponLoading}
|
|
115
|
+
couponApplied={!!coupon}
|
|
116
|
+
onRemove={removeCoupon}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
98
119
|
</View>
|
|
99
120
|
</KeyboardAwareScrollView>
|
|
100
121
|
|
|
101
|
-
{/* Bottom container
|
|
122
|
+
{/* Bottom container */}
|
|
102
123
|
<View style={styles.bottomContainer}>
|
|
103
124
|
{error ? (
|
|
104
125
|
<View style={styles.errorWrapper}>
|
|
@@ -107,18 +128,18 @@ const ZezoPay: React.FC<ZezoPayProps> = ({
|
|
|
107
128
|
) : null}
|
|
108
129
|
|
|
109
130
|
<PayButton
|
|
110
|
-
onPaymentInitiate={
|
|
131
|
+
onPaymentInitiate={payNow}
|
|
111
132
|
status={
|
|
112
|
-
|
|
133
|
+
success
|
|
113
134
|
? 'success'
|
|
114
|
-
:
|
|
135
|
+
: loadingPayment
|
|
115
136
|
? 'processing'
|
|
116
|
-
: !
|
|
137
|
+
: !provider || totalAmount === 0
|
|
117
138
|
? 'disabled'
|
|
118
139
|
: 'idle'
|
|
119
140
|
}
|
|
120
141
|
paymentButtonText={`Pay ${formatCurrency({
|
|
121
|
-
amount:
|
|
142
|
+
amount: totalAmount,
|
|
122
143
|
minimumFractionDigits: 0,
|
|
123
144
|
})}`}
|
|
124
145
|
noteText="Powered by Zezo Pay"
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { PaymentProviderData } from '@zezosoft/zezopay-client';
|
|
2
1
|
import React, { memo, useCallback } from 'react';
|
|
3
2
|
import { Pressable, StyleSheet, Text, View, Animated } from 'react-native';
|
|
4
3
|
import { scale, moderateScale, verticalScale } from 'react-native-size-matters';
|
|
4
|
+
import type { IReadyPaymentProvider } from '../http/api-sdk';
|
|
5
5
|
|
|
6
6
|
interface PaymentMethodProps {
|
|
7
|
-
providers:
|
|
7
|
+
providers: IReadyPaymentProvider[];
|
|
8
8
|
selectedProvider: string | null;
|
|
9
9
|
onProviderChange: (provider: string) => void;
|
|
10
10
|
isLoading?: boolean;
|
|
@@ -52,7 +52,7 @@ const ProviderLogo: React.FC<{
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
const ProviderItem: React.FC<{
|
|
55
|
-
provider:
|
|
55
|
+
provider: IReadyPaymentProvider;
|
|
56
56
|
isProviderSelected: boolean;
|
|
57
57
|
isLoading: boolean;
|
|
58
58
|
onPress: (provider: string) => void;
|
|
@@ -118,7 +118,7 @@ const PaymentMethod: React.FC<PaymentMethodProps> = ({
|
|
|
118
118
|
{(isLoading ? skeletonItems : providers).map((provider) => (
|
|
119
119
|
<ProviderItem
|
|
120
120
|
key={provider.provider}
|
|
121
|
-
provider={provider
|
|
121
|
+
provider={provider}
|
|
122
122
|
isProviderSelected={provider.provider === selectedProvider}
|
|
123
123
|
isLoading={isLoading}
|
|
124
124
|
onPress={handleProviderChange}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { View, Text, Image, TouchableOpacity, StyleSheet } from 'react-native';
|
|
2
2
|
import { X } from 'lucide-react-native';
|
|
3
|
-
import type { ISummaryItem } from '@zezosoft/zezopay-client';
|
|
4
3
|
import { formatCurrency } from '../utils';
|
|
4
|
+
import type { ISummaryItem } from '../types';
|
|
5
5
|
|
|
6
6
|
export const Summary = ({
|
|
7
7
|
items = [],
|