Skip to content
This repository was archived by the owner on Mar 27, 2021. It is now read-only.

Commit 226387a

Browse files
committed
Fix bug in demo component
1 parent cf6c643 commit 226387a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

demo/demo/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,6 @@ class _PaymentRequestForm extends React.Component<
166166
},
167167
});
168168

169-
paymentRequest.on('token', ({complete, token, ...data}) => {
170-
console.log('Received Stripe token: ', token);
171-
console.log('Received customer information: ', data);
172-
complete('success');
173-
});
174-
175-
paymentRequest.canMakePayment().then((result) => {
176-
this.setState({canMakePayment: !!result});
177-
});
178-
179169
this.state = {
180170
canMakePayment: false,
181171
paymentRequest,
@@ -187,6 +177,18 @@ class _PaymentRequestForm extends React.Component<
187177
paymentRequest: Object,
188178
};
189179

180+
componentDidMount() {
181+
this.state.paymentRequest.on('token', ({complete, token, ...data}) => {
182+
console.log('Received Stripe token: ', token);
183+
console.log('Received customer information: ', data);
184+
complete('success');
185+
});
186+
187+
this.state.paymentRequest.canMakePayment().then((result) => {
188+
this.setState({canMakePayment: !!result});
189+
});
190+
}
191+
190192
render() {
191193
return this.state.canMakePayment ? (
192194
<PaymentRequestButtonElement

0 commit comments

Comments
 (0)