PHP code example of kikwik / instant-win-bundle

1. Go to this page and download the library: Download kikwik/instant-win-bundle 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/ */

    

kikwik / instant-win-bundle example snippets


namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use App\Repository\ConfigurationRepository;
use Kikwik\InstantWinBundle\Interfaces\ConfigurationInterface;
use Kikwik\InstantWinBundle\Traits\ConfigurationTrait;

/**
 * @ORM\Entity(repositoryClass=ConfigurationRepository::class)
 */
class Configuration implements ConfigurationInterface
{
    use ConfigurationTrait;

    //...
}

namespace App\Repository;

use App\Entity\Configuration;
use Kikwik\InstantWinBundle\Interfaces\ConfigurationRepositoryInterface;
use Kikwik\InstantWinBundle\Traits\ConfigurationRepositoryTrait;

class ConfigurationRepository extends ServiceEntityRepository implements ConfigurationRepositoryInterface
{
    use ConfigurationRepositoryTrait;

    //...
}

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use App\Repository\ConfigurationRepository;
use Kikwik\InstantWinBundle\Interfaces\ConfigurationInterface;
use Kikwik\InstantWinBundle\Traits\ConfigurationTrait;

/**
 * @ORM\Entity(repositoryClass=ConfigurationRepository::class)
 */
class Configuration implements ConfigurationInterface
{
    use ConfigurationTrait;

    //...
}

namespace App\Repository;

use App\Entity\Configuration;
use Kikwik\InstantWinBundle\Interfaces\LeadRepositoryInterface;
use Kikwik\InstantWinBundle\Traits\LeadRepositoryTrait;

class LeadRepository extends ServiceEntityRepository implements LeadRepositoryInterface
{
    use LeadRepositoryTrait;

    //...
}

namespace App\Controller;

class CompetitionController extends AbstractController
{
 /**
     * @Route("/scopri-se-hai-vinto", name="app_competition_instantWin")
     */
    public function step3instantWin(Request $request, InstantWin $instantWin)
    {
        // call instant win lottery
        $lead->setIsInstantWinner($instantWin->lottery());
        $message = $lead->getIsInstantWinner()
            ? $this->configuration->getInstantWinWinnerMessage()
            : $this->configuration->getInstantWinLooserMessage();

        // send $message as sms
        $smsLog = $smsGateway->send($this->configuration->getInstantWinSenderName(),$lead->getPhoneNumber(), $message);
        
        if(in_array($smsLog->getResponseGroup(), ['REJECTED','UNDELIVERABLE']))
        {
            // reset instant win in case of recipient error
            $lead->setIsInstantWinner(false);
        }
        $this->em->persist($lead);
        $this->em->flush();
        
    }
}