mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
supporter ban auto-refund
This commit is contained in:
parent
1584bb0865
commit
ca428a22da
1 changed files with 16 additions and 0 deletions
|
@ -562,6 +562,7 @@ class Site < Sequel::Model
|
||||||
self.banned_at = Time.now
|
self.banned_at = Time.now
|
||||||
save validate: false
|
save validate: false
|
||||||
destroy
|
destroy
|
||||||
|
account_sites_dataset.exclude(id: self.id).all.each {|s| s.ban!}
|
||||||
end
|
end
|
||||||
|
|
||||||
def ban_all_sites_on_account!
|
def ban_all_sites_on_account!
|
||||||
|
@ -1350,6 +1351,21 @@ class Site < Sequel::Model
|
||||||
if stripe_paying_supporter?
|
if stripe_paying_supporter?
|
||||||
customer = Stripe::Customer.retrieve stripe_customer_id
|
customer = Stripe::Customer.retrieve stripe_customer_id
|
||||||
subscription = customer.subscriptions.retrieve stripe_subscription_id
|
subscription = customer.subscriptions.retrieve stripe_subscription_id
|
||||||
|
|
||||||
|
if is_banned
|
||||||
|
latest_invoice = Stripe::Invoice.retrieve subscription.latest_invoice
|
||||||
|
|
||||||
|
payment_intent_id = latest_invoice.payment_intent
|
||||||
|
if payment_intent_id
|
||||||
|
payment_intent = Stripe::PaymentIntent.retrieve(payment_intent_id)
|
||||||
|
|
||||||
|
if payment_intent.charges.data.any?
|
||||||
|
charge_id = payment_intent.charges.data.first.id
|
||||||
|
Stripe::Refund.create({ charge: charge_id })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
subscription.delete
|
subscription.delete
|
||||||
|
|
||||||
self.plan_type = nil
|
self.plan_type = nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue