🐛Increment gems for year sale purchase

This commit is contained in:
Matt Lott 2015-08-24 10:54:06 -07:00
parent 7d419c1615
commit 9c492a2d4b
3 changed files with 12 additions and 0 deletions

View file

@ -28,6 +28,7 @@ module.exports =
service: 'stripe' service: 'stripe'
amount: parseInt(stripeCharge.amount) amount: parseInt(stripeCharge.amount)
payment.set 'description', stripeCharge.metadata.description if stripeCharge.metadata.description payment.set 'description', stripeCharge.metadata.description if stripeCharge.metadata.description
payment.set 'gems', parseInt(stripeCharge.metadata.gems) if stripeCharge.metadata.gems
payment.set 'stripe', payment.set 'stripe',
customerID: stripeCharge.customer customerID: stripeCharge.customer
timestamp: parseInt(stripeCharge.metadata.timestamp) timestamp: parseInt(stripeCharge.metadata.timestamp)

View file

@ -127,6 +127,7 @@ class SubscriptionHandler extends Handler
metadata = metadata =
type: req.body.type type: req.body.type
userID: req.user._id + '' userID: req.user._id + ''
gems: subscriptions.basic.gems * 12
timestamp: parseInt(req.body.stripe?.timestamp) timestamp: parseInt(req.body.stripe?.timestamp)
description: req.body.description description: req.body.description
@ -146,6 +147,14 @@ class SubscriptionHandler extends Handler
stripeInfo = _.cloneDeep(req.user.get('stripe') ? {}) stripeInfo = _.cloneDeep(req.user.get('stripe') ? {})
stripeInfo.free = endDate.toISOString().substring(0, 10) stripeInfo.free = endDate.toISOString().substring(0, 10)
req.user.set('stripe', stripeInfo) req.user.set('stripe', stripeInfo)
# Add year's worth of gems to User
purchased = _.clone(req.user.get('purchased'))
purchased ?= {}
purchased.gems ?= 0
purchased.gems += parseInt(charge.metadata.gems)
req.user.set('purchased', purchased)
req.user.save (err, user) => req.user.save (err, user) =>
if err if err
@logSubscriptionError(req.user, "User save error: #{JSON.stringify(err)}") @logSubscriptionError(req.user, "User save error: #{JSON.stringify(err)}")

View file

@ -1394,7 +1394,9 @@ describe 'Subscriptions', ->
endDate.setUTCFullYear(endDate.getUTCFullYear() + 1) endDate.setUTCFullYear(endDate.getUTCFullYear() + 1)
expect(stripeInfo.free).toEqual(endDate.toISOString().substring(0, 10)) expect(stripeInfo.free).toEqual(endDate.toISOString().substring(0, 10))
expect(stripeInfo.customerID).toBeDefined() expect(stripeInfo.customerID).toBeDefined()
expect(user1.get('purchased')?.gems).toEqual(3500*12)
Payment.findOne 'stripe.customerID': stripeInfo.customerID, (err, payment) -> Payment.findOne 'stripe.customerID': stripeInfo.customerID, (err, payment) ->
expect(err).toBeNull() expect(err).toBeNull()
expect(payment).toBeDefined() expect(payment).toBeDefined()
expect(payment.get('gems')).toEqual(3500*12)
done() done()