I have a typical scenario like i have a video model which are paid.
I have stripe integrated for credit card processing. But the problem is how can i check if the user is subscribed and the users payment is not out of date before the user the watching video?
Any ideas how to accomplish this?
Any help would be appreciated.
thanks.
First you need a way to tell if the user is valid. You can do that by keeping track of amount owed, or by using a datetime field such as last_paid_at which you update when the user pays their bill.
In a before_filter for videos, check if the user is invalid. So if the balance > 0 or if it's been longer than a month since the last payment.
Check out Stripe Webhooks to get notified when a payment goes through. Basically webhooks are endpoints where stripe can send you information.
Related
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.
I'm working with stripe. I'm confused: is the only way to charge the user (customer) by showing them the Stripe pop up where they enter in their bank card details and click ok? Is there any way to charge them without having them doing that themselves, let's say, by a cron task which is run once a month on my web server where they're registered?
I'm guessing, there should be a way to do so but they have to do that manually at least once, for the second time their card details are saved at Stripe server and I, indeed, can charge them automatically, is that so?
It sounds like you're trying to do subscriptions, which is a whole Stripe topic in and of itself. You may want to check out Pete Keen's blog (and book). A relevant entry is here - https://www.petekeen.net/using-stripe-checkout-for-subscriptions
This gem may also be helpful - https://github.com/andrewculver/koudoku
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.
In a ruby on rails app I want the ability for a person to donate to my paypal. However, I want to get a callback to know how much they donated. Is this possible with the default paypal 'buy' or 'donate' button, or will I have to use some sort of paypal api. Hopefully, there is some option besides the api.
Any info at all would be much appreciated.
Take a look at Instant Payment Notification (IPN). When IPN is configured PayPal will POST transaction data to a listener script you have sitting on your server. It'll handle payments, refunds, disputes, or pretty much any transaction that hits your PayPal account so you can automate things based on specific events in real-time.
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.