mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 05:52:40 +03:00
Added redemptionCount to Offer
refs https://github.com/TryGhost/Team/issues/1132 This is a read-only property for tracking how many times an Offer has been redeemed
This commit is contained in:
parent
30fa4158bd
commit
34c0a7f6af
@ -27,6 +27,7 @@ const OfferStatus = require('./OfferStatus');
|
|||||||
* @prop {string} [stripe_coupon_id]
|
* @prop {string} [stripe_coupon_id]
|
||||||
* @prop {OfferStatus} status
|
* @prop {OfferStatus} status
|
||||||
* @prop {OfferTier} tier
|
* @prop {OfferTier} tier
|
||||||
|
* @prop {number} redemptionCount
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,6 +45,7 @@ const OfferStatus = require('./OfferStatus');
|
|||||||
* @prop {string} currency
|
* @prop {string} currency
|
||||||
* @prop {string} [stripe_coupon_id]
|
* @prop {string} [stripe_coupon_id]
|
||||||
* @prop {string} status
|
* @prop {string} status
|
||||||
|
* @prop {number} redemptionCount
|
||||||
* @prop {TierProps|OfferTier} tier
|
* @prop {TierProps|OfferTier} tier
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -124,6 +126,10 @@ class Offer {
|
|||||||
return this.props.status;
|
return this.props.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get redemptionCount() {
|
||||||
|
return this.props.redemptionCount;
|
||||||
|
}
|
||||||
|
|
||||||
set status(value) {
|
set status(value) {
|
||||||
this.props.status = value;
|
this.props.status = value;
|
||||||
}
|
}
|
||||||
@ -261,6 +267,15 @@ class Offer {
|
|||||||
const duration = OfferDuration.create(data.duration, data.duration_in_months);
|
const duration = OfferDuration.create(data.duration, data.duration_in_months);
|
||||||
const status = OfferStatus.create(data.status || 'active');
|
const status = OfferStatus.create(data.status || 'active');
|
||||||
|
|
||||||
|
if (isNew && data.redemptionCount !== undefined) {
|
||||||
|
// TODO correct error
|
||||||
|
throw new errors.InvalidOfferCode({
|
||||||
|
message: 'An Offer cannot be created with redemptionCount'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const redemptionCount = data.redemptionCount || 0;
|
||||||
|
|
||||||
if (cadence.value === 'year' && duration.value.type === 'repeating') {
|
if (cadence.value === 'year' && duration.value.type === 'repeating') {
|
||||||
throw new errors.InvalidOfferDuration({
|
throw new errors.InvalidOfferDuration({
|
||||||
message: 'Offer `duration` must be "once" or "forever" for the "yearly" cadence.'
|
message: 'Offer `duration` must be "once" or "forever" for the "yearly" cadence.'
|
||||||
@ -319,6 +334,7 @@ class Offer {
|
|||||||
currency,
|
currency,
|
||||||
tier,
|
tier,
|
||||||
stripe_coupon_id: couponId,
|
stripe_coupon_id: couponId,
|
||||||
|
redemptionCount,
|
||||||
status
|
status
|
||||||
}, {isNew});
|
}, {isNew});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user