users: add account upgrade integration tests.

* Test that the user upgrade process integrates with Stripe correctly.
* Replace a deprecated `card` param with `source` in `Stripe::Charge.create`.
* Rescue Stripe::StripeError instead of Stripe::CardError so that we
  handle failures outside of card failures, such as network errors.
This commit is contained in:
evazion
2020-12-13 18:33:46 -06:00
parent c82e05d828
commit 2144f45fa4
4 changed files with 109 additions and 7 deletions

View File

@@ -42,15 +42,10 @@ class UserUpgradesController < ApplicationController
end
begin
charge = Stripe::Charge.create(
:amount => cost,
:currency => "usd",
:card => params[:stripeToken],
:description => params[:desc]
)
charge = Stripe::Charge.create(amount: cost, currency: "usd", source: params[:stripeToken], description: params[:desc])
@user.promote_to!(level, User.system, is_upgrade: true)
flash[:success] = true
rescue Stripe::CardError => e
rescue Stripe::StripeError => e
DanbooruLogger.log(e)
flash[:error] = e.message
end