Skip to content
This repository was archived by the owner on Mar 27, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions demo/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,6 @@ class _PaymentRequestForm extends React.Component<
},
});

paymentRequest.on('token', ({complete, token, ...data}) => {
console.log('Received Stripe token: ', token);
console.log('Received customer information: ', data);
complete('success');
});

paymentRequest.canMakePayment().then((result) => {
this.setState({canMakePayment: !!result});
});

this.state = {
canMakePayment: false,
paymentRequest,
Expand All @@ -176,6 +166,18 @@ class _PaymentRequestForm extends React.Component<
paymentRequest: Object,
};

componentDidMount() {
this.state.paymentRequest.on('token', ({complete, token, ...data}) => {
console.log('Received Stripe token: ', token);
console.log('Received customer information: ', data);
complete('success');
});

this.state.paymentRequest.canMakePayment().then((result) => {
this.setState({canMakePayment: !!result});
});
}

render() {
return this.state.canMakePayment ? (
<PaymentRequestButtonElement
Expand Down
4 changes: 2 additions & 2 deletions src/components/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ const Element = (
});
}

componentWillReceiveProps(nextProps: Props) {
const options = _extractOptions(nextProps);
componentDidUpdate() {
const options = _extractOptions(this.props);
if (
Object.keys(options).length !== 0 &&
!isEqual(options, this._options)
Expand Down
6 changes: 3 additions & 3 deletions src/components/PaymentRequestButtonElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ class PaymentRequestButtonElement extends React.Component<Props> {
this._element.mount(this._ref);
});
}
componentWillReceiveProps(nextProps: Props) {
if (this.props.paymentRequest !== nextProps.paymentRequest) {
componentDidUpdate(prevProps: Props) {
if (this.props.paymentRequest !== prevProps.paymentRequest) {
console.warn(
'Unsupported prop change: paymentRequest is not a customizable property.'
);
}
const options = _extractOptions(nextProps);
const options = _extractOptions(this.props);
if (
Object.keys(options).length !== 0 &&
!shallowEqual(options, this._options)
Expand Down
14 changes: 7 additions & 7 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ export default class Provider extends React.Component<Props> {
}
}

componentWillReceiveProps(nextProps: Props) {
componentDidUpdate(prevProps: Props) {
const apiKeyChanged =
this.props.apiKey &&
nextProps.apiKey &&
this.props.apiKey !== nextProps.apiKey;
prevProps.apiKey &&
this.props.apiKey !== prevProps.apiKey;

const stripeInstanceChanged =
this.props.stripe &&
nextProps.stripe &&
this.props.stripe !== nextProps.stripe;
prevProps.stripe &&
this.props.stripe !== prevProps.stripe;
if (
!this._didWarn &&
(apiKeyChanged || stripeInstanceChanged) &&
Expand All @@ -174,10 +174,10 @@ export default class Provider extends React.Component<Props> {
return;
}

if (!this._didWakeUpListeners && nextProps.stripe) {
if (!this._didWakeUpListeners && this.props.stripe) {
// Wake up the listeners if we've finally been given a StripeShape
this._didWakeUpListeners = true;
const stripe = ensureStripeShape(nextProps.stripe);
const stripe = ensureStripeShape(this.props.stripe);
this._meta.stripe = stripe;
this._listeners.forEach((fn) => {
fn(stripe);
Expand Down