fix(donate): remove call to verification when not signed in

This commit is contained in:
Mrugesh Mohapatra
2020-03-20 13:07:02 +05:30
parent 08ec29fa1b
commit 8866ed74c2
2 changed files with 37 additions and 23 deletions

View File

@ -233,7 +233,7 @@ class DonateForm extends Component {
render() {
const { donationAmount, donationDuration } = this.state;
const { handleProcessing } = this.props;
const { handleProcessing, isSignedIn } = this.props;
const {
donationState: { processing, success, error }
} = this.state;
@ -268,6 +268,7 @@ class DonateForm extends Component {
donationDuration={donationDuration}
handleProcessing={handleProcessing}
onDonationStateChange={this.onDonationStateChange}
skipAddDonation={!isSignedIn}
/>
</Col>

View File

@ -33,27 +33,39 @@ export class PaypalButton extends Component {
handleApproval = data => {
const { amount, duration } = this.state;
this.props.handleProcessing(duration, amount, 'Paypal payment submission');
this.props.onDonationStateChange(false, true, '');
verifySubscriptionPaypal(data)
.then(response => {
const data = response && response.data;
this.props.onDonationStateChange(
true,
false,
data.error ? data.error : ''
);
})
.catch(error => {
const data =
error.response && error.response.data
? error.response.data
: {
error:
'Something is not right. Please contact team@freecodecamp.org'
};
this.props.onDonationStateChange(false, false, data.error);
});
const { skipAddDonation = false } = this.props;
if (!skipAddDonation) {
this.props.handleProcessing(
duration,
amount,
'Paypal payment submission'
);
this.props.onDonationStateChange(false, true, '');
verifySubscriptionPaypal(data)
.then(response => {
const data = response && response.data;
this.props.onDonationStateChange(
true,
false,
data.error ? data.error : ''
);
})
.catch(error => {
const data =
error.response && error.response.data
? error.response.data
: {
error: `Something is not right. Please contact team@freecodecamp.org`
};
this.props.onDonationStateChange(false, false, data.error);
});
} else {
this.props.onDonationStateChange(
true,
false,
data.error ? data.error : ''
);
}
};
render() {
@ -101,7 +113,8 @@ const propTypes = {
donationDuration: PropTypes.string,
handleProcessing: PropTypes.func,
isDonating: PropTypes.bool,
onDonationStateChange: PropTypes.func
onDonationStateChange: PropTypes.func,
skipAddDonation: PropTypes.bool
};
const mapStateToProps = createSelector(