forked from iamraphson/react-paystack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
109 lines (101 loc) · 2.73 KB
/
Copy pathApp.js
File metadata and controls
109 lines (101 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React from 'react';
import logo from './logo.svg';
import {usePaystackPayment, PaystackButton, PaystackConsumer} from './dist/index.es';
import './App.css';
const config = {
reference: new Date().getTime().toString(),
email: 'user@example.com',
amount: 20000,
publicKey: 'pk_test_a137d402b5975716e89952a898aad2832c961d69',
firstname: 'cool',
lastname: 'story',
/*split: { //if you want to use transaction split
"type": "percentage",
"bearer_type": "all",
"subaccounts": [
{
"subaccount": "ACCT_mtl3xzwjfhcldkw",
"share": 30
},
{
"subaccount": "ACCT_y19ht107y44o294",
"share": 20
}
]
}*/
};
const onSuccess = (reference) => {
// Implementation for whatever you want to do with reference and after success call.
console.log('reference', reference);
};
const onClose = () => {
// implementation for whatever you want to do when the Paystack dialog closed.
console.log('closed');
};
const PaystackHookExample = () => {
const initializePayment = usePaystackPayment(config);
return (
<div>
<button
onClick={() => {
initializePayment({onSuccess, onClose});
}}
>
Paystack Hooks Implementation
</button>
</div>
);
};
const PaystackHookSplitParameterExample = () => {
const initializePayment = usePaystackPayment(config);
return (
<div>
<button
onClick={() => {
initializePayment({config: {currency: 'NGN'}, onSuccess, onClose});
}}
>
Paystack Hooks with split parameter Implementation
</button>
</div>
);
};
function App() {
const componentProps = {
...config,
text: 'Paystack Button Implementation',
onSuccess,
onClose,
};
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<PaystackHookExample />
<PaystackHookSplitParameterExample />
<PaystackButton {...componentProps} />
<PaystackConsumer {...componentProps}>
{({initializePayment}) => {
return (
<button onClick={() => initializePayment({onSuccess, onClose})}>
Paystack Consumer Implementation
</button>
);
}}
</PaystackConsumer>
</div>
);
}
export default App;