user upgrades: add links to Stripe payment & receipt page.

Add links to the Stripe payment page and the Stripe receipt page on
completed user upgrades.

The Stripe payment link is a link to the payment details on the Stripe
dashboard and is only visible to the owner.
This commit is contained in:
evazion
2020-12-28 22:25:09 -06:00
parent e29e2da8be
commit 87af02f689
8 changed files with 154 additions and 6 deletions

View File

@@ -198,6 +198,32 @@ class UserUpgrade < ApplicationRecord
checkout
end
def receipt_url
return nil if pending? || stripe_id.nil?
checkout_session = Stripe::Checkout::Session.retrieve(stripe_id)
payment_intent = Stripe::PaymentIntent.retrieve(checkout_session.payment_intent)
charge = payment_intent.charges.data.first
charge.receipt_url
end
def payment_url
return nil if pending? || stripe_id.nil?
checkout_session = Stripe::Checkout::Session.retrieve(stripe_id)
payment_intent = Stripe::PaymentIntent.retrieve(checkout_session.payment_intent)
"https://dashboard.stripe.com/payments/#{payment_intent.id}"
end
def has_receipt?
!pending?
end
def has_payment?
!pending?
end
class_methods do
def register_webhook
webhook = Stripe::WebhookEndpoint.create({