コード例 #1
0
ファイル: Choice.php プロジェクト: PayIcam/shotgun
 public function shotgun($user, $payutcClient)
 {
     $desc = new Desc();
     $desc->select($this->descId);
     // Check not yet shotguned
     $opt = Option::getUser($user->login, $this->descId);
     if (count($opt) > 0) {
         $o = $opt[0];
         if ($o->status == 'W') {
             $o->checkStatus($payutcClient, $desc->payutc_fun_id);
         }
         if ($o->status == 'V') {
             throw new \Exception("Tu as déjà une place pour cet événement.");
         } else {
             return $o->payutc_tra_url;
         }
     }
     // Check available
     if (!$this->isAvailable()) {
         throw new \Exception("Tu as malheureusement cliqué trop lentement, ce choix n'est plus disponible !");
     }
     // Check always open
     $debut = new \DateTime($desc->debut);
     $fin = new \DateTime($desc->fin);
     $now = new \DateTime("NOW");
     $diff = $now->diff($debut);
     if ($diff->invert) {
         if ($now->diff($fin)->invert) {
             throw new \Exception("Désolé la vente est terminé...");
         }
     } else {
         throw new \Exception("La vente n'est pas encore ouvert ! Qu'est ce que tu fais la ?");
     }
     // Let's play !
     // cotisation
     // if($user->is_cotisant != 1) {
     //     $art_id = $this->payutc_art_idNC;
     // } else {
     $art_id = $this->payutc_art_idC;
     // }
     $vente = $payutcClient->createTransaction(array("items" => json_encode(array(array($art_id, 1))), "fun_id" => $desc->payutc_fun_id, "mail" => $user->mail, "return_url" => Config::get("self_url") . "shotgun?id=" . $desc->id, "callback_url" => Config::get("self_url") . "callback"));
     $opt = new Option();
     $opt->user_login = $user->login;
     $opt->user_prenom = $user->prenom;
     $opt->user_nom = $user->nom;
     $opt->user_mail = $user->mail;
     $opt->user_cotisant = $user->is_cotisant ? 1 : 0;
     $opt->fk_desc_id = $desc->id;
     $opt->fk_choice_id = $this->id;
     $opt->payutc_tra_id = $vente->tra_id;
     $opt->payutc_tra_url = $vente->url;
     $opt->date_creation = date("Y-m-d H:i:s");
     $opt->status = 'W';
     $opt->insert();
     return $vente->url;
 }