Re-Authorize Stripe PaymentIntent before Expiration - ruby-on-rails

I am using Rails 7 and the Pay gem to create an auction/bidding website. A user places a bid, and through pay gem/stripe I am setting up a PaymentIntent and setting the capture_method as "manual". If the user is outbid then we cancel that PaymentIntent and setup a new one for the new bid. When the user wins the bid then we capture that PaymentIntent. All works well for a use case where bids are flowing in regularly.
But in testing I have come across the situation where the PaymentIntent is automatically canceling after a 7 day expiration period. There could be a situation where the auction goes for a month and so the first few bid(s) sit there for more than 7 days and I would rather them not be canceled.
Is it just a simple solution as setting up a delayed job that runs before 7 days where it cancels and creates a new PaymentIntent? Seems like it's straight forward but I worry about the users credit card statement and seeing authorized charges coming in and out.
Looking through Stripe documentation I know that if using Terminal you can request an extended_authorization, but we aren't using Terminal obviously. But not seeing a way to reauthorize instead of capture a PaymentIntent

Overall you have two options:
Cancel and re-authorize as you stated. Yes this can lead to confusion for the Ccstomer if they see multiple auth's on their statement. It is up to the issuer for when they drop those canceled auth's off the statement.
Use a SetupIntent to collect a payment method ahead of time and then charge it once the bidding is complete. The challenge here is that there is a chance that the payment method is set up successfully but then the issuer decides to decline the actual charge at which point you would need to bring your customer back on-session to collect a new payment method and charge that one.

Related

Ruby on rails. Monthly subscription best practices

Hello I have a monthly subscription on my app using Braintree which is working ok. I would like some advice on best practices for the event where payments aren't made on time for whatever reason.
I currently have a User model with subscribed:boolean subscribeddate:date and subscribedend:date.
When a user completes payment through braintree, the attributes get updated to subscribed:true subscribeddate:Date.today and subscribedend:Sometime_way_in_the_future .
When a user cancels a subscription, the attributes get updated too, subscribed:false and subscribedend:(a braintree attribute, billing_due_date)
This way I can filter things in my app according to dates and subscription status. The only problem I can see with this is if Braintree tries to charge an account one month but fails. Braintree has an attribute for this (.days_past_due), but my app has no way of knowing whether this has occurred or not.
What are the best practices for this? Should I do a scheduled task each day to check if every single user has a value for the .days_past_due attribute on the Braintree server? Would this not be incredibly slow if I have a lot of users?
I may be going about this all wrong and I'd just like a bit of advice on the matter,
Thanks.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support#braintreepayments.com.
Your best bet is going to be to implement Braintree's recurring billing webhooks. Webhooks send you a notification via HTTP POST whenever an event occurs that may not have been directly triggered by an API call—such as a customer getting charged via their subscription, a subscription getting canceled, or a subscription going past due. This will allow you to directly respond to subscription events, without having to perform daily checks to see if any changes have occurred.
To use webhooks, you need to choose which events you want to receive webhooks for, designate an endpoint on your server where we'll send the notifications, and set up that endpoint with code to parse the webhook notification into a useable form. For details, see this guide with instructions.

Subscriptions in Stripe - if a subscription payment didn't pan out

I'm working on a Rails app where I'm using stripe for creating subscriptions. Suppose, the first month the user has been charged successfully but on the second month their bank card got expired or ran out of money and they, obviously, weren't charged. How would I, as an admin of that Rails app, know if such the case has happened with one of my users?
Check api for callback after payment process, there must be something which would notify your app regarding payment(if it was succesfull or failure), and afterwards do some actions.

Rails & Stripe: Is it possible to let user pay an amount monthly until they completed the amount?

For example the user needs to pay $2000,
and I want to let them pay the $2000 in 5 months, and then complete the payment not charge them anymore.
This is the closes I have came close to, please let me know if this is wrong:
1- Create Subscription plans for the amounts of payment.
2- Creating a delayed job to cancel the subscription after the 5 month.
Will this be risky to do so ?
Thanks,
Yes, that's exactly how you'd want to handle it. To be more detailed...
First, you'll need to have a web hooks endpoint:
https://stripe.com/docs/webhooks
Next, you'll want to subscribe the customer to a plan like normal. We'll notify your site, via the web hooks, of when payments are made on a recurring subscription. Specifically, you'll want to watch for invoice.payment_succeeded events:
https://stripe.com/docs/api#event_types
Once a specific customer has hit the right number of payments (which you'll track on your end), you'd then issue a cancel subscription request:
https://stripe.com/docs/api#cancel_subscription
Hope that helps!
Larry
PS I work on Support at Stripe.

How to Integrate Authorize.Net ARB and AIM together

I want to Integrate Authorized.Net ARB and AIM together using rails.
Actually, I want Instant payment when user signs up today and I want the subscription to start today. for this i want to charge their first payment via the AIM API. and if AIM tranaction get succeed then only i will create ARB.I write code for both my ARB works perfect but when i write code for the AIM it gives error This transaction has been declined but when i create an ARB with same card it works perfectly.I really don't know how to go for this.
Also I want to know when subscription is declined when processing a future scheduled payment is Authorize.Net cancelled that Subscription or try again on next day?if it try next day again how many times it will try? Can I check or write a code using SILENT POST that after 5 times it's subscription should get cancelled.
ARB performs no validation of a credit card when a subscription is created (other then validating the card has a valid card number format, properly formatted expiration date, etc and won't expire before the first payment is scheduled for). Therefore you have to use AIM to validate the card first, either by running a transaction or performing an AUTH_ONLY, and then if it is successful establish the subscription with ARB. Basically once you get that decline from AIM your script should abort and notify the user of the error and have them try again with a new credit card.
If a subscription payment is declined the subscription will be suspended. If you update the subscription before the next scheduled payment is due the missed payment will automatically be attempted again and if successful the subscription will be active again.
There is no way through any current API to check the status of a subscription. It currently can only be done through the control panel. It is on their to do list so this may change in the future.
UPDATE 2011-12-01
The ARB API now offers the ARBGetSubscriptionStatusRequest call to get a subscription's status.

Paypal subscriptions IPN - problem with users subscribing multiple times

I'm using paypal subscriptions and the instant payment notification (IPN) to handle subscribers on my site.
For the most part it works well but there is one occasional problem I've encountered.
Usually if a user cancels their subscription, I wait for the "end of term" (subscr_eot) notification before disabling access to my site.
So if they prepay for the whole month, and then cancel right away, they still have access for the rest of the month (as it should be).
But some users are having this problem where they:
Cancel their subscription
Before the "end of term" is reached they decide to re-subscribe
When the "end of term" is reached for their first subscription, my app receives the notification and fires off an email to the user with something like "your account has been disabled, if you ever want to sign up again, you can re-subscribe by clicking here".
This confuses them because they are thinking...that's weird, I thought I subscribed like a week ago (and they did). So they go subscribe AGAIN. Now they have two concurrent running subscriptions to my site and I get a support email in a month or two ("wtf you billed me twice this month jerk!!")
So I haven't found a good way to fix this. I guess the best solution would be to do an additional API call when the "end of term" notification is received which asks paypal "hey did this person already re-subscribe?". If so then no need to fire off that email. But I haven't seen any way to do this API call yet.
Another solution is to disable their account immediately when they cancel (the "subscr_cancel" notification) but then I get different angry support emails "hey I prepaid for the whole month why was my account disabled already!!".
Anyone else solved this?
I know this is an old thread, but I haven't seen an actual answer to this question, so if someone happens to wonder across this like I did, here's a solution.
If someone cancels their account (subscr_cancel) before their end of term (subscr_eot) I would set it up in my database to handle it. For instance, if you have a "Users" table in your database, just add a new "int" field and call it "Term." By default, this field should be set to "0." Then, inside of your IPN, set it up so that if a user cancels their subscription before the end of the term, it sets the "Term" field for that user to "1." If that user goes back and re-subscribes to your services, have the IPN update the "Term" field for that user back to "0."
Then, inside of your mailing script, just have it check the "Term" field for that user when it runs for the end of term. If it's set to "0" then don't send the email. If it's set to "1" then send the email saying, "Adios!"
As far as I know there is no paypal api to examine subscriptions if you are using website payment standard/pro buttons, which I assume you are.
I deal with this by keeping the active/cancel/resubscribe state in my database and update the state based on the IPN messages I get from paypal. I map the IPN messages to my uses with the custom field in the button, which is sent back on every IPN message.
There are also a lot of third parties which help you manage this process since paypal's api is a little weak in this area. Recurly is one I've looked at and plan to implement, and there are others out there as well.
Cite: Re: When is subscr_eot issued?
If you started accepting subscriptions after November 2009, the subscriber ID's will start 'I-' - and will not return a 'subscr_eot' at the end of their time. Paypal expect you to keep note of how long they are subscribed for and update the account to downgrade (or whatever) when that period expires, unless the customer pays again in the meantime.
How to prevent duplicate PayPal payments?
You would want to add a unique identifier to the "invoice" parameter; and enable "Block duplicate payments" within the 'Profile' > 'My selling tools' section on your account at www.paypal.com

Resources