So you built an app and want to introduce a more flexible way of pricing it. Some features are less expensive for you as a business, and others are more expensive. Or maybe you want to introduce a new feature but charge for it separately? For cases like this, and many others, a very good solution is to sell different types of credits used for different areas of the system. Let's see some of the benefits of doing so, and how you can easily implement it in your application.

Why sell credits in the first place?

If you're selling access to an API, or an expensive process that can be repeated multiple times, it makes sense to sell it not as a flat-fee unlimited use, but as credits.

  • Users can decide how much they want to spend. This includes both spending less, and spending more! If you're limiting your users to just X number of actions per month, you might be leaving money on the table from power-users who would be willing to pay more for extra credits.
  • Users are less stressed. Depending on your configuration, the credits purchased can be held on the account forever, allowing users to take a break stress-free and come back later, knowing their invested credits will not go to waste.
  • Helps avoid malicious usage. Countless cloud software can be abused by subscribing for a single month, getting all the data you need, and cancelling the subscription. With credits, though, you get a natural rate-limiter in that your users can only consume as much as they have purchased credits. If they need a lot of data/processing from your app, they will have to buy more credits.

So, now that you're convinced you should sell credits rather than an all-inclusive access fee, let's see how you can use multiple types of credits in your app to better segregate different features based on their cost.

How do multiple credit types help your users?

There's a few ways that having multiple credit types (or currencies, but let's stick to credits in this article) will help your users:

  • Cost efficiency: having different credit types means developers can buy more of what they actually need, thus saving money and seeing more value from your application.
  • Convenience: If you have multiple types of credits, you like have lots of features to sell as well, and developers love an all-inclusive platform, because it's convenient, and credits allow you to better price all the different features you offer.

How do multiple credit types help your business?

Your business also improves by offering different types of credits:

  • Increased revenue streams: by offering a variety of credits, your business can cater to a broader range of customers and needs, which can increase the customer base and boost revenue.
  • Customer retention: a platform that offers everything a user needs for its digital operations is more likely to retain customers, as it provides a one-stop solution, reducing the likelihood of customers switching to competitors.
  • Cross-selling and data insights: having customers use multiple services on the same platform provides valuable data on customer behaviour and needs. This data can be used to improve your services, create targeted marketing campaigns, and cross-sell products effectively.
  • Operational efficiency: managing one platform for multiple services can be more efficient than operating separate services, leading to reduced costs and increased operational efficiency.
  • Predictable scaling: by selling credits, your revenue is much better correlated to your costs. As users buy more credits, they will need more processing power from you to use those credits.
  • Avoid non-paying customers: if you charge for your service in advance, i.e. selling credits for future-use of your service, then there's never going to be an issue with someone not paying for the services provided. They already pre-pay for your services by buying credits.

Lots of benefits to the business, you see. OK, so you should definitely sell multiple types of credits, but how?

That's where the amazing Laravel package comes in, called Spike billing.

Setting up multiple types of credits

If you're using Spike already (if not, snatch a license here), configuring multiple types of credits is as easy as adding a few lines of code to the Spike configuration file config/spike.php

'credit_types' => [
    [
        'id' => 'credits',
        'translation_key' => 'spike::translations.credits',
        'icon' => null,
    ],

    // let's add a new credit type - SMS
    [
        'id' => 'sms',
        'translation_key' => 'app.sms',
        'icon' => '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M10.5 1.5H8.25A2.25 2.25 0 0 0 6 3.75v16.5a2.25 2.25 0 0 0 2.25 2.25h7.5A2.25 2.25 0 0 0 18 20.25V3.75a2.25 2.25 0 0 0-2.25-2.25H13.5m-3 0V3h3V1.5m-3 0h3m-3 18.75h3" /></svg>'
    ],
],

config/spike.php

In the example above, we have added an sms credit type, which we can later use to sell SMS credits to users, and to consume them when sending SMS messages. We used an SVG string to easily give an icon unique to this credit type.

From this point on, your users will see their balance of SMS credits automatically. Now, let's sell them.

Selling multiple types of credits

In order to sell the new SMS credit that we configured above, we simply need to update our subscription or product configurations inside the same config/spike.php file, adding another CreditAmount to the list of providables (think of "providables" as things that a subscription/product provides when purchased).

Here's an example of how we can start selling SMS credits with the standard subscription plan configuration:

use Opcodes\Spike\CreditAmount;

'subscriptions' => [
    [
        'id' => 'standard',
        'name' => 'Standard',
        'short_description' => 'Great for small businesses',
        'payment_provider_price_id_monthly' => 'price_xxxxxx1',
        'payment_provider_price_id_yearly' => 'price_xxxxxx2',
        'price_in_cents_monthly' => 1000,
        'price_in_cents_yearly' => 10000,
        'provides_monthly' => [
            CreditAmount::make(5000),
            CreditAmount::make(100, 'sms'),
        ],
    ],

    // other plans...
],

config/spike.php

See the CreditAmount::make(100, 'sms') we have added above? Now this subscription plan will provide one hundred SMS credits every month, automatically. Easy.

The same can be done when configuring products:

use Opcodes\Spike\CreditAmount;

'products' => [
    [
        'id' => 'standard_pack',
        'name' => 'Standard pack',
        'short_description' => 'Great value for occasional use',
        'payment_provider_price_id' => 'price_xxxxxxxx3',
        'price_in_cents' => 1000,
        'provides' => [
            CreditAmount::make(5000)->expiresAfterMonths(6),
            CreditAmount::make(100, 'sms'),
        ],
    ],

    // other products...
],

config/spike.php

The CreditAmount::make(100, 'sms') added above will provide 100 SMS credits when the "Standard pack" is purchased. The user can even buy multiple packs at once and the appropriate multiple of credits will be provided.

You don't need to update the UI or make any other changes - your users will be able to see the new credits offered by your subscriptions and products when they are looking to purchase something.

Consuming multiple types of credits

Now that your user has bought some SMS credits, how do we consume them? Again, with Spike billing it is as easy as adding one more parameter to credit usage.

When your app has sent an SMS message for this user, simply add this line to consume a number of credits:

$user->credits('sms')->spend($smsMessagesCount);

spending an X amount of SMS credits

Their SMS credit balance will be reduced by the value of $smsMessagesCount.

💡
A side note
With SMS, keep in mind that the cost for you to send that message will depend on character encoding and the length of the message. Check out this Twilio article to learn more. This is why you may want to count the actual cost of the message and take the appropriate number of credits from the user.

What about users who don't have any credits? You can check the balance very easily before taking any expensive action, like sending an SMS message. Here's a typical example you would do:

$smsMessagesCount = 5;

if ($user->credits('sms')->canSpend($smsMessagesCount)) {
    
    // send the message

    $user->credits('sms')->spend($smsMessagesCount);
}

checking first if user has enough SMS credits for sending this message

Want to display their SMS balance somewhere outside the billing portal? Again, very easy:

$user->credits('sms')->balance();

getting the SMS balance for a user

To learn more about spending credits, visit Spike documentation on using credits.

To sum up...

In conclusion, introducing different types of credits for services like APIs can offer numerous benefits to both users and businesses.

For your users, it means greater flexibility and cost-efficiency, allowing them to purchase and consume services according to their specific needs without the pressure of a flat-fee structure.

For your businesses, it translates into diversified revenue streams, improved customer retention, enhanced operational efficiency, and better alignment of revenue with costs.

Implementing a system to sell and manage multiple types of credits can be streamlined with a tool like the Spike billing package, simplifying the process for developers and enhancing the user experience.

By adopting this approach, your business can cater to a wider range of customer needs while also benefiting from a more predictable and scalable business model.

Now, go build something amazing!