Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe 503 error - illegal IP 127.0.0.1 webhook problems

I'm working on setting up a webhook from Stripe. Essentially because it's a subscription model and I need to know if I shall keep on renewing the month or not. I'd like to do that through the event 'invoice.payment_succeeded'.

When I test my webhook url in stripe I get this:

host localhost:3000 resolves to illegal IP 127.0.0.1

my full endpoint is:

localhost:3000/hooks/receiver

route:

get 'hooks/receiver' => "hooks#receiver"

and the hooks controller looks like this:

class HooksController < ApplicationController
 require 'json'
 Stripe.api_key

 def receiver
  data_json = JSON.parse request.body.read

  p data_json['data']['object']['customer']

  if data_json[:type] == 'invoice.payment_succeded'
   make_active(data_event)
  end 

  if data_json[:type] == 'invoice.payment_failed'
   # something make_inactive(data_event)
  end
end

def make_active(data_event)
 @user = User.find_by_customer_token(data['data']['object']['customer'])
 @status = @user.statuses.pluck(:list_id).presence || -1
 Resque.enqueue(ScheduleTweets, @user.token, @user.id, @status)
end

 def make_inactive(data_event)

 end 
end

Does anybody know how to fix this?

like image 978
sja Avatar asked Dec 04 '22 04:12

sja


1 Answers

You cannot use 127.0.0.1 or localhost as a webhook in Stripe. A webhook involves Stripe sending data from their serves to yours, but your 127.0.0.1 isn't available to Stripe since only you can access localhost.

like image 128
Matthew Arkin Avatar answered Dec 25 '22 00:12

Matthew Arkin