forked from iamraphson/react-paystack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPayStack.js
More file actions
71 lines (65 loc) · 1.82 KB
/
Copy pathPayStack.js
File metadata and controls
71 lines (65 loc) · 1.82 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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class PayStack extends Component {
constructor(props){
super(props);
this.state = {
text: this.props.text || "Make Payment",
class: this.props.class || "",
metadata: this.props.metadata || {},
currency: this.props.currency || "NGN",
plan: this.props.plan || "",
quantity: this.props.quantity || "",
subaccount: this.props.subaccount || "",
transaction_charge: this.props.transaction_charge || 0,
bearer: this.props.bearer || ""
}
}
payWithPaystack = () => {
const handler = window.PaystackPop.setup({
key: this.props.paystackkey,
email: this.props.email,
amount: this.props.amount,
ref: this.props.reference,
metadata: this.state.metadata,
callback: (response) => {
this.props.callback(response)
},
onClose: () => {
this.props.close()
},
currency: this.state.currency,
plan: this.state.plan,
quantity: this.state.quantity,
subaccount: this.state.subaccount,
transaction_charge: this.state.transaction_charge,
bearer: this.state.bearer
});
handler.openIframe();
}
render(){
return (
<span>
<button onClick={this.payWithPaystack} className={this.state.class}>{this.state.text}</button>
</span>
);
}
}
PayStack.propTypes = {
text: PropTypes.string,
class: PropTypes.string,
metadata: PropTypes.object,
currency: PropTypes.string,
plan: PropTypes.string,
quantity: PropTypes.string,
subaccount: PropTypes.string,
transaction_charge: PropTypes.number,
bearer: PropTypes.string,
reference: PropTypes.string.isRequired,
email: PropTypes.string.isRequired,
amount: PropTypes.number.isRequired, //in kobo
paystackkey: PropTypes.string.isRequired,
callback: PropTypes.func.isRequired,
close: PropTypes.func.isRequired
}
export default PayStack;