MCPcopy Create free account
hub / github.com/codecombat/codecombat / loadPrepaid

Method loadPrepaid

app/views/account/PrepaidView.js:117–161  ·  view source on GitHub ↗
(ppc)

Source from the content-addressed store, hash-verified

115 }
116
117 loadPrepaid (ppc) {
118 if (!ppc) { return }
119 const options = {
120 cache: false,
121 method: 'GET',
122 url: `/db/prepaid/-/code/${ppc}`
123 }
124
125 options.success = (model, res, options) => {
126 this.ppcInfo = []
127 if (model.get('type') === 'terminal_subscription') {
128 let left, left1, left2, left3, unlocksLeft
129 const months = (left = __guard__(model.get('properties'), x => x.months)) != null ? left : 0
130 const days = (left1 = __guard__(model.get('properties'), x1 => x1.days)) != null ? left1 : 0
131 const maxRedeemers = (left2 = model.get('maxRedeemers')) != null ? left2 : 0
132 const redeemers = (left3 = model.get('redeemers')) != null ? left3 : []
133 if (ppc.length === 14) {
134 unlocksLeft = 1
135 } else {
136 unlocksLeft = maxRedeemers - redeemers.length
137 }
138 this.ppcInfo.push($.t('account_prepaid.prepaid_add_months', { months }))
139 this.ppcInfo.push($.t('account_prepaid.can_use_times', { unlocksLeft }))
140 // TODO: user needs to know they can't apply it more than once to their account
141 } else {
142 this.ppcInfo.push(`Type: ${model.get('type')}`)
143 }
144 return (typeof this.render === 'function' ? this.render() : undefined)
145 }
146 options.error = (model, res, options) => {
147 if (res.status === 404) {
148 if (res.responseText === 'Activation code has been used') {
149 this.ppcInfo.push($.i18n.t('account_prepaid.activation_code_used'))
150 if (typeof this.render === 'function') {
151 this.render()
152 }
153 return
154 }
155 }
156 return this.statusMessage('Unable to retrieve code.', 'error')
157 }
158
159 this.prepaid = new Prepaid()
160 return this.prepaid.fetch(options)
161 }
162
163 onClickLookupCodeButton (e) {
164 this.ppc = $('.input-ppc').val()

Callers 3

initializeMethod · 0.95

Calls 5

statusMessageMethod · 0.95
__guard__Function · 0.70
getMethod · 0.45
renderMethod · 0.45
fetchMethod · 0.45

Tested by

no test coverage detected