Install Dependencies
composer require c975l/gift-voucher-bundle
composer require c975l/payment-bundle stripe/stripe-php endroid/qr-code
Configure the Bundle
Add to config/bundles.php:
return [
// ...
C975L\GiftVoucherBundle\C975LGiftVoucherBundle::class => ['all' => true],
C975L\PaymentBundle\C975LPaymentBundle::class => ['all' => true],
];
Publish Config & Assets
php artisan vendor:publish --tag=gift-voucher-config
php artisan vendor:publish --tag=gift-voucher-assets
Configure Stripe & Terms of Sale
Update .env with Stripe keys and set the gift_voucher.terms_of_sale_url in config/gift_voucher.php.
First Use Case: Create a Voucher Request Form
Use the provided Twig template (gift_voucher/request_form.html.twig) or extend it:
{{ render(controller('C975LGiftVoucherBundle:GiftVoucher:requestForm')) }}
Frontend Integration
$('.gift-voucher-recipient').select2();
Backend Processing
use C975L\GiftVoucherBundle\Controller\GiftVoucherController;
// In your routes:
$router->mountPrefix('/gift-voucher', GiftVoucherController::class)
->add('request', 'request')
->add('redeem', 'redeem');
Payment Integration
config/payment.php and link it to the voucher:
// Example: After form submission
$voucher = $this->get('gift_voucher.manager')->createVoucher($data);
$payment = $this->get('payment.manager')->createPayment($voucher->getId(), $amount);
Redemption Flow
$qrCode = $this->get('gift_voucher.manager')->generateQrCode($voucher->getSecretCode());
$pdf = $this->get('gift_voucher.manager')->generatePdf($voucher);
Email Automation
gift_voucher/email/voucher_email.html.twig) to include:
Toolbar Integration
Use c975LToolbarBundle to add voucher management to your admin panel:
// In your toolbar config
$toolbar->addItem('Gift Vouchers', 'gift_voucher_dashboard', 'fa-gift');
Dynamic PDFs
Extend the PDF generation by overriding the GiftVoucherPdfGenerator service:
# config/services.yaml
services:
App\Service\CustomGiftVoucherPdfGenerator:
decorates: 'gift_voucher.pdf_generator'
arguments: ['@gift_voucher.pdf_generator.inner']
Validation Logic Validate QR codes in your redemption controller:
public function redeemAction(Request $request) {
$secretCode = $request->get('secret_code');
$isValid = $this->get('gift_voucher.manager')->validateVoucher($secretCode);
if (!$isValid) {
throw $this->createNotFoundException('Invalid voucher');
}
}
Missing Stripe Configuration
Stripe\Exception\InvalidRequestException if keys are misconfigured..env and config/payment.php for STRIPE_SECRET_KEY and STRIPE_PUBLISHABLE_KEY.Terms of Sale URL Unreachable
c975LSiteBundle to generate a PDF route or ensure your URL is publicly accessible.QR Code Security
$voucher->getSecretCode().PDF Generation Overhead
Enable Debug Mode
Set GIFT_VOUCHER_DEBUG: true in .env to log QR codes and secret codes (for testing only).
Check Stripe Webhooks
Ensure your Stripe webhook endpoint (configured in config/payment.php) is reachable:
php artisan payment:webhook-test
Custom Voucher Fields
Extend the GiftVoucher entity:
// src/Entity/GiftVoucher.php
use C975L\GiftVoucherBundle\Entity\GiftVoucher as BaseVoucher;
class GiftVoucher extends BaseVoucher {
/**
* @ORM\Column(type="string", nullable=true)
*/
private $customField;
}
Override Email Templates
Copy the default template to templates/gift_voucher/email/ and customize:
{# templates/gift_voucher/email/custom_voucher_email.html.twig #}
{% extends 'gift_voucher/email/voucher_email.html.twig' %}
{% block subject %}Custom Voucher Subject{% endblock %}
Add Recipient Validation
Hook into the gift_voucher.pre_redeem event:
// src/EventListener/VoucherValidationListener.php
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use C975L\GiftVoucherBundle\Event\PreRedeemEvent;
class VoucherValidationListener implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
'gift_voucher.pre_redeem' => 'validateRecipient',
];
}
public function validateRecipient(PreRedeemEvent $event) {
$recipient = $event->getRecipient();
if ($recipient->isBlacklisted()) {
$event->stopPropagation();
}
}
}
Secret Code Length
Default is 4 letters (configurable via gift_voucher.secret_code_length).
Increase for higher security (e.g., gift_voucher.secret_code_length: 6).
Expiry Logic
Vouchers expire after gift_voucher.expiry_days (default: 365). Set to 0 for no expiry.
QR Code Size
Adjust via gift_voucher.qr_code_size (default: 200). Larger sizes improve readability but increase file size.
How can I help you explore Laravel packages today?