Example #1
0
 function renderHtml()
 {
     $betaling = new VIH_Model_Betaling($this->context->name());
     $onlinebetaling = new VIH_Onlinebetaling('capture');
     $eval = $onlinebetaling->capture($betaling->get('transactionnumber'), (int) $betaling->get('amount') * 100);
     if ($eval) {
         if (!empty($eval['qpstat']) and $eval['qpstat'] === '000') {
             if ($betaling->setStatus('approved')) {
                 $historik = new VIH_Model_Historik($betaling->get('belong_to'), $betaling->get('belong_to_id'));
                 $historik->save(array('type' => 'dankort', 'comment' => 'Capture transaktion #' . $betaling->get('transactionnumber')));
             }
             return new k_SeeOther($this->context->url('../'));
         } else {
             // An error occured with the capture
             // Dumping return data for debugging
             /*
             echo "<pre>";
             var_dump($eval);
             echo "</pre>";
             */
             $historik = new VIH_Model_Historik($betaling->get('belong_to'), $betaling->get('belong_to_id'));
             $historik->save(array('type' => 'dankort', 'comment' => 'Fejl ved capture af transaktion #' . $betaling->get('transactionnumber')));
             throw new Exception('Betalingen kunne ikke hæves, formentlig fordi den er ugyldig');
         }
     } else {
         throw new Exception('Der var en kommunikationsfejl med Onlinebetalingen');
     }
     return 'error';
 }
Example #2
0
 function postForm()
 {
     $tilmelding = VIH_Model_LangtKursus_Tilmelding::factory($this->context->name());
     $tilmelding->loadBetaling();
     if ($this->getForm()->validate()) {
         // create a payment which functions as an third party id at quickpay
         // payment is coupled with the current registration
         // after pbs update the status of the payment
         // set status to 000 if captured at PBS
         $eval = false;
         $betaling = $tilmelding->betalingFactory();
         $submitted_amount = $this->body('amount');
         if (is_array($submitted_amount)) {
             $amount = 0;
             foreach ($submitted_amount as $amount) {
                 $total_amount += $amount;
             }
         } elseif (is_numeric($submitted_amount)) {
             $total_amount = $submitted_amount;
         } else {
             throw new Exception('De postede beløbsværdier er ikke gyldige');
         }
         $betaling_amount = $total_amount / 100;
         $betaling_id = $betaling->save(array('type' => 'quickpay', 'amount' => $betaling_amount));
         if ($betaling_id == 0) {
             throw new Exception("Kunne ikke oprette betaling");
         }
         $onlinebetaling = new VIH_Onlinebetaling('authorize');
         $onlinebetaling->addCustomVar("Kursusnavn", "Langtkursus: " . $tilmelding->kursus->get("kursusnavn"));
         $onlinebetaling->addCustomVar("Navn", $tilmelding->get("navn"));
         $onlinebetaling->addCustomVar("Tilmelding_ID", $tilmelding->get("id"));
         $eval = $onlinebetaling->authorize($this->body('cardnumber'), $this->body('yy') . $this->body('mm'), $this->body('cvd'), $betaling_id, $total_amount);
         if ($eval) {
             if ($eval['qpstat'] === '000') {
                 $betaling->setTransactionnumber($eval['transaction']);
                 $betaling->setStatus('completed');
                 $historik = new VIH_Model_Historik($betaling->get('belong_to'), $betaling->get('belong_to_id'));
                 if (!$historik->save(array('betaling_id' => $betaling->get('id'), 'type' => 'dankort', 'comment' => 'Onlinebetaling # ' . $betaling->get('transactionnumber')))) {
                     throw new Exception('Der var en fejl med at gemme historikken.');
                 }
                 return new k_SeeOther($this->context->url());
             } else {
                 // An error occured with the authorize
                 $this->extra_text .= "<p><strong>Der opstod en fejl under transaktionen. " . $onlinebetaling->statuskoder[$eval['qpstat']] . ". Du kan prøve igen.</strong></p>";
             }
         } else {
             throw new Exception('Kommunikationsfejl med PBS og QuickPay');
         }
     }
     return $this->render();
 }
Example #3
0
 /**
  * NOTICE: First we need to make a local payment, so we have a
  * local id to use for capture at quickpay.
  * When the payment has been captured we set status = 000
  */
 function postForm()
 {
     $tilmelding = VIH_Model_KortKursus_Tilmelding::factory($this->context->name());
     if ($this->getForm()->validate()) {
         $eval = false;
         $betaling = new VIH_Model_Betaling("kortekurser", $tilmelding->get("id"));
         $betaling_amount = $this->body('amount') / 100;
         $betaling_id = $betaling->save(array('type' => 'quickpay', 'amount' => $betaling_amount));
         if ($betaling_id == 0) {
             throw new Exception("Kunne ikke oprette betaling");
         }
         $onlinebetaling = new VIH_Onlinebetaling('authorize');
         $onlinebetaling->addCustomVar("Kursusnavn", "Kortkursus: " . $tilmelding->kursus->getKursusNavn());
         $onlinebetaling->addCustomVar("Kontaktnavn", $tilmelding->get("navn"));
         $onlinebetaling->addCustomVar("Tilmelding_ID", $tilmelding->get("id"));
         $eval = $onlinebetaling->authorize($this->body('cardnumber'), $this->body('yy') . $this->body('mm'), $this->body('cvd'), $betaling_id, $this->body('amount'));
         if ($eval) {
             if ($eval['qpstat'] === '000') {
                 // The authorization was completed
                 $betaling->setTransactionnumber($eval['transaction']);
                 $betaling->setStatus('completed');
                 $historik = new VIH_Model_Historik($betaling->get('belong_to'), $betaling->get('belong_to_id'));
                 if (!$historik->save(array('betaling_id' => $betaling->get('id'), 'type' => 'dankort', 'comment' => 'Onlinebetaling # ' . $betaling->get('transactionnumber')))) {
                     throw new Exception('Der var en fejl med at gemme historikken.');
                 }
                 return new k_SeeOther($this->context->url());
             } else {
                 // An error occured with the authorize
                 $this->extra_text = '<p class="warning">Der opstod en fejl under transaktionen. ' . $onlinebetaling->statuskoder[$eval['qpstat']] . '. Du kan prøve igen.</p>';
             }
         } else {
             $this->extra_text = 'Kommunikationsfejl med PBS eller QuickPay';
         }
     }
     return $this->render();
 }
$form->applyFilter('trim', '__ALL__');
$form->applyFilter('addslashes', '__ALL__');
$form->applyFilter('strip_tags', '__ALL__');
if ($form->validate()) {
    // først skal vi oprette en betaling - som kan fungere som id hos qp
    // betalingen skal kobles til den aktuelle tilmelding
    // når vi så har haft den omkring pbs skal betalingen opdateres med status for betalingen
    // status sættes til 000, hvis den er godkendt hos pbs.
    $eval = false;
    $betaling = new VIH_Model_Betaling('elevforeningen', $order_id);
    $betaling_amount_quickpay = $betaling_amount * 100;
    $betaling_id = $betaling->save(array('type' => 'quickpay', 'amount' => $betaling_amount));
    if ($betaling_id == 0) {
        trigger_error("Kunne ikke oprette betaling", E_USER_ERROR);
    }
    $onlinebetaling = new VIH_Onlinebetaling('authorize');
    $onlinebetaling->addCustomVar('Elevforeningsmedlem', $contact['number']);
    $onlinebetaling->addCustomVar('Kontaktid', $contact['id']);
    $eval = $onlinebetaling->authorize($form->exportValue('cardnumber'), $form->exportValue('yy') . $form->exportValue('mm'), $form->exportValue('cvd'), $betaling_id, $betaling_amount_quickpay);
    if ($eval) {
        if ($eval['qpstat'] === '000') {
            // The authorization was completed
            /*
            echo 'Authorization: ' . $qpstatText["" . $eval['qpstat'] . ""] . '<br />';
            echo "<pre>";
            var_dump($eval);
            echo "</pre>";
            */
            $betaling->setTransactionnumber($eval['transaction']);
            $betaling->setStatus('completed');
            $historik = new VIH_Model_Historik($betaling->get('belong_to'), $betaling->get('belong_to_id'));