mirror of
https://github.com/TryGhost/Ghost.git
synced 2023-12-13 21:00:40 +01:00
Fixed subscription issue with null coupons
no-issue Coupons were being sent as null to the api, so we support non required fields
This commit is contained in:
parent
ab3b0d95a2
commit
5cb8972e2c
|
@ -118,7 +118,7 @@ module.exports = function MembersApi({
|
|||
}
|
||||
|
||||
/* subscriptions */
|
||||
apiRouter.post('/subscription', getData('adapter', 'plan', 'stripeToken', 'coupon'), ssoOriginCheck, (req, res) => {
|
||||
apiRouter.post('/subscription', getData('adapter', 'plan', 'stripeToken', {name: 'coupon', required: false}), ssoOriginCheck, (req, res) => {
|
||||
const {signedin} = getCookie(req);
|
||||
if (!signedin) {
|
||||
res.writeHead(401, {
|
||||
|
|
|
@ -56,8 +56,8 @@ export default class Form extends Component {
|
|||
return (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const requiredFields = children.map(c => c.attributes.bindTo).filter(x => !!x)
|
||||
if (!requiredFields.some(x => !data[x])) {
|
||||
const requiredFields = children.map(c => c.attributes && c.attributes.bindTo).filter(x => !!x)
|
||||
if (!requiredFields.some(x => data[x] == null)) {
|
||||
onSubmit(this.state.data)
|
||||
}
|
||||
this.setState({
|
||||
|
|
|
@ -6,11 +6,22 @@ function getData(...props) {
|
|||
}
|
||||
|
||||
const data = props.concat('origin').reduce((data, prop) => {
|
||||
if (!data || !req.body[prop]) {
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let propObj = typeof prop === 'string' ? {
|
||||
name: prop,
|
||||
required: true
|
||||
} : prop;
|
||||
|
||||
const value = req.body[propObj.name];
|
||||
if (propObj.required && !value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Object.assign(data, {
|
||||
[prop]: req.body[prop]
|
||||
[propObj.name]: value
|
||||
});
|
||||
}, {});
|
||||
|
||||
|
|
Loading…
Reference in a new issue