Simple Commerce has an additional Digital Products addon, allowing you to link up assets that your customer will be able to download after checking out. If you need it, the addon also includes a basic license verification API.
To install, require this addon as a Composer dependency:
composer require doublethreedigital/sc-digital-products
You may optionally publish the config file by running:
php artisan vendor:publish --tag="sc-digital-products-config"
The config file will be published to config/sc-digital-products.php
That's it! You're ready to start selling Digital Products with Simple Commerce! 🎉
Once installed, you'll see a Digital Product
tab appear on the publish form for your product entries.
In each of your digital products, you should enable the Is Digital Product?
toggle and add the downloadable assets. These are the assets the customer will be able to access once they have purchased your product.
As of v3.1.0, the Digital Products addon supports adding different 'downloadable assets' per variant. So, instead of specifying the 'Download Limit' and 'Downloadable Assets' in the Digital Product
tab, you'll specify them on each of your variants.
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);
If you'd like the Digital Products addon 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' => [ \DoubleThreeDigital\DigitalProducts\Notifications\DigitalDownloadsNotification::class => [ 'to' => 'customer', ], ],],
You can learn more about Simple Commerce's notifications system in the SC Documentation.
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"
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.
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 /api/sc-digital-downloads/verification
with a JSON body containing the license key you wish to verify.
{ "license_key": "IpebSuXft9Koio5GgP7TSRdtl"}
A valid response will look like this:
{ "license_key": "IpebSuXft9Koio5GgP7TSRdtl", "valid": true}
And an invalid one will be like this.
{ "license_key": "IpebSuXft9Koio5GgP7TSRdtl", "valid": false}
The Digital Downloads addon automatically provides a history log of every time something is downloaded. The download history is tracked per order item. When tracking downloads, we store the timestamp of download and the IP address it was downloaded from.
Inside your order's entry, it may look something like this:
items: - product: d113c964-d254-4f6b-931b-686348f36af5 quantity: 1 total: 9000 id: a50a22d3-432f-4b6c-85db-48ea7ba92036 license_key: COt2IXuPqP6VTg3cfXmqQmP0 download_url: 'blahbla.test/link-for-download' download_history: - timestamp: 1613228831 ip_address: 127.0.0.1 - timestamp: 1613228828 ip_address: 127.0.0.1 - timestamp: 1613228746 ip_address: 127.0.0.1 - timestamp: 1613228722 ip_address: 127.0.0.1