Setting up products with Spike
Products are non-recurring purchases. The user can add one or more products to their shopping cart and checkout with a single click. This makes it easy for you to sell bundles of credits, or other products from within Spike.
Displaying the products view
The page to buy products will show up automatically once there is at least one product set up.
You can either add it via config/spike.php
configuration file, or by providing a
custom product resolver.
Hiding the products view
If you would like to hide the products page completely, set the 'products'
to an empty array:
'products' => [],
Adding products via config
In order to make a product available for purchase, you simply add an associative array to the config/spike.php
configuration file. You can add as many products as you'd like.
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,
'currency' => 'USD',
'provides' => [
CreditAmount::make(5000)->expiresAfterMonths(6),
],
],
// other products...
],
Here's a rundown of the attributes:
Attributes | Required | Description |
---|---|---|
id | yes | Identifier of the product. Must be unique. |
name | yes | The name of the product that will be visible to the user. |
short_description | no | A short description of the product that will be visible to the user. |
payment_provider_price_id | yes | Stripe's or Paddle's price_id for this product. Learn how to set up Stripe products. |
price_in_cents | yes | The price of the product in cents. This will be visible to the user in a friendly format. |
currency | no | The currency code for this product (e.g., 'USD', 'EUR', 'GBP'). When specified, overrides the default application currency for this product. |
provides | no | An array of providables that are provided upon purchase of this product. |
Archiving old products
It's OK to remove any outdated products from the config/spike.php
configuration. But if you would like to keep them there for reference, but hide them from the users, you can archive a product by setting the archived
flag to true
.
'products' => [
[
'id' => 'standard_pack',
'name' => 'Standard pack',
'archived' => true, // <== add this line
// other attributes...
],
],
Thank you page
When a user completes the purchase of credits, they will be shown a "Thank you" page in Spike. You can redirect from that page to a different page of your choice after any duration of your choice.
You can do so by adding this line to your AppServiceProvider::boot()
method:
// Will redirect the user to "/custom-thank-you-page" after 5 seconds.
Spike::redirectAfterProductPurchaseTo('/custom-thank-you-page', 5);
The first parameter even accepts a callback which will receive the Opcodes\Spike\Cart
instance where you can find the purchased items/products, if you need that to build the final redirect URL.
use Opcodes\Spike\Cart;
Spike::redirectAfterProductPurchaseTo(function (Cart $cart) {
if ($cart->billable->subscribed()) {
return "/special-subscriber-thank-you";
}
return null; // `null` value will not redirect anywhere.
}, 5);
Multi-currency support
Spike v3 supports multi-currency products, allowing you to offer products in different currencies. When configuring products, you can specify a currency
attribute to override the default application currency for that specific product.
use Opcodes\Spike\CreditAmount;
'products' => [
[
'id' => 'usd_pack',
'name' => 'US Dollar Pack',
'short_description' => 'Credits for US customers',
'payment_provider_price_id' => 'price_usd_xxxxxxxx',
'price_in_cents' => 1000,
'currency' => 'USD',
'provides' => [
CreditAmount::make(5000)->expiresAfterMonths(6),
],
],
[
'id' => 'eur_pack',
'name' => 'Euro Pack',
'short_description' => 'Credits for European customers',
'payment_provider_price_id' => 'price_eur_xxxxxxxx',
'price_in_cents' => 900,
'currency' => 'EUR',
'provides' => [
CreditAmount::make(5000)->expiresAfterMonths(6),
],
],
],
Important notes about multi-currency:
- Mixed currency carts are not allowed: Users cannot add products with different currencies to their cart. If they attempt to do so, they will receive a clear error message.
- Currency validation: The system validates that all products in a cart use the same currency before processing payment.
- Case insensitive: Currency codes are handled case-insensitively (e.g., 'USD', 'usd', 'Usd' are all treated the same).
- Backward compatibility: Products without a specified currency will continue to work as before, using your default application currency.