Skip to content

Commit

Permalink
Removes Stripe credit card code/config
Browse files Browse the repository at this point in the history
  • Loading branch information
willroberts committed Sep 13, 2022
1 parent f92c795 commit 9abe792
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 875 deletions.
46 changes: 1 addition & 45 deletions app/ui/views2/shop/credit_card_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,51 +68,7 @@ const CreditCardFormView = Backbone.Marionette.ItemView.extend({
this.trigger('submit');

return new Promise((resolve, reject) => {
if (typeof Stripe !== 'undefined') {
Stripe.setPublishableKey(process.env.STRIPE_CLIENT_KEY);
Stripe.card.createToken({
number: this.ui.number.val(),
cvc: this.ui.cvc.val(),
exp_month: this.ui.expiration_month.val(),
exp_year: this.ui.expiration_year.val(),
}, (status, response) => {
if (response.error) {
// Show the errors on the form
const errorMessage = response.error.message || 'Failed to save credit card data.';
reject(errorMessage);
} else {
// response contains id and card, which contains additional card details
const token = response.id;
const last_four_digits = this.ui.number.val().substr(this.ui.number.val().length - 4);

if (this.ui.save_card.is(':checked') || InventoryManager.getInstance().walletModel.get('card_last_four_digits')) {
const request = $.ajax({
data: JSON.stringify({
card_token: token,
last_four_digits,
}),
url: `${process.env.API_URL}/api/me/shop/customer`,
type: 'POST',
contentType: 'application/json',
dataType: 'json',
});

request.done((response) => {
resolve({ token, stored: true });
});

request.fail((response) => {
reject(response && response.responseJSON && (response.responseJSON.error || response.responseJSON.message) || 'Failed to save credit card data. Please retry.');
});
} else {
resolve({ token, stored: false });
}
}
});
} else {
const errorMessage = 'Failed to save credit card data.';
reject(errorMessage);
}
resolve('Credit card storage is disabled.');
});
},

Expand Down
163 changes: 1 addition & 162 deletions cli/crm.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2038,45 +2038,8 @@ program
.catch (e)->
console.log prettyError.render(e)
callback(e)
program
.command 'charges:sync <charge_id>'
.description 'sync charge JSON to billing copy of data'
.action (args,callback)->
charge_id = args.charge_id
knex("user_charges").where('charge_id',charge_id).first()
.bind {}
.then (row)->
if not row?
throw new Error("Could not find row")
stripe = require("stripe")(config.get('stripeSecretKey'))
Promise.promisifyAll(stripe.charges)
return stripe.charges.retrieveAsync(charge_id)
.then (chargeData)->
@.chargeData = chargeData
console.log prettyjson.render(@.chargeData)
return confirmAsync("Continue?")
.then ()->
knex("user_charges").where('charge_id',charge_id).update({
'charge_json':@.chargeData,
'updated_at':moment().utc().toDate()
})
.catch DidNotConfirmError, (e)->
callback(e)
# process.exit(1)
.catch (e)->
console.log prettyError.render(e)
callback(e)
# process.exit(1)
###

program
.command 'steam:unlink <username_or_email>'
.description 'unlink steam from a user\'s account'
Expand Down Expand Up @@ -2239,130 +2202,6 @@ program
callback(e)
# process.exit(1)
program
.command 'charges:refund <charge_id> [suspend]'
.description 'refund a STRIPE charge'
.action (args,callback)->
charge_id = args.charge_id
is_suspended = args.suspend || false
if not charge_id.indexOf('ch_') == 0
callback(new Error("This doesn't look like a STRIPE charge ID"))
if not SyncModule?
SyncModule = require 'server/lib/data_access/sync'
knex("user_charges").where('charge_id',charge_id).first()
.bind {}
.then (row)->
if not row?
throw new Error("Could not find row")
@.charge = row
console.log prettyjson.render(row)
if is_suspended
console.log "User WILL be suspended".cyan
else
console.log "User will NOT suspended".yellow
return knex("user_spirit_orbs").where({
'user_id':row.user_id
'transaction_id':charge_id
}).select()
.then (rows)->
return confirmAsync("Refunding #{charge_id} for #{@.charge.amount} ... #{rows?.length} orbs will be deleted")
.then ()->
charge = @.charge
return knex.transaction (tx)->
knex("user_spirit_orbs").where({
'user_id':charge.user_id
'transaction_id':charge_id
}).delete().transacting(tx)
.then (count)->
return confirmAsync("DELETED #{count} ORBS... commit?")
.then ()->
return knex("user_charges").where("charge_id",charge_id).update({
refunded_at:moment().utc().toDate()
memo:"refunded and orbs deleted"
}).transacting(tx)
.then (count)->
console.log("UPDATED #{count} charges...")
if is_suspended
return knex("users").where("id",charge.user_id).update({
is_suspended:true
suspended_at:moment().utc().toDate()
suspended_memo:"received refund for opened spirit orbs"
}).transacting(tx)
else
return 0
.then (count)->
console.log("UPDATED #{count} users...")
return confirmAsync("Final check... commit?")
.then ()->
console.log "COMMIT".cyan
tx.commit()
.catch (e)->
console.log e
console.log "ROLLBACK".red
tx.rollback()
return;
.then ()->
console.log "re-sync user #{@.charge.user_id} account data to Firebase... "
return SyncModule._syncUserFromSQLToFirebase(@.charge.user_id)
.then ()->
console.log "refunding $ amount ..."
stripe = require("stripe")(config.get('stripeSecretKey'))
@.stripe = stripe
Promise.promisifyAll(stripe.charges)
Promise.promisifyAll(stripe.refunds)
return stripe.refunds.createAsync({
charge: charge_id
})
.then ()->
console.log "syncing charge data from billing system to SQL ..."
return @.stripe.charges.retrieveAsync(charge_id)
.then (chargeData)->
console.log "got chargeData ..."
console.log prettyjson.render(chargeData)
@.chargeData = chargeData
knex("user_charges").where('charge_id',charge_id).update({
'charge_json':@.chargeData,
'updated_at':moment().utc().toDate()
})
.then (count)->
console.log "updated #{count} charges"
console.log "DONE".green
.catch DidNotConfirmError, (e)->
callback(e)
# process.exit(1)
.catch (e)->
console.log prettyError.render(e)
callback(e)
# process.exit(1)
program
.command 'referral_codes'
.description 'list referral codes'
Expand Down
10 changes: 0 additions & 10 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,6 @@ const config = convict({
env: 'BUGSNAG_WORKER',
},
},
stripeSecretKey: {
doc: 'Stripe Secret API key.',
default: '',
env: 'STRIPE_API_KEY',
},
stripeClientKey: {
doc: 'STRIPE client key.',
default: '',
env: 'STRIPE_CLIENT_KEY',
},
consul: {
enabled: {
doc: 'Enable/disable Consul-based server assignment.',
Expand Down
1 change: 0 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"analyticsEnabled": true,
"amaId":"",
"gaId":"",
"stripeClientKey":"",
"zendeskEnabled": true,
"bugsnag": {
"client_key": ""
Expand Down
1 change: 0 additions & 1 deletion gulp/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ bundler.transform(envify({
FIREBASE_URL: config.get('firebase.url'),
AMI_ID: config.get('amaId'),
MARKETING_AMA_ID: config.get('marketingAmaId'),
STRIPE_CLIENT_KEY: config.get('stripeClientKey'),
ALL_CARDS_AVAILABLE: config.get('allCardsAvailable'),
AI_TOOLS_ENABLED: config.get('aiToolsEnabled'),
RECORD_CLIENT_LOGS: config.get('recordClientLogs'),
Expand Down
1 change: 0 additions & 1 deletion gulp/bundler.register.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ bundler.transform(envify({
FIREBASE_URL: config.get('firebase.url'),
AMI_ID: config.get('amaId'),
MARKETING_AMA_ID: config.get('marketingAmaId'),
STRIPE_CLIENT_KEY: config.get('stripeClientKey'),
ALL_CARDS_AVAILABLE: config.get('allCardsAvailable'),
AI_TOOLS_ENABLED: config.get('aiToolsEnabled'),
RECORD_CLIENT_LOGS: config.get('recordClientLogs'),
Expand Down
Loading

0 comments on commit 9abe792

Please sign in to comment.