mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
Stripe API version update fixes
Using customer sources instead of cards so we can update our API version: https://stripe.com/docs/upgrades?since=2014-11-05#api-changelog
This commit is contained in:
parent
a4f50c4dd1
commit
7e46b819c4
2 changed files with 17 additions and 18 deletions
|
@ -36,7 +36,7 @@ module.exports = class SubscriptionView extends RootView
|
||||||
else
|
else
|
||||||
c.nextPaymentDate = periodEnd
|
c.nextPaymentDate = periodEnd
|
||||||
c.cost = "$#{(subscription.plan.amount/100).toFixed(2)}"
|
c.cost = "$#{(subscription.plan.amount/100).toFixed(2)}"
|
||||||
if card = @stripeInfo.cards?.data?[0]
|
if card = @stripeInfo.sources?.data?[0]
|
||||||
c.card = "#{card.brand}: x#{card.last4}"
|
c.card = "#{card.brand}: x#{card.last4}"
|
||||||
if @payments?.loaded
|
if @payments?.loaded
|
||||||
c.monthsSubscribed = (x for x in @payments.models when not x.get('productID')).length # productID is for gem purchases
|
c.monthsSubscribed = (x for x in @payments.models when not x.get('productID')).length # productID is for gem purchases
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe '/db/payment', ->
|
||||||
request = require 'request'
|
request = require 'request'
|
||||||
paymentURL = getURL('/db/payment')
|
paymentURL = getURL('/db/payment')
|
||||||
checkChargesURL = getURL('/db/payment/check-stripe-charges')
|
checkChargesURL = getURL('/db/payment/check-stripe-charges')
|
||||||
|
|
||||||
firstApplePayment = {
|
firstApplePayment = {
|
||||||
apple: {
|
apple: {
|
||||||
rawReceipt: testReceipt
|
rawReceipt: testReceipt
|
||||||
|
@ -15,7 +15,7 @@ describe '/db/payment', ->
|
||||||
localPrice: '$5.00'
|
localPrice: '$5.00'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
secondApplePayment = {
|
secondApplePayment = {
|
||||||
apple: {
|
apple: {
|
||||||
rawReceipt: testReceipt
|
rawReceipt: testReceipt
|
||||||
|
@ -23,7 +23,7 @@ describe '/db/payment', ->
|
||||||
localPrice: '$10.00'
|
localPrice: '$10.00'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paymentCreated = null
|
paymentCreated = null
|
||||||
|
|
||||||
it 'clears the db first', (done) ->
|
it 'clears the db first', (done) ->
|
||||||
|
@ -32,13 +32,13 @@ describe '/db/payment', ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe 'posting Apple IAPs', ->
|
describe 'posting Apple IAPs', ->
|
||||||
|
|
||||||
it 'denies anonymous users trying to pay', (done) ->
|
it 'denies anonymous users trying to pay', (done) ->
|
||||||
request.get getURL('/auth/whoami'), ->
|
request.get getURL('/auth/whoami'), ->
|
||||||
request.post {uri: paymentURL, json: firstApplePayment}, (err, res, body) ->
|
request.post {uri: paymentURL, json: firstApplePayment}, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe 403
|
expect(res.statusCode).toBe 403
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'creates a payment object and credits gems to the user', (done) ->
|
it 'creates a payment object and credits gems to the user', (done) ->
|
||||||
loginJoe ->
|
loginJoe ->
|
||||||
request.post {uri: paymentURL, json: firstApplePayment}, (err, res, body) ->
|
request.post {uri: paymentURL, json: firstApplePayment}, (err, res, body) ->
|
||||||
|
@ -48,7 +48,7 @@ describe '/db/payment', ->
|
||||||
expect(user.get('purchased').gems).toBe(5000)
|
expect(user.get('purchased').gems).toBe(5000)
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
|
|
||||||
it 'is idempotent', (done) ->
|
it 'is idempotent', (done) ->
|
||||||
loginJoe ->
|
loginJoe ->
|
||||||
request.post {uri: paymentURL, json: firstApplePayment}, (err, res, body) ->
|
request.post {uri: paymentURL, json: firstApplePayment}, (err, res, body) ->
|
||||||
|
@ -74,7 +74,7 @@ describe '/db/payment', ->
|
||||||
expect(user.get('purchased').gems).toBe(16000)
|
expect(user.get('purchased').gems).toBe(16000)
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
|
|
||||||
describe 'posting Stripe purchases', ->
|
describe 'posting Stripe purchases', ->
|
||||||
|
|
||||||
stripe = require('stripe')(config.stripe.secretKey)
|
stripe = require('stripe')(config.stripe.secretKey)
|
||||||
|
@ -121,7 +121,7 @@ describe '/db/payment', ->
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
it 'ignores repeated purchases', (done) ->
|
it 'ignores repeated purchases', (done) ->
|
||||||
data = { productID: 'gems_5', stripe: { token: stripeTokenID, timestamp: timestamp } }
|
data = { productID: 'gems_5', stripe: { token: stripeTokenID, timestamp: timestamp } }
|
||||||
request.post {uri: paymentURL, json: data }, (err, res, body) ->
|
request.post {uri: paymentURL, json: data }, (err, res, body) ->
|
||||||
|
@ -133,7 +133,7 @@ describe '/db/payment', ->
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
it 'allows a new charge on the existing customer', (done) ->
|
it 'allows a new charge on the existing customer', (done) ->
|
||||||
data = { productID: 'gems_5', stripe: { timestamp: new Date().getTime() } }
|
data = { productID: 'gems_5', stripe: { timestamp: new Date().getTime() } }
|
||||||
request.post {uri: paymentURL, json: data }, (err, res, body) ->
|
request.post {uri: paymentURL, json: data }, (err, res, body) ->
|
||||||
|
@ -144,11 +144,11 @@ describe '/db/payment', ->
|
||||||
joeData = user.toObject()
|
joeData = user.toObject()
|
||||||
expect(user.get('purchased').gems).toBe(10000)
|
expect(user.get('purchased').gems).toBe(10000)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "updates the customer's card when you submit a new token", (done) ->
|
it "updates the customer's card when you submit a new token", (done) ->
|
||||||
stripe.customers.retrieve joeData.stripe.customerID, (err, customer) ->
|
stripe.customers.retrieve joeData.stripe.customerID, (err, customer) ->
|
||||||
originalCustomerID = customer.id
|
originalCustomerID = customer.id
|
||||||
originalCardID = customer.cards.data[0].id
|
originalCardID = customer.sources.data[0].id
|
||||||
stripe.tokens.create {
|
stripe.tokens.create {
|
||||||
card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
||||||
}, (err, token) ->
|
}, (err, token) ->
|
||||||
|
@ -159,7 +159,7 @@ describe '/db/payment', ->
|
||||||
joeData = user.toObject()
|
joeData = user.toObject()
|
||||||
expect(joeData.stripe.customerID).toBe(originalCustomerID)
|
expect(joeData.stripe.customerID).toBe(originalCustomerID)
|
||||||
stripe.customers.retrieve joeData.stripe.customerID, (err, customer) ->
|
stripe.customers.retrieve joeData.stripe.customerID, (err, customer) ->
|
||||||
expect(customer.cards.data[0].id).not.toBe(originalCardID)
|
expect(customer.sources.data[0].id).not.toBe(originalCardID)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'clears the db', (done) ->
|
it 'clears the db', (done) ->
|
||||||
|
@ -172,7 +172,7 @@ describe '/db/payment', ->
|
||||||
card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
card: { number: '4242424242424242', exp_month: 12, exp_year: 2020, cvc: '123' }
|
||||||
}, (err, token) ->
|
}, (err, token) ->
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
productID: 'gems_5'
|
productID: 'gems_5'
|
||||||
stripe: { token: token.id, timestamp: timestamp }
|
stripe: { token: token.id, timestamp: timestamp }
|
||||||
breakAfterCharging: true
|
breakAfterCharging: true
|
||||||
|
@ -181,11 +181,11 @@ describe '/db/payment', ->
|
||||||
loginJoe (joe) ->
|
loginJoe (joe) ->
|
||||||
request.post {uri: paymentURL, json: data }, (err, res, body) ->
|
request.post {uri: paymentURL, json: data }, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe 500
|
expect(res.statusCode).toBe 500
|
||||||
|
|
||||||
data = _.omit data, 'breakAfterCharging'
|
data = _.omit data, 'breakAfterCharging'
|
||||||
request.post {uri: paymentURL, json: data }, (err, res, body) ->
|
request.post {uri: paymentURL, json: data }, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe 201
|
expect(res.statusCode).toBe 201
|
||||||
|
|
||||||
Payment.count({}, (err, count) ->
|
Payment.count({}, (err, count) ->
|
||||||
expect(count).toBe(1)
|
expect(count).toBe(1)
|
||||||
User.findById(joe.get('_id'), (err, user) ->
|
User.findById(joe.get('_id'), (err, user) ->
|
||||||
|
@ -199,7 +199,7 @@ describe '/db/payment', ->
|
||||||
clearModels [User, Payment], (err) ->
|
clearModels [User, Payment], (err) ->
|
||||||
throw err if err
|
throw err if err
|
||||||
done()
|
done()
|
||||||
|
|
||||||
# Testing card numbers are here: https://stripe.com/docs/testing
|
# Testing card numbers are here: https://stripe.com/docs/testing
|
||||||
|
|
||||||
it 'handles card that attaches to customer but fails to be charged', (done) ->
|
it 'handles card that attaches to customer but fails to be charged', (done) ->
|
||||||
|
@ -295,4 +295,3 @@ describe '/db/payment', ->
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue