You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.7 KiB

Add `now billing` and `now upgrade` (#309) * Add the skeleton of `now cc` * Add the `ls` command * Add `inquirer` dependency * Add the `set-default` command * Fix typo * Show the real number of cards when selecting the default one * Add the `ls` command * Fix: Do not throw if there's no cards in the account * Add `blessed` dependency * Add the first sketch of `now cc add` * Add instructions * Add labels * Save every element in the `elements` array instead of variables * Tweaks * Fix: update the element attribute if it's not a special case * Add the `name` input; Add moving between inputs; Make the state more reliable * Auto "detect" if the input is losing focus * Remove useless stuff * Add the ability to move between the fields with tab/shift+tab * Add CCV field * Make the cycling between the fields "infinite" * Add expiration date field and allow only numbers in the CCV field * The form shouldn't have a fixed height * Add the address box and label * Add the address fields * Remove blessed stuff * Add preliminary input field * output utils * add prompt for booleans * fix @matheuss linting problems * remove example * lint * error and info helpers * helper for embedded commands * Remove useless stuff * Add `trailing` option * Add `resolveChars` option * Add `validate` option * Add `strip-ansi` dependency * Add `credit-card` dependency * Add credit card masking * Add support for expiration date mask * Make things simpler * Add auto completion support * Always show the `card_` id prefix * Add `@google/maps` dependency * Always print the initial value if it's available * Add `stripe` dependency * Add `add()` method * Add billing related utils * Add `now cc add` * Rename `cc` to `billing` * Fix: log only one blank line * Refactor * Add list input component * This shouldn't be here * Add `code` output util * Add `now upgrade | downgrade` * add build step * make it more future-proof * more reliable build * remove lock for now * Hide the CCV * Print the new line before `Saving card` * Use the new `success` component * Add confirmation steps for `cc rm` and `cc set-default` * Temporarily monket patch Inquirer * Build before testing * Run the tests using the built files * Fix the `prepublish` script and run the `build` one before packaging * Improve `now help`
8 years ago
const stripe = require('stripe')('pk_live_alyEi3lN0kSwbdevK0nrGwTw')
const Now = require('../lib')
module.exports = class CreditCards extends Now {
async ls() {
const res = await this._fetch('/www/user/cards')
const body = await res.json()
return body
}
async setDefault(cardId) {
await this._fetch('/www/user/cards/default', {
method: 'PUT',
body: {cardId}
})
return true
}
async rm(cardId) {
await this._fetch(`/www/user/cards/${encodeURIComponent(cardId)}`, {method: 'DELEtE'})
return true
}
/* eslint-disable camelcase */
add(card) {
return new Promise(async (resolve, reject) => {
const expDateParts = card.expDate.split(' / ')
card = {
name: card.name,
number: card.cardNumber,
cvc: card.ccv,
address_country: card.country,
address_zip: card.zipCode,
address_state: card.state,
address_city: card.city,
address_line1: card.address1
}
card.exp_month = expDateParts[0]
card.exp_year = expDateParts[1]
try {
const stripeToken = (await stripe.tokens.create({card})).id
const res = await this._fetch('/www/user/cards', {
method: 'POST',
body: {stripeToken}
})
const body = await res.json()
if (body.card && body.card.id) {
resolve({
last4: body.card.last4
})
} else if (body.error && body.error.message) {
reject({message: body.error.message})
} else {
reject('Unknown error')
}
} catch (err) {
reject({
message: err.message || 'Unknown error'
})
}
})
}
}