Skip to content
Creates and validates Gift-Voucher
Branch: master
Clone or download
LaurentMarquet v3.0.1
- Updated `GiftVoucherEmail` to use `getPdfFilePath()` that returns the url instead of the content (15/07/2019)
Latest commit 5a7decd Jul 15, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Controller v2.1.1 Mar 12, 2019
DependencyInjection v2.1.1 Mar 12, 2019
Entity v2.1.1 Mar 12, 2019
Form v2.1.1 Mar 12, 2019
Repository v2.1.1 Mar 12, 2019
Resources v2.1.1.2 Jul 15, 2019
Security v2.1.1 Mar 12, 2019
Service v3.0.1 Jul 15, 2019
Twig v2.1.1 Mar 12, 2019
.gitignore v2.1.1.2 Jul 15, 2019 v3.0.1 Jul 15, 2019
LICENSE v2.1.1.2 Jul 15, 2019 v3.0 Jul 15, 2019 v3.0 Jul 15, 2019
c975LGiftVoucherBundle.php v2.1.1 Mar 12, 2019
composer.json v3.0 Jul 15, 2019
composer.lock v2.1.1.2 Jul 15, 2019


GiftVoucherBundle does the following:

  • Allows to create Gift Voucher request form,
  • Interfaces with Stripe via c975LPaymentBundle for its payment,
  • Creates a PDF, using KnpSnappyBundle and wkhtmltopdf, of the GiftVoucher and sends it by email,
  • Creates a QR Code using QrCodeBundle,
  • Allows to use the GiftVoucher via a QrCode plus validation aftewards,
  • Integrates with c975LToolbarBundle,
  • PDF and Qrcode are NOT stored but created on the fly,
  • Joins your Terms of sales as PDF to the email,

The security is provided by a four-letter secret code, included in the QrCode, but not in the displayed Gift-Voucher identifier.

This Bundle relies on the use of c975LPaymentBundle, Stripe and its PHP Library. So you MUST have a Stripe account.

It also recomended to use this with a SSL certificat to reassure the user.

As the Terms of sales MUST be sent to the user with the Gift-Voucher, you MUST provide a Route or url for this PDF file. If you don't have such, you may consider using c975LSiteBundle for its pre-defined models and c975LPageEditBundle for its ability to create a PDF.

You can also give a better user's experience by using Select2 for the selection of GiftVoucher. Simply include it to your layout using

    {# jQuery has to be linked before #}
    {# In your css block #}
    {{ inc_lib('select2', 'css', '4.*') }}
    {# In your javascript block #}
    {{ inc_lib('select2', 'js', '4.*') }}

GiftVoucherBundle dedicated web page.

GiftVoucherBundle API documentation.

Bundle installation

Step 1: Download the Bundle

v3.x works with Symfony 4.x. Use v2.x for Symfony 3.x Use Composer to install the library

    composer require c975l/giftvoucher-bundle

Step 2: Configure the Bundle

Check dependencies for their configuration:

For KnpSnappyBundle you can use this configuration if it suits to your needs.

    process_timeout: 20
    temporary_folder: "%kernel.cache_dir%/snappy"
        enabled: true
        binary: "%kernel.root_dir%/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64"
            print-media-type: true
            page-size: A4
            orientation: 'portrait'
            encoding : utf-8
            dpi: 300
            images: true
            image-quality: 80
            margin-left: 10mm
            margin-right: 10mm
            margin-top: 10mm
            margin-bottom: 10mm
        enabled: false

c975LGiftVoucherBundle uses c975L/ConfigBundle to manage configuration parameters. Use the Route "/gift-voucher/config" with the proper user role to modify them.

Step 3: Enable the Routes

Then, enable the routes by adding them to the /config/routes.yaml file of your project:

    resource: "@c975LGiftVoucherBundle/Controller/"
    type: annotation
    prefix: /
    #Multilingual website use the following
    #prefix: /{_locale}
    #defaults:   { _locale: '%locale%' }
    #    _locale: en|fr|es

Step 4: Create MySql tables

You can use php bin/console make:migration to create the migration file as documented in Symfony's Doctrine docs OR use /Resources/sql/gift-voucher.sql to create the tables gift_voucher_available and gift_voucher_purchased. The DROP TABLE are commented to avoid dropping by mistake.

Step 5: Override templates

It is strongly recommended to use the Override Templates from Third-Party Bundles feature to integrate fully with your site.

For this, simply, create the following structure /templates/bundles/c975LGiftVoucherBundle/ in your app and then duplicate the file layout.html.twig in it, to override the existing Bundle file.

In layout.html.twig, it will mainly consist to extend your layout and define specific variables, i.e. :

{% extends 'layout.html.twig' %}

{% block content %}
    {% block giftVoucher_content %}
    {% endblock %}
{% endblock %}```

Then in your `layout.html.twig` and its dependencies, such as `header.html.twig`, `footer.html.twig`, `navbar.html.twig`, etc. you can use the condition `if display == 'pdf'` or `if display == 'html'` to choose what to display to which format, and you keep all your data in one place.

**Keep in mind that links have to be absolute, or their content included, to be exported (see below).**

How to use
GiftVoucherBundle uses `KnpSnappyBundle` to generates PDF, which itself uses `wkhtmltopdf`. `wkhtmltopdf` requires that included files, like stylesheets, are included with an absolute url. But, there is a known problem with SSL, see, which force you to downgrade openssl, like in

You can avoid this problem by including the whole content of included files, which is what `wkhtmltopdf` does, in your html output. To integrate them easily, you can, as [c975L/SiteBundle]( does, use [c975L/IncludeLibraryBundle]( with the following code:
{# in your layout.html.twig > head #}
    {% if display == 'pdf' %}
        {{ inc_content('bootstrap', 'css', '3.*') }}
        {{ inc_content(absolute_url(asset('css/styles.min.css')), 'local') }}
    {% else %}
        {{ inc_lib('bootstrap', 'css', '3.*') }}
        {{ inc_lib('cookieconsent', 'css', '3.*') }}
        {{ inc_lib('fontawesome', 'css', '5.*') }}
        {{ inc_lib(absolute_url(asset('css/styles.min.css')), 'local') }}
    {% endif %}


The different Routes (naming self-explanatory) available are:

  • giftvoucher_display
  • giftvoucher_config
  • giftvoucher_create
  • giftvoucher_modify
  • giftvoucher_duplicate
  • giftvoucher_delete
  • giftvoucher_dashboard
  • giftvoucher_purchased
  • giftvoucher_offer
  • giftvoucher_offer_all
  • giftvoucher_use
  • giftvoucher_slug
  • giftvoucher_help
  • giftvoucher_qrcode

You should use Route giftvoucher_offer_all as an entry point to your Gift-Vouchers.

Twig extensions

You can use the following Twig extensions to display Gift-Vouchers around your web site.


There are different ways to use this extension:

{{ gv_offer_button(GIFTVOUCHER_AVAILABLE_ID) }} will display a button with defaults styles {{ gv_offer_button(GIFTVOUCHER_AVAILABLE_ID, 'btn-primary') }} will display a button with specified styles {{ gv_offer_button(GIFTVOUCHER_AVAILABLE_ID, 'WHATEVER_STYLE_YOU_HAVE_DEFINED_IN_CSS') }} will display a button using your own styles

These codes, and other variants, are recalled on the display of Gift-Voucher for Admin users.


You will use this Twig extension to display a link to ofeer the Gift-Voucher

{{ gv_offer_link(GIFTVOUCHER_AVAILABLE_ID) }} will display a link

This code is recalled on the display of Gift-Voucher for Admin users.


This Twig extension will create a view of your Gift-Vouchers. It is used on Resources/views/pages/offerAll.html.twig template, used by Route giftvoucher_offer_all.

{{ gv_view_all() }} will create the view with all your available Gift-Vouchers {{ gv_view_all(NUMBER_OF_GIFTVOUCHERS_TO_DISPLAY) }} will create the view with the specified number of your available Gift-Vouchers {{ gv_view_all(NUMBER_OF_GIFTVOUCHERS_TO_DISPLAY, ORDERED_FIELD) }} will create the view with the specified number of your available Gift-Vouchers, ordered by the specified field. Values for this field are the ones of the Database Table gift_voucher_available. You will mostly use id, object (default one), slug, amount.

If this project help you to reduce time to develop, you can buy me a coffee :)

You can’t perform that action at this time.