1. Go to this page and download the library: Download alancole/vouchers library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$voucher->set('owner', 'Alan');
echo $voucher->get('owner'); // Alan
$model = new Vouchers\Voucher\Model([
'owner' => [
' '
namespace My\Voucher\Generator;
use Vouchers\Voucher\Code\Interface as Generator;
class MyCode implements Generator
{
public function part()
{
return bin2hex(openssl_random_pseudo_bytes(2));
}
public function generate()
{
return strtoupper(sprintf("%s-%s-%s", $this->part(), $this->part(), $this->part()));
}
public function validate()
{
return true;
}
}
$collection->validator(function ($voucher) {
return $voucher->expire_date > new DateTime();
}, "Sorry, this voucher is expired");
try {
$collection->validate("ALAN-COLE-CODE");
} catch (\Vouchers\Exceptions\VoucherNotValid $e) {
return $e->getMessage(); // "Sorry, this voucher is expired";
}
$api = new Discovery\Subscriptions\Api();
$api->setApiKey(getenv("SUBS_API_KEY"));
$api->setAppId(getenv("SUBS_APP_ID"));
$vouchers = $api->getAllVouchers();
$bag = new Vouchers\Bag();
$bag->map($vouchers, function($voucher) {
return new Vouchers\Voucher($voucher);
});
# Add some validators
$bag->validator(function ($voucher) {
return $voucher->owner == "Eurosport";
}, "Sorry, this voucher was not valid.");
$bag->validator(function ($voucher) {
return !$voucher->used;
}, "Sorry, this voucher has been used.");
$bag->validator(function ($voucher) {
return new DateTime($voucher->valid_till) < new DateTime();
}, "Sorry, this voucher is expired.");
try {
$voucher = $collection->validate(filter_val(INPUT_POST, "voucher_code", FILTER_SANITIZE_STRING));
$voucher->set("used", true // not really needed.
$api->putVoucherClaim($voucher); // because this takes care of it.
} catch (\Vouchers\Exceptions\VoucherNotValid $e) {
echo $e->getMessage();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.