Stripe: Expire/Cancel subscription after n payments - laravel

In our app, we create subscriptions for users which is working good, subscription can vary on type of plan. But I am not able to figure out how to cancel subscription after user has fully paid.
Is there any parameter we can tell stripe at the time of creation of subscription that tells it when subscription should cancel OR tell it to cancel it after n number of payments?
So essentially if customer bought a product which costs 1000, we would charge him 100 a month but then automatically cancel subscription once he has fully paid.
Thanks for the help

I answered this here: Stripe cancel subscription at specific date
Stripe just added this to their API and I happened to stumble upon it. They have a field called "cancel_at" that can be set to a date in the future. They don't have this attribute listed in their documentation since it is so new. You can see the value in the response object here:
https://stripe.com/docs/api/subscriptions/create?lang=php
I've tested this using .NET and can confirm it sets the subscription to expire at value you provide.

When you create a subscription in Stripe, there is no way to tell Stripe to stop the subscription after N months or when a given amount in reached.
From the documentation:
By default, a subscription continues, and the customer continues to be
billed, until it’s canceled
So what you could do is to cancel the subscription once a given condition is met.
You could use webhooks to get notified every time the customer is billed, at the end of every billing cycle, using the invoice.payment_succeeded event (documentation here).
Somehow you could keep track of the total amount paid by the customer in your database and the amount that is left before the item you sell is "fully paid".
Everytime you get the webhook, you increment the total and, if the required amount in reached, you cancel the subscription so that the customer will not be billed the next month.

Related

Laravel cashier swapping taking immediate effect

As per the documentation swap() method swap the current subscription with the new one on the next billing date, means after end of current plan. And swapAndInvoice() will take immediate effect without waiting for the current plan to end.
But the swap() method is not working as described. It is taking immediate effect.
$subscription_result = $user->subscription('primary')->swap('new_price_id');
This is what I am using to swap subscription.
example
,
Plan A :- 3 days ($3)
Plan B :- 7 days ($7)
User subscribed to Plan A on 25th March, next billing cycle is on 28th March.
User changed subscription to Plan B on 25th March, it should take effect on 28th (using swap() method). But it is taking effect immediately and showing next billing cycle is on 1st April.
I have tried using swapAndInvoice() instead of swap(), but both the methods are giving same output, no difference.
The reason for this behavior is not related to the swap() method specifically, but instead to how Subscription upgrades and downgrades behave. When you update a subscription to a price with a different interval than the previous price (like with your example a 3 day interval vs. 7 day interval), then the billing_cycle_anchor will be reset immediately and a new invoice will be generated. The swapAndInvoice() method will cut a new invoice at the time of the Subscription update regardless of whether the intervals of the price update stay the same. Whereas just using swap() in the case where the interval of the two prices are the same would result in an invoice not being created until the next natural billing cycle.
The Stripe API way to accomplish your use-case here would be to utilize Subscription Schedules. However, Cashier may not support this feature directly.
I ran into this same issue, but might have found a workaround. I'm still testing it myself so bear that in mind.
In short, it's not Cashier that's the issue, Stripe's default behaviour when billing period changes in a subscription is to charge immediately. (If it was the same billing period however, it would charge in the future. Unfortunately not what we need here.)
https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#immediate-payment
However, Stripe is designed to handle multiple subscriptions per user! Cashier auth()->user()->subscription() will always pull their most recent subscription so it works nicely.
Cancel their existing subscription (stripe will attach a "grace period" until their scheduled expiry date).
Get default payment method
Create a new subscription (with a trial period of however long was left on the last subscription. You'll need this date saved somewhere).
I added 'proration_behavior' => 'none' as $subscriptionOptions (dug in the code to find create() accepts more than one parameter). Unsure if this is what made the difference, but haven't tested yet without it.
You will have to manage the actual "expiration date" yourself somewhere, which is fine because you will need this date somewhere for #3 anyways. Just ensure your date updating is accurate.
Code Ex.
auth()->user()->subscription('default')->cancel();
$payment_method = auth()->user()->defaultPaymentMethod()->id;
auth()->user()->newSubscription('default', $plan->stripe_plan_id)
->trialDays(45)
->create($payment_method, [], ['proration_behavior' => 'none']);
return redirect()->route('billing')->withMessage('Subscription successfully changed');
Note: Your "trial_ends_at" date under subscriptions table will be inaccurate. I'm recommend using "trial_ends_at" under users table which isn't tied to payments when a user registers.

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().

Avoid Braintree recurring-billing for a single subscription

I need to let users choose to block a monthly recurring-bill.
Default subscription options are:
never_expires: true,
number_of_billing_cycles: nil
Is
never_expires: false,
number_of_billing_cycles: 0
the proper update to a subscription to accomplish that? Is 0 allowed as value for number of billing cycles? I want to update the subscription for a single user so that is not paying on the following month
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
You should be able to accomplish your goal through creating a discount. You'll need to create a discount associated with a plan via the Control Panel. However, via the API you'll be able to add a discount to the subscription. Specifically, you should create a discount on the subscription that equals the amount of the subscription in order to bypass a month.
Braintree doesn't really do this (at least, that I can tell...)
The way I would approach a 'free month' sort of thing is to simply do a refund for that month https://developers.braintreepayments.com/guides/recurring-billing/manage/php#refunding-a-subscription

Billing with Authorize.net ARB Billing on specific dates instead of an interval

I have a subscription which happens on four specific dates on during the year according to a custom cycle . I want to get people to subscribe but get billed together on the same day every 2 months. If I set it to 2 month interval everyone gets charged separately according to the day they subscribe . Can a fixed payment date be set with ARB Recurring billing ?
What you need to do is charge the user using the AIM API and pro rate their first payment up to the first scheduled payment date. Then the ARB subscription will take over. That's all there is to it.

Event Before the Record is changed in MS Access

I have an MS Access Form where I have two subforms. I need to be able to run a code/query before the record is discarded.
This DB is for tracking a hotel's sales and payments. The bounded form has the following layout:
First we have the main form with global fields like, ClientID, client name, address, bill date, restaurant bill, spa charges, etc.
Then I have the rooms subform (Datasheet view). This form has all rooms allotted to the guest. It also has the number of days charged and Rate fields.
Lastly I have a payments sub form (DataSheet View). It has all payments received from the guest. Last Tab index is for the payments Subform. I need to find the total amount the customer was billed. (sum of all room rate X number of days + Money Spent in Spa + Restaurant Bill). I also need to find the sum of all payments. If the total payment is different from total bill then I need to prompt the Operator to confirm the addition.
I know the VBA codes and queries to process the above. But what I do not know is how to trigger this event. I tried AfterUpdate, but it is fired the moment I move to any Sub Form. I need the code to run after the Operator has made all changes and is ready to move to the next record. I am at a loss on how to accomplish this.
You could just place the function in the after update of the last field in the operator's workflow on the last subform?
Alternatively, place a check to run the code on your move next/prev buttons to ensure the operator has completed the entirety of the workflow?
Could you post a ss of the form(s) so I can get a visual picture :)?

Resources