Files
danbooru/test/factories/user_upgrade.rb
evazion 74ed2a8b96 user upgrades: add UserUpgrade model.
Add a model to store the status of user upgrades.

* Store the upgrade purchaser and the upgrade receiver (these are
  different for a gifted upgrade, the same for a self upgrade).
* Store the upgrade type: gold, platinum, or gold-to-platinum upgrades.
* Store the upgrade status:
** pending: User is still on the Stripe checkout page, no payment
   received yet.
** processing: User has completed checkout, but the checkout status in
   Stripe is still 'unpaid'.
** complete: We've received notification from Stripe that the payment
   has gone through and the user has been upgraded.
* Store the Stripe checkout ID, to cross-reference the upgrade record on
  Danbooru with the checkout record on Stripe.

This is the upgrade flow:

* When the user clicks the upgrade button on the upgrade page, we call
  POST /user_upgrades and create a pending UserUpgrade.
* We redirect the user to the checkout page on Stripe.
* When the user completes checkout on Stripe, Stripe sends us a webhook
  notification at POST /webhooks/receive.
* When we receive the webhook, we check the payment status, and if it's
  paid we mark the UserUpgrade as complete and upgrade the user.
* After Stripe sees that we have successfully processed the webhook,
  they redirect the user to the /user_upgrades/:id page, where we show
  the user their upgrade receipt.
2020-12-24 21:15:04 -06:00

39 lines
889 B
Ruby

FactoryBot.define do
factory(:user_upgrade) do
recipient { create(:member_user) }
purchaser { recipient }
upgrade_type { "gold" }
status { "pending" }
stripe_id { nil }
factory(:self_gold_upgrade) do
upgrade_type { "gold" }
end
factory(:self_platinum_upgrade) do
upgrade_type { "platinum" }
end
factory(:self_gold_to_platinum_upgrade) do
recipient { create(:gold_user) }
upgrade_type { "gold_to_platinum" }
end
factory(:gift_gold_upgrade) do
purchaser { create(:user) }
upgrade_type { "gold" }
end
factory(:gift_platinum_upgrade) do
purchaser { create(:user) }
upgrade_type { "platinum" }
end
factory(:gift_gold_to_platinum_upgrade) do
recipient { create(:gold_user) }
purchaser { create(:user) }
upgrade_type { "gold_to_platinum" }
end
end
end