mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 09:42:36 +02:00
try to fix stripe webhook
This commit is contained in:
parent
496385438a
commit
f687b7becd
2 changed files with 24 additions and 14 deletions
|
@ -1,3 +1,23 @@
|
||||||
|
def stripe_get_site_from_event(event)
|
||||||
|
customer_id = event['data']['object']['customer']
|
||||||
|
customer = Stripe::Customer.retrieve customer_id
|
||||||
|
|
||||||
|
# Some old accounts only have a username for the desc
|
||||||
|
desc_split = customer.description.split(' - ')
|
||||||
|
|
||||||
|
if desc_split.length == 1
|
||||||
|
site_where = {username: desc_split.first}
|
||||||
|
end
|
||||||
|
|
||||||
|
if desc_split.last.to_i == 0
|
||||||
|
site_where = {username: desc_split.first}
|
||||||
|
else
|
||||||
|
site_where = {id: desc_split.last}
|
||||||
|
end
|
||||||
|
|
||||||
|
site.where(site_where).first
|
||||||
|
end
|
||||||
|
|
||||||
post '/stripe_webhook' do
|
post '/stripe_webhook' do
|
||||||
event = JSON.parse request.body.read
|
event = JSON.parse request.body.read
|
||||||
if event['type'] == 'customer.created'
|
if event['type'] == 'customer.created'
|
||||||
|
@ -14,16 +34,7 @@ post '/stripe_webhook' do
|
||||||
end
|
end
|
||||||
|
|
||||||
if event['type'] == 'charge.failed'
|
if event['type'] == 'charge.failed'
|
||||||
|
site = stripe_get_site_from_event event
|
||||||
EmailWorker.perform_async({
|
|
||||||
from: 'web@neocities.org',
|
|
||||||
to: 'kyle@neocities.org',
|
|
||||||
subject: "[Neocities] charge.failed debug",
|
|
||||||
body: event.inspect
|
|
||||||
})
|
|
||||||
|
|
||||||
site_id = event['data']['object']['description'].split(' - ').last
|
|
||||||
site = Site[site_id]
|
|
||||||
|
|
||||||
EmailWorker.perform_async({
|
EmailWorker.perform_async({
|
||||||
from: 'web@neocities.org',
|
from: 'web@neocities.org',
|
||||||
|
@ -34,8 +45,7 @@ post '/stripe_webhook' do
|
||||||
end
|
end
|
||||||
|
|
||||||
if event['type'] == 'customer.subscription.deleted'
|
if event['type'] == 'customer.subscription.deleted'
|
||||||
site_id = event['data']['object']['description'].split(' - ').last
|
site = stripe_get_site_from_event event
|
||||||
site = Site[site_id]
|
|
||||||
site.stripe_subscription_id = nil
|
site.stripe_subscription_id = nil
|
||||||
site.plan_type = nil
|
site.plan_type = nil
|
||||||
site.save_changes validate: false
|
site.save_changes validate: false
|
||||||
|
|
|
@ -2,9 +2,9 @@ Hello,
|
||||||
|
|
||||||
We're writing to let you know that Neocities has had an issue charging your card. We will try again automatically in a few days, but we just wanted to give you a heads up in case something is wrong with your card.
|
We're writing to let you know that Neocities has had an issue charging your card. We will try again automatically in a few days, but we just wanted to give you a heads up in case something is wrong with your card.
|
||||||
|
|
||||||
We will retry over the next few weeks. If we can't make a successful charge, your account will be downgraded from supporter to the free plan.
|
We will retry over the next few weeks. If we can't make a successful charge, we will automatically switch your account over to the free plan.
|
||||||
|
|
||||||
If you need to change the card on file, you can do so on the settings page. If you run into any issues, please contact us at https://neocities.org/contact.
|
If you need to change the card on file, you can do so on your account settings page. If you run into any issues, please contact us at https://neocities.org/contact.
|
||||||
|
|
||||||
Regards,
|
Regards,
|
||||||
- The Neocities Team
|
- The Neocities Team
|
||||||
|
|
Loading…
Add table
Reference in a new issue