Skip to content

Commit c86789c

Browse files
committed
feat(paywithflutterwave): add v3 pay with flutterwave
1 parent c04f0cb commit c86789c

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/PayWithFlutterwave.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import {
4+
PayWithFlutterwavePropsBase,
5+
OptionsPropTypeBase,
6+
PayWithFlutterwavePropTypesBase
7+
} from './PaywithFlutterwaveBase';
8+
import FlutterwaveInit, {FlutterwaveInitOptions} from './FlutterwaveInit';
9+
import {PAYMENT_OPTIONS} from './configs';
10+
import {PaymentOptionsPropRule} from './utils/CustomPropTypesRules';
11+
import PayWithFlutterwaveBase from './PaywithFlutterwaveBase';
12+
13+
export interface RedirectParams {
14+
status: 'successful' | 'cancelled',
15+
transaction_id?: string;
16+
tx_ref: string;
17+
}
18+
19+
// create V3 component props
20+
export type PayWithFlutterwaveProps = PayWithFlutterwavePropsBase & {
21+
onRedirect: (data: RedirectParams) => void;
22+
options: Omit<FlutterwaveInitOptions, 'redirect_url'>;
23+
}
24+
25+
// create V3 component
26+
const PayWithFlutterwave:React.FC<PayWithFlutterwaveProps> = ({options, ...props}) => {
27+
return (
28+
<PayWithFlutterwaveBase
29+
{...props}
30+
reference={options.tx_ref}
31+
options={options}
32+
init={FlutterwaveInit}
33+
/>
34+
);
35+
}
36+
37+
// define component prop types
38+
PayWithFlutterwave.propTypes = {
39+
...PayWithFlutterwavePropTypesBase,
40+
// @ts-ignore
41+
options: PropTypes.shape({
42+
...OptionsPropTypeBase,
43+
authorization: PropTypes.string.isRequired,
44+
tx_ref: PropTypes.string.isRequired,
45+
payment_options: PaymentOptionsPropRule(PAYMENT_OPTIONS),
46+
customer: PropTypes.shape({
47+
name: PropTypes.string,
48+
phonenumber: PropTypes.string,
49+
email: PropTypes.string.isRequired,
50+
}).isRequired,
51+
meta: PropTypes.object,
52+
customizations: PropTypes.shape({
53+
title: PropTypes.string,
54+
logo: PropTypes.string,
55+
description: PropTypes.string,
56+
}),
57+
}).isRequired,
58+
};
59+
// export component as default
60+
export default PayWithFlutterwave;

0 commit comments

Comments
 (0)