fix(client): call donate api withCredentials
This commit is contained in:
committed by
mrugesh
parent
2a449d03a3
commit
368aa688fa
@ -14,11 +14,10 @@ import {
|
|||||||
} from '@freecodecamp/react-bootstrap';
|
} from '@freecodecamp/react-bootstrap';
|
||||||
import { injectStripe } from 'react-stripe-elements';
|
import { injectStripe } from 'react-stripe-elements';
|
||||||
|
|
||||||
import { apiLocation } from '../../../../config/env.json';
|
|
||||||
import Spacer from '../../../components/helpers/Spacer';
|
import Spacer from '../../../components/helpers/Spacer';
|
||||||
import StripeCardForm from './StripeCardForm';
|
import StripeCardForm from './StripeCardForm';
|
||||||
import DonateCompletion from './DonateCompletion';
|
import DonateCompletion from './DonateCompletion';
|
||||||
import { postJSON$ } from '../../../templates/Challenges/utils/ajax-stream.js';
|
import { postChargeStripe } from '../../../utils/ajax';
|
||||||
import { userSelector, isSignedInSelector } from '../../../redux';
|
import { userSelector, isSignedInSelector } from '../../../redux';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
@ -123,34 +122,40 @@ class DonateForm extends Component {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const chargeStripePath = isSignedIn
|
return postChargeStripe(isSignedIn, {
|
||||||
? `${apiLocation}/internal/donate/charge-stripe`
|
|
||||||
: `${apiLocation}/unauthenticated/donate/charge-stripe`;
|
|
||||||
return postJSON$(chargeStripePath, {
|
|
||||||
token,
|
token,
|
||||||
amount
|
amount
|
||||||
}).subscribe(
|
})
|
||||||
res =>
|
.then(response => {
|
||||||
|
const data = response && response.data;
|
||||||
this.setState(state => ({
|
this.setState(state => ({
|
||||||
...state,
|
...state,
|
||||||
donationState: {
|
donationState: {
|
||||||
...state.donationState,
|
...state.donationState,
|
||||||
processing: false,
|
processing: false,
|
||||||
success: true,
|
success: true,
|
||||||
error: res.error
|
error: data.error ? data.error : null
|
||||||
}
|
}
|
||||||
})),
|
}));
|
||||||
err =>
|
})
|
||||||
|
.catch(error => {
|
||||||
|
const data =
|
||||||
|
error.response && error.response.data
|
||||||
|
? error.response.data
|
||||||
|
: {
|
||||||
|
error:
|
||||||
|
'Something is not right. Please contact team@freecodecamp.org'
|
||||||
|
};
|
||||||
this.setState(state => ({
|
this.setState(state => ({
|
||||||
...state,
|
...state,
|
||||||
donationState: {
|
donationState: {
|
||||||
...state.donationState,
|
...state.donationState,
|
||||||
processing: false,
|
processing: false,
|
||||||
success: false,
|
success: false,
|
||||||
error: err.error
|
error: data.error
|
||||||
}
|
}
|
||||||
}))
|
}));
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resetDonation() {
|
resetDonation() {
|
||||||
|
@ -3,9 +3,14 @@ import { apiLocation } from '../../config/env.json';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
const base = apiLocation + '/internal';
|
const base = apiLocation + '/internal';
|
||||||
|
const baseUnauthenticated = apiLocation + '/unauthenticated';
|
||||||
|
|
||||||
axios.defaults.withCredentials = true;
|
axios.defaults.withCredentials = true;
|
||||||
|
|
||||||
|
export function postUnauthenticated(path, body) {
|
||||||
|
return axios.post(`${baseUnauthenticated}${path}`, body);
|
||||||
|
}
|
||||||
|
|
||||||
function get(path) {
|
function get(path) {
|
||||||
return axios.get(`${base}${path}`);
|
return axios.get(`${base}${path}`);
|
||||||
}
|
}
|
||||||
@ -45,6 +50,13 @@ export function getArticleById(shortId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** POST **/
|
/** POST **/
|
||||||
|
export function postChargeStripe(isSignedIn, body) {
|
||||||
|
const donatePath = '/donate/charge-stripe';
|
||||||
|
return isSignedIn
|
||||||
|
? post(donatePath, body)
|
||||||
|
: postUnauthenticated(donatePath, body);
|
||||||
|
}
|
||||||
|
|
||||||
export function putUpdateLegacyCert(body) {
|
export function putUpdateLegacyCert(body) {
|
||||||
return post('/update-my-projects', body);
|
return post('/update-my-projects', body);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user