Skip to content

Commit a228e9a

Browse files
committed
feat(paywithflutterwavev2): create component
1 parent e1a0825 commit a228e9a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/PayWithFlutterwaveV2.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import {
4+
PayWithFlutterwavePropsBase,
5+
OptionsPropTypeBase,
6+
PayWithFlutterwavePropTypesBase
7+
} from './PaywithFlutterwaveBase';
8+
import FlutterwaveInitV2, {FlutterwaveInitV2Options} from './FlutterwaveInitV2';
9+
import {PAYMENT_OPTIONS_V2} from './configs';
10+
import {PaymentOptionsPropRule} from './utils/CustomPropTypesRules';
11+
import PayWithFlutterwaveBase from './PaywithFlutterwaveBase';
12+
13+
export interface RedirectParamsV2 {
14+
cancelled?: 'true' | 'false';
15+
flwref?: string;
16+
txref: string;
17+
}
18+
19+
export type PayWithFlutterwaveV2Props = PayWithFlutterwavePropsBase & {
20+
onRedirect: (data: RedirectParamsV2) => void;
21+
options: Omit<FlutterwaveInitV2Options, 'redirect_url'>;
22+
}
23+
24+
// create V2 component
25+
const PayWithFlutterwaveV2:React.FC<PayWithFlutterwaveV2Props> = ({options, ...props}) => {
26+
return (
27+
<PayWithFlutterwaveBase
28+
{...props}
29+
reference={options.txref}
30+
options={options}
31+
init={FlutterwaveInitV2}
32+
/>
33+
);
34+
}
35+
36+
// define component prop types
37+
PayWithFlutterwaveV2.propTypes = {
38+
...PayWithFlutterwavePropTypesBase,
39+
// @ts-ignore
40+
options: PropTypes.shape({
41+
...OptionsPropTypeBase,
42+
payment_options: PaymentOptionsPropRule(PAYMENT_OPTIONS_V2),
43+
txref: PropTypes.string.isRequired,
44+
PBFPubKey: PropTypes.string.isRequired,
45+
customer_firstname: PropTypes.string,
46+
customer_lastname: PropTypes.string,
47+
customer_email: PropTypes.string.isRequired,
48+
customer_phone: PropTypes.string,
49+
country: PropTypes.string,
50+
pay_button_text: PropTypes.string,
51+
custom_title: PropTypes.string,
52+
custom_description: PropTypes.string,
53+
custom_logo: PropTypes.string,
54+
meta: PropTypes.arrayOf(PropTypes.shape({
55+
metaname: PropTypes.string,
56+
metavalue: PropTypes.string,
57+
})),
58+
}).isRequired,
59+
};
60+
// export component as default
61+
export default PayWithFlutterwaveV2;

0 commit comments

Comments
 (0)