I'm working on a project that aims to charge user by request. He will have an account, and monthly a receipt should be sent to him describing how much of the service he used on the month. Is there some gem or documentaion about this?
My concern is about just registering as a legitm use, when the request completes correctly, so as to avoid charging him error requests. I believe its a very careful part of the application. Have anyone seen anything about this?
I don't think you'll find a gem for that. Probably you'll end up creating a Rack middleware and add it to the end of the middlewares chain, check if the status code is 200 and increment the user's usage counter.
Related
I am using Stripe gem in my rails application, it's working fine in the development environment but in my production environment getting an exception.
Stripe::APIError: (Status 409) with message There is currently another in-progress request using this Idempotent Key (that probably means you submitted twice, and the other request is still going through).
How can I rescue this or handle this exception?
Any help would be appreciated.
The retry logic is supposed to be for when your application doesn't know Stripe's response, primarily during network issues likes timeouts. In this case your server received a response from stripe and one of two things could be happening. Either you're retring the same event that is currently in progress /or/ the event in progress is actually different than the one you're trying but given some issue in your application stack you actually chose the same indempotency token for two api requests.
For further details please read this link :- https://stripe.com/docs/api/idempotent_requests
I am currently using gon gem to load the client_token in braintree.
Below shows the controller methods:
def new
#rental_info = display_rental_info(params[:rental_request_new_form])
#product = Product.find(params[:rental_request_new_form][:product_id])
gon.client_token = generate_client_token
end
private
def generate_client_token
Braintree::ClientToken.generate(customer_id: current_user.braintree_customer_id)
end
Soon enough, I realised the potential problem of this way. If the connection to Braintree is slow, it will just hold the request and block all other requests. Sometimes (in a rare probability), it will take 6-10s to load the request. And one time it actually result in Net::OpenTimeout - execution expired error after waiting for 60seconds..
I wonder what is a good way to come around this and prevent it from blocking other requests
I work at Braintree. The response times that you are seeing for our ClientToken.generate endpoint are unusual for our production environment, but may be experienced in our sandbox environment. I would suggest that you reach out to our support team to further diagnose this issue.
Further, calling out to Braintree in a single request should not block other requests to your web server. Web servers handle multiple requests concurrently. If you attempted to make the call to ClientToken.generate asynchronously, it would allow you to do other server side processing for this request while the Braintree token is being received, but I would weigh the benefits of parallelizing the processing for a single request before committing to the additional complexity.
since all other posts seem to be out of date or not presenting good solutions:
My web app uses the gem "Devise" for people to register on my website.
Attack Description
I noticed that every few seconds somebody send a new registration with a different email address. I don't know if every request came from the same or a different IP since my heroku logs show only the latest logs and my SendGrid account is blocked.
What are good solution to stop attacker from sending multiple registrations?
I think one solution would be to add captcha.
Look at this:
https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise
The second, more complicated solution would be to try to block IP addresses.
Make a table of regestration attempts and if there are many registrations form the same ip block it. (ban the user, see link below)
I would also make sure he does not know it failed, make him think the registration was successful.
https://github.com/columbusrb/conclave/issues/16
I am Developing a new warehouse integration for the company I work for as there was not existing solution.
I have gotten almost every feature to work including
fulfillment request and stock requests and even registered a carrier service for real time shipping rates however for some reason i can not get the
/fetch_tracking_numbers call to fire from shopify according to the documentation
"Once per hour Shopify will make a request to this endpoint if there are any completed fulfillments awaiting tracking numbers from the remote fulfillment service."
however I have added logs to the call so i can trouble shoot it however it seems that shopify never makes this call to the server.
If I visit the url myself i can fire the code (logs and all) however it doesn't seem like shopify is doing so
In the install I made sure to provide a valid call back url (thats why fetch stock works fine) and set the tracking support field to true but still nothing
One way to be sure would be ensure that a product's variant is set to your custom fulfillment company. Then complete a bogus order for the product. Now fulfill it. Once you have fulfilled it, Shopify will poll your end point for order's and their tracking numbers. It works fine for me... but I am thinking maybe you're waiting for Shopify and nothing is actually fulfilled.
I am probably too late to answer this but Shopify will make calls to this only if
1) you have "completed" fulfillments
2) tracking number for this completed fulfillments is pending.
You need to mark "complete" a fulfillment after shipping all the order line items
I have an API where users can create, what I call, orders.
I enqueue those orders and process them via Sidekiq gem. When the process is done, I currently send an email to the user. However, I am looking on how to notify him programatically.
So, sending the user a POST request to a particular endpoint, telling him that the order has been processed.
I am wondering which kind of security or other technical things I should take into account when doing this, or if there is any kind of gem that would help me on developing this.
you can check pub/sub pattern to do this...
when sidekiq finish processing then you publish an event... and you register the browser to listen to this event... which is better than sending the user a POST request to a particular endpoint, telling him that the order has been processed.
there are many libraries out there that can help you implementing the pub/sub pattern check the following...
PubNub
Pusher
Bunny
RabbitMQ
Redis
please note that you will have to use the rails app as the publisher and the front end as the subscriber ( you can check equivalent libs for JS )
and if you are interested in implementing the pub/sub within the same rails app... i've looked a lot and found that only those are the working solutions ( for app to publish and listen to his published events without getting locked in the process )
EventBus
Event_BG_Bus
Wisper
this is a post on how to use those gems to implement pub/sub pattern