Stripe Custom Recurring Donations - ruby

Let me tell you first that Stripe is working perfectly for me with Sinatra.
The thing is, for recurring payments, i have to create plans on Stripe. I have this requirement on my donations page. It works well for fixed amounts for which i created plans.
My question is what should i do when a user enters an amount like $54 for which i don't have plans in stripe? Do i create plans on the fly for each new donation amount? That seems a little too stretched for me. Is there any other way around this?

The recommended way to do this by the stripe people is to have a subscription for a base amount, and then listen via webhooks for an "invoice created" event. You can then create an invoice item to adjust the amount depending on the user's preferred cost.
The invoice itself is send to the customer an hour after creation so you have that window in which you can add invoice items to adjust the total.
It's explained here...
https://support.stripe.com/questions/metered-subscription-billing
This is not ideal as it would be nicer to have a "set and forget" solution, and it almost seems like the "creating plans on the fly" would be the easier way to go.

Related

Laravel Cashier incrementQuantity() tidy invoicing

Has anybody here dealt with incrementing subscriptions for "admin" users? Also, how do you handle invoicing and first/second-month charges in a neat manner?
I have a use case where users can sign up other subscribers and pay for these subscriptions from their card on file. The "admin" user signs up for the first subscription, and I keep incrementing the original sub every time a new sub is added.
When I send these through Cashier, the user only seems to get charged once, and then the second, third, etc., the first-month cost gets added onto the next month's invoice, and a new line item of unused time every time the admin user adds a new sub. So I first do:
$request->user()->newSubscription()->create();
Then I do:
$request->user()->subscription()->incrementQuantity();
The user only gets charged one monthly charge at newSubscription()->create(), And the next month's invoice has the following math.
(# of Subscriptions x Monthly Charge) - (Monthly Charge)
And the invoice has a ton of line items saying "Unused Time ..." which looks OK if that admin user only has one or two additions to their subscription but gets messy real quick beyond that. This seems super unprofessional and annoying to explain to the admin users. How do you/would you guys go about making this smoother? I understand that the invoicing for the incrementQuantity() method is enforced by the Stripe API, but it doesn't make sense to have so many prorating adjustments in a first invoice.
What is your goal/desired behavior here? Laravel cashier does allow you to change how you want the prorations to behave. By default prorations will be created and pulled into the next invoice, but you can also choose to disable prorations entirely or create prorations and have them immediately invoiced so that the difference is price is paid for immediately.
If you don't want any prorations generated at all when you update the quantity of a Subscription you can use noProrate() (see laravel's docs). Disabling prorations entirely may not be what you want though, since it won't allow you to charge a customer for the difference in price when they update mid-cycle. As an example, if you start off with a quantity: 1 Subscription they'll be charge for just 1 unit at the start of the month. If prorations are turned off and you update to quantity: 5, the customer won't have to pay for the new price until the subscription is renewed. If this is still what you want to do, you'd use it like this: $request->user()->subscription()->noProrate()-> incrementQuantity().
Another option would be to keep generating prorations, but have them immediately invoiced so that they aren't reflected in the renewal invoice at the end of the month. This will result in the customer being invoiced more often, but would solve your issue where the renewal invoice looks cluttered because of all the prorations. You would get this behavior by using alwaysInvoice() like this: $request->user()->subscription()->alwaysInvoice()-> incrementQuantity().

Laravel payment multi subscriptions

I am working on a SAAS project where users can create various projects. With each project, they can choose from 5 different plans. Each plan has its own costs per month. Hotjar is a kind of equal concept.
Now I want to arrange the subscription with Stripe. The problem with that was that a user can have a maximum x subscription, which of course was a shame. Then I decided to take 1 subscription that has several plans. But now I have a dilemma, to update the subscription you have to change the number via SubscriptionItem. Then you have to save yourself which plan has which SubscriptionItem_id for which user. That is quite a detour and can cause many problems.
Someone is a better way with Stripe or another payment software.
You don't necessarily need to store the subscritpion_item IDs, you can look it up via the subscription_item list API. All you need to do is store the subscription_id for your customers, and based on that ID you can retrieve the list of subscription_items:
\Stripe\Stripe::setApiKey("sk_test_9GavlLpfiKewqeCBXvRvmVgd");
\Stripe\SubscriptionItem::all(["subscription" => "sub_EQlPGjVj4o5luH"]);
Then you can handle the data part of the returned JSON object and update / delete / etc these subscription items.
If you only have the customer_id handy, then you can use the subscription list API (with status as well on the GET params) to retrieve the list of active subscriptions.

Zoho data structure setup for e-commerce referral program

Building custom integration for a client with their e-commerce store and Zoho. They essentially have a referral program, for the easiest explanation. When someone purchases, we need to keep track of who the referring person was in Zoho and credit them - I have this all available. They only sell 1 product so we don't need actual financial / sales data, just the number of units attributed to the person in Zoho. They eventually want to be able to have reports generated in Zoho to tell them how many units each person is doing per month, who is their best performer, etc.
All the potential referral people are stored as Contacts in Zoho. My task is simply getting the data from the e-commerce site into Zoho, I do not have to create any reports or anything within Zoho. I have no experience with the Zoho world so I am not quite sure where the best place to even put this data as there are so many different Zoho "things" to use. I thought about using Invoices, but again we don't necessarily need the transaction data just counts and when they happened to produce the above stated reports.
I was finally able to reach someone at Zoho: Sales Orders are the right place to put this.

Laravel Cashier - adding a column that must be updated on subscription create, resume or cancel

I want to provide my users with the ability to lock in their rate for X number of years. However, this is not possible with Stripe API or Cashier. That is why I will have to do it on my application end. To do this I will need a subscribed_at column. I know I can get it straight from Stripe customer's subscription (field current_period_start) but it takes too much time to retrieve it and I will need this functionality quite a lot. So, in my subscriptions table, where I have all of Cashier's needed fields (stripe_id, stripe_active, ..., subscription_ends_at) I want to add this subscribed_at column. Now, I want to automatically update this value anytime a subscription is create, resume, or cancel. On cancel I need to set the value to NULL.
I don't want (and it's not a good practice) to modify Cashier's code. (In StripeGateway.php there is a method updateLocalStripeData() which fires exactly for these three options but as I said I don't want to modify it).
I cannot override the StripeGateway.php method updateLocalStripeData() because my Subscription Model does not extend it.
So far the only solution that worked but which I don't really like is to use Model events saving and there retrieve the subscription's current_period_start field and insert it into my Subscription Model's subscribed_at field.
What other ways to do this?

how can i decrease the product price on cart page?

If the user has an existing account balance, I'd like to give him the option to specify how much of his previous balance to apply to the item and sync this info with the cart and order. I have already implemented the user's account balance, both on the front and back end.
Would a coupon-like system work best, or should I try something else?
Thanks in advance.
I would let the customer decrease its cart total with the balance would be more simple / logic for the customer also (?)
What E-commerce solution do you use? Magento(?) If so there are coupon extensions that can handle this.
You could also build a simple balance system where users would see there balance in there account ( if such feature is implemented) or just mail them a message with a unique code that you save in DB + the value of balance then use this code as a coupon on checkout.
We have created quite a few e-commerce solutions up to date. Usually, when user balance is involved, then what you do is create two transactions referred to one invoice. In the first transaction specify the amount taken from balance, where as leave the other transaction for whatever checkout method you use. Upon callback from the checkout, see if the balance paid matches the invoice to mark it as paid respectfully.
Alternatively, you can use discount - decrease user balance and add "discount" to the order. It all depends on your accounting needs and preferences.
On Amazon they allow you to apply any unused balance to the existing order. Its when you checkout that they say you have $150 credit on your account, would you like to apply this to your order, it defaults to yes in a tick box.
Its quite neat and simple, it doesn't allow you to apply a part amount from what I've seen.
Then when you go to payment you pay $total - balance.
So if you have $200 total, the payment via credit card would be for the $50.

Resources