Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jasd's avatar
Level 1

Laravel Cashier and other Payment Methods

Hey, I am planning on using Stripe for subscription, but also manually paying through some other payment method like Swish (mobile payment) that is later manually activated.

Does it still make sense to use Billable contract to handle this kind of alternative subscription, like:

if ($user->subscribed()) { }

How should I set this up in my database?

users subscriptions (billable contract on this model?) payment_types (?)

0 likes
5 replies
MikeHopley's avatar

Cashier itself only works with Stripe payments. Looking at the Billable contract code, it seems to be heavily based on Stripe. For example, it has a method called getStripeSubscription(). I would say it's not really a contract; it's an implementation using Stripe.

While you could implement this Billable contract, you'd need a whole lot of "dummy" (empty) methods that don't make any sense. This doesn't seem like a good fit.

It might make more sense to define your own Billable interface, with the methods that your application requires for its payment process. You'll have to think about whether this even makes sense though -- are the payment methods similar enough in their fundamental actions?

In case it's helpful, I can share my setup (which is not perfect but does work). Bear in mind that your needs may be different...

I have a BillingInterface with only one method:

<?php namespace BBapp\providers\payment;

use BBapp\providers\payment\SubscriptionPlan as Plan;
use BBapp\models\User;

interface BillingInterface {

    public function startSubscription( Plan $plan, User $user, $token );

}

...where $token is the authentication token from Stripe, Paypal, etc.

I have a SubscriptionManagerInterface that defines actions on existing subscriptions:

<?php namespace BBapp\providers\payment;

use BBapp\models\Subscription;
use BBapp\providers\payment\SubscriptionPlan as Plan;
use BBapp\models\User;

interface SubscriptionManagerInterface {

    // Stop the subscription payments (can be resumed, will cancel at term end)
    public function stop( Subscription $subscription );

    // Resume the subscription after it was stopped
    public function resume( Subscription $subscription );

}

Each of these has a Stripe implementation. I will also add Paypal when I get time, but for now it's just Stripe.

As for the logic for querying subscriptions -- e.g. "does this user have an active subscription?" -- well, I just shove it all on the User model: $user->hasActiveSubscription(), etc. It works fine. You could of course add more abstraction if you feel the need.

1 like
jasd's avatar
Level 1

Thank you for your reply. I've been sketching some on this through the day, what do you think?

payment_types Stripe Swish

subscriptions user_id payment_type_id expires_at cancelled ...etc

The "Subscription" would be the model which can be checked if an subscription is active, etc.

To start/resume/cancel a subscription I would have a Interface "SubscriptionManager" as you typed above.

I would have a Factory class which resolves a SubscriptionManager with the correct class (i.e. one to handle Stripe, and one to manually do it)

The problem left is, where would I store any potential tokens, i.e. a Stripe needs a creditCardToken, and I guess Paypal maybe needs one that belongs to a user,

payment_token payment_type_id user_id token

Maybe?

MikeHopley's avatar
Level 17

That all sounds good to me. :) I like your addition of a factory class for resolving the SubscriptionManager. I was planning to do something like that but never got around to it.

As for the tokens -- these are not meant to be stored. They are single use. So I would not put them on a database.

Stripe sends you a token as part of the payment process, and Paypal's new REST API requires a token for authentication with the API (at least, it did when I last dabbled with it, but it was incomplete then).

jasd's avatar
Level 1

Alright then! Thank you for your thoughts and ideas! Much appreciated!

Please or to participate in this conversation.