Digital Products
- Installation
- Adding downloadable assets to products
- Overriding the license key generation logic
- Notifications
- License Verification
- Download History
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.
Installation
To install, require this addon as a Composer dependency:
1composer require doublethreedigital/sc-digital-products
You may optionally publish the config file by running:
1php 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! 🎉
Adding downloadable assets to products
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.
Product Variants
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.
Overriding the license key generation logic
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
.
1$this->app->bind('LicenseKey', App\Repositories\LicenseKeyRepository::class);
Notifications
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.
1'notifications' => [2 'digital_download_ready' => [3 \DoubleThreeDigital\DigitalProducts\Notifications\DigitalDownloadsNotification::class => [4 'to' => 'customer',5 ],6 ],7],
You can learn more about Simple Commerce's notifications system in the SC Documentation.
Customising the default view
If you wish to customise the default email view, you can publish it with this command.
1php artisan vendor:publish --tag="sc-digital-products-views"
You'll then find the published views in your resources/views/vendor/sc-digital-products
folder.
Using your own notification
If you wish to have full control over the notification being used here, you may simply replace the class name.
License Verification
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.
1{2 "license_key": "IpebSuXft9Koio5GgP7TSRdtl"3}
A valid response will look like this:
1{2 "license_key": "IpebSuXft9Koio5GgP7TSRdtl",3 "valid": true4}
And an invalid one will be like this.
1{2 "license_key": "IpebSuXft9Koio5GgP7TSRdtl",3 "valid": false4}
Download History
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:
1items: 2 - product: d113c964-d254-4f6b-931b-686348f36af5 3 quantity: 1 4 total: 9000 5 id: a50a22d3-432f-4b6c-85db-48ea7ba92036 6 license_key: COt2IXuPqP6VTg3cfXmqQmP0 7 download_url: 'blahbla.test/link-for-download' 8 download_history: 9 - timestamp: 161322883110 ip_address: 127.0.0.111 - timestamp: 161322882812 ip_address: 127.0.0.113 - timestamp: 161322874614 ip_address: 127.0.0.115 - timestamp: 161322872216 ip_address: 127.0.0.1