Rails: Stripe webhooks for `invoice.payment_action_required` & `invoice.payment_failed` - ruby-on-rails-5

I am sending customer emails when i get the events invoice.payment_action_required & invoice.payment_failed.
this causes a email to be sent to the user when they are subscribing for the first time and are on_session.
How do i ensure that the emails are not getting sent the user is subscribing the first time but are only sent when the events happen for recurring payments.
Any help on this would be really great.
Thanks.

You can check the billing_reason of the Invoice in the Event so you can identify and ignore events relating to to the first payment of a subscription(they'd have subscription_create).
https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason

Related

Email addresses automatically getting added to Global Unsubscribe after API send

I have a weird problem where some email addresses are automatically getting added to my Global Unsubscribes after each API send to that address.
The initial email gets sent and delivered, but then the receiving address is automatically added to the group, and any subsequent API sends will cause the email to get dropped immediately. I have to manually remove the addresses every time.
Does anyone have any ideas what could be causing this?
I had the same issue, it seems like some spam filters "click" all the links that are in emails. I also contacted sendgrid support and they confirmed that this might be the case and there is nothing they can do about it.
Unfortunately the only solution I could come up with is a two step unsubscribe, that you have to implement yourself. Creating unsubscribe links that redirect you to your own server, where you add a confirmation step.

Bitcoin transaction verification process

I am building and app which will offer payment in bitcoins. I know that when I send bitcoin from one address to another it can be tracked by blockain API to verify the transaction. After receiving some assets I want to send some assets back. The customer will have an input field where he will paste his deposit wallet address. I am subscribed to blockchain API to track received assets to my bitcoin address. How can I verify that the payment was made by certain customer? Checking his address doesn't seem to solve the problem because if customer uses wallets like Coinbase, Bitstamp etc. transaction is made from multiple addresses.
A few helpers here:
What you need to do is to generate a new address and give it to your customer. This way you can uniquely identify him
Wait for confirmation before making the decision. Just because you see a transaction, does not mean you have the money. You need to wait for a few blocks and several (>6) confirmations

BlueSnap Subscription Fail simulation

Is there any way to simulate bluesnap. what happens when a recurring payment fails, for example, if the user doesn't have money on the card in that moment?
Thank in advance :)
BlueSnap offers IPN (Instant Payment Notification) alerts for events such as declined CC charge for a subscription. This type of IPN is defined as "on demand" - which means you will need to register to receive it in the BlueSnap control panel.
https://support.bluesnap.com/docs/on-demand-ipns
Since the IPNs are messages sent over HTTP, you can choose to send them to your server, and configure a receiver for it there. Once the IPN reached your server it can be parsed by your receiver and you can choose what to do with it, for example:
send an automated email to your customer support or accounting department
send an email to the shopper
log the event in your system for later analysis.
IPNs can also be sent manually, thus simulating this event. For you specific case, the IPN for CC_CHARGE_FAILED can by opening a browser with a connection that can access your server, and putting the IPN in the address line. Your receiver will get the information and respond accordingly.
If you already received an IPN for an actual CC charge failure - use that IPN message as is. If you have not yet received such an IPN and in fact you're just starting out and building your own receiver, you should contact BlueSnap merchant support at merchants#bluesnap.com and they'll send you a sample.

Send message to th all of bots users (telegram api)

how to send Send message to the all of bots users?
There is no way to sned message to all ?
what is the method name ?
From Official API FAQ:
How can I message all of my bot's subscribers at once?
Unfortunately, at this moment we don't have methods for sending bulk messages, e.g. notifications. We may add something along these lines in the future. (...)
Obviously, if you store users chat_id, you can send individual message to all users (I use this method).
Navid wants to send message to all subscribers via bot.
If subscribers are more than 100 persons bot will very slow to sending all messages and may doesn't send messages to all.
Navid's question was how we can send message without this problem?
you can send with curl_multi_exec
Currently, a developer would need to implement a special broadcasting function that would send the message to each active user at the time adding a small delay to avoid hitting the rate limit of 30 messages per second (see https://core.telegram.org/bots/faq#how-can-i-message-all-of-my-bot-39s-subscribers-at-once). This would mean that a very popular bot with say 10K active users cannot give timely notification as the last user would get the message about 5 minutes after the first user.
Here is a feature request to ask to add a method in the Bot API to broadcast a message to all its active users at once. You can upvote this feature request. https://bugs.telegram.org/c/8463

REST API design for endpoint with notification

I am creating an API endpoint which takes a customer order, create the order and send email notification. At our current design once we successfully create the order, we send a success notification 201 to client and then make a call for our internal email api. Upon getting success notification from us the client app shows users a message to check his/her email.
I don't feel comfortable with this design because if for some reason the email sending method failed there are no way for client to understand this. On the other hand if we wait for to successfully the send the email and then send client app success notification it takes longer times.
So what is the right approach for overcoming this problem?
I think your design works. Why would the client care if the mail service is not working? If the order passes all validations on the server and is persisted I would treat that as a successful state and return 201 Created.
When the client gets 201 Created, then do what you say; give the user a message about checking their mail, but tell them that they should have some patience. Something like:
Your order was submitted. Please check your mail. If you haven't got a mail in 24 hours please contact us, "or whatever other solution here".
You have no control on what time the mail will arrive at the users mail box anyway since mail sending is not a synchronous process.
Remember: Seperate your conserns.
202 Accepted would usually be the most appropriate response for a request which requires further processing. In your case, however, this might not be right because the email is not fundamental to the resource creation.
201 Created is perfectly acceptable for you because the order has actually been created. However, as the spec says, you should return a Location header with the URI of the created resource and an entity describing how to access the resource. That should get around your issue with a mail service failure - the client can still access their order and, to be honest, e-mail is not guaranteed delivery so I'm hoping that the email isn't an absolutely required part of your business process.