Simple Commerce supports both physical and digital products.
When a product is classified as a Digital Product, customers will receive a link to download their purchased products after checkout. If you're selling software, Simple Commerce also generates license keys for each product so you can verify your purchases using a basic license verification API.
By default, all products are classified as "Physical" products. However, you can easily flip the switch and change a product to a "Digital" product using the Product Type toggle:
After switching to a Digital Product, you'll see two fields appear in the sidebar:
Downloadable Assets
- The files the customer should be able to download after checkout.Download Limit
- The maximum number of times a product can be downloaded. Leave blank for no limit.If you're editing a product with variants, these fields will instead show in the options for each of your variants.
If you'd like to send your customers an email notification after they've purchased digital products, add the following to your config/simple-commerce.php
config file.
'notifications' => ['digital_download_ready' => [\DuncanMcClean\SimpleCommerce\Notifications\DigitalDownloadsNotification::class => ['to' => 'customer',],],],
'notifications' => ['digital_download_ready' => [\DuncanMcClean\SimpleCommerce\Notifications\DigitalDownloadsNotification::class => ['to' => 'customer',],],],
Learn more about Notifications in Simple Commerce.
If you wish to customise the default email view, you can publish it with this command.
php artisan vendor:publish --tag="sc-digital-products-views"
php artisan vendor:publish --tag="sc-digital-products-views"
You'll then find the published views in your resources/views/vendor/sc-digital-products
folder.
If you wish to have full control over the notification being used here, you may simply replace the class name.
Simple Commerce will automatically generate license keys for each digital product that is purchased. This is often useful when selling software, where you want customers to enter a valid license key before they can use your software.
We've included a basic verification endpoint which you can use to check if a customer's license key is valid. Before you can use the endpoint, you'll need to enable Statamic's REST API.
Once enabled, you can simply make a POST request to /!/simple-commerce/digital-products/verification
with a JSON body containing the license key you wish to verify.
{"license_key": "IpebSuXft9Koio5GgP7TSRdtl"}
{"license_key": "IpebSuXft9Koio5GgP7TSRdtl"}
A valid response will look like this:
{"license_key": "IpebSuXft9Koio5GgP7TSRdtl","valid": true}
{"license_key": "IpebSuXft9Koio5GgP7TSRdtl","valid": true}
And an invalid one will be like this.
{"license_key": "IpebSuXft9Koio5GgP7TSRdtl","valid": false}
{"license_key": "IpebSuXft9Koio5GgP7TSRdtl","valid": false}
By default, we create a serial license key which you can give to your customers. However, you may want to customise where the code comes from or maybe you want to send it away to a third party service.
To do this, you can create your own license key repository which implements the one provided by this addon.
To register your repository, you'll need to bind it to our LicenseKey
facade. You can do this in your AppServiceProvider
.
$this->app->bind('LicenseKey', App\Repositories\LicenseKeyRepository::class);
$this->app->bind('LicenseKey', App\Repositories\LicenseKeyRepository::class);
Every time a customer downloads a product, Simple Commerce keeps track of it. We store the timestamp & the customer's IP address for reference.
The download history log looks like this:
items:- product: d113c964-d254-4f6b-931b-686348f36af5quantity: 1total: 9000id: a50a22d3-432f-4b6c-85db-48ea7ba92036license_key: COt2IXuPqP6VTg3cfXmqQmP0download_url: 'blahbla.test/link-for-download'download_history:- timestamp: 1613228831ip_address: 127.0.0.1- timestamp: 1613228828ip_address: 127.0.0.1- timestamp: 1613228746ip_address: 127.0.0.1- timestamp: 1613228722ip_address: 127.0.0.1
items:- product: d113c964-d254-4f6b-931b-686348f36af5quantity: 1total: 9000id: a50a22d3-432f-4b6c-85db-48ea7ba92036license_key: COt2IXuPqP6VTg3cfXmqQmP0download_url: 'blahbla.test/link-for-download'download_history:- timestamp: 1613228831ip_address: 127.0.0.1- timestamp: 1613228828ip_address: 127.0.0.1- timestamp: 1613228746ip_address: 127.0.0.1- timestamp: 1613228722ip_address: 127.0.0.1