pay with voucher
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 21 Dec 2008 16:58:09 +0000 (16:58 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 21 Dec 2008 16:58:09 +0000 (16:58 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@223 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

doc/prog_protocol.html
src/orderwin.cpp
src/orderwin.h
www/inc/classes/order.php
www/inc/classes/voucher.php
www/inc/db/db_scheme.php

index 94a1a3c..2f3df99 100644 (file)
@@ -740,7 +740,10 @@ The <tt>getvoucherprices</tt> transaction can be used to retrieve allowed vouche
 
 <h3>Using a Voucher</h3>
 
-The <tt>usevoucher</tt> transaction can be used to use a voucher for payment. The request contains the voucher-ID on the first line and the order to be paid on the second line. The response contains the amount that remains on the voucher on success or contains an error message if an error occurred.
+The <tt>usevoucher</tt> transaction can be used to use a voucher for payment. The request contains the voucher-ID on the first line and the order to be paid on the second line.<p>
+
+On success the response contains the amount that remains on the voucher on the first line and the now current amount that has been paid for the order on the second line.
+On error the response contains an error message.
 
 <h3>Returning/Cancelling a Voucher</h3>
 
index 5976a80..7a027e3 100644 (file)
@@ -85,6 +85,8 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o)
         ->setEnabled(req->hasRole("orderpay"));
        m->addAction(tr("&Refund..."),this,SLOT(refund()))
         ->setEnabled(req->hasRole("orderrefund"));
+       m->addAction(tr("Pay with &Voucher..."),this,SLOT(payvoucher()))
+        ->setEnabled(req->hasRole("usevoucher"));
         
        m=mb->addMenu(tr("P&rinting"));
        m->setEnabled(o.isStored());
@@ -655,6 +657,39 @@ void MOrderWindow::payment()
        m_paid->setText(m_order.amountPaidString());
 }
 
+void MOrderWindow::payvoucher()
+{
+       if(!m_order.isValid())return;
+       //get voucher
+       bool ok;
+       QString vid=QInputDialog::getText(this,tr("Enter Voucher"),tr("Please enter the ID of the voucher you want to use:"),QLineEdit::Normal,"",&ok);
+       if(!ok)return;
+       if(vid=="")return;
+       MVoucher vou(req,vid);
+       if(!vou.isValid()){
+               QMessageBox::warning(this,tr("Warning"),tr("This voucher is not valid."));
+               return;
+       }
+       //submit
+       QByteArray rq=vid.toAscii()+"\n"+QByteArray::number(m_order.orderID());
+       if(!req->request("usevoucher",rq)){
+               QMessageBox::warning(this,tr("Warning"),tr("Unable to submit payment request."));
+               return;
+       }
+       if(req->responseStatus()!=MWebRequest::Ok){
+               QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay: %1").arg(qApp->translate("php::",req->responseBody())));
+               return;
+       }
+       QStringList sl=QString::fromAscii(req->responseBody().trimmed()).split("\n");
+       if(sl.size()>1){
+               m_order.setAmountPaid(sl[1].toInt());
+               m_paid->setText(m_order.amountPaidString());
+       }
+       if(sl.size()>0){
+               QMessageBox::information(this,tr("Voucher Info"),tr("Remaining value of this voucher: %1").arg(cent2str(sl[0].toInt())));
+       }
+}
+
 void MOrderWindow::refund()
 {
        if(!m_order.isValid())return;
index f1686f3..1d2d2fe 100644 (file)
@@ -72,6 +72,8 @@ class MOrderWindow:public QMainWindow
                void payment();
                /**generate a refund*/
                void refund();
+               /**pay with a voucher*/
+               void payvoucher();
                
                /**change a ticket/voucher price*/
                void changeItem();
index 12eebdb..2ce4a91 100644 (file)
@@ -988,12 +988,16 @@ function orderByTicketXml($ticket)
        global $db;
        $res=$db->select("ticket","orderid","ticketid=".$db->escapeString($ticket));
        if(count($res)<1){
-               header("X-MagicSmoke-Status: Error");
-               die(tr("Ticket not found."));
+               //try voucher instead
+               $res=$db->select("voucher","orderid","voucherid=".$db->escapeString($ticket));
+               if(count($res)<1){
+                       header("X-MagicSmoke-Status: Error");
+                       die(tr("Ticket or Voucher not found."));
+               }
        }
-       if($res[0]["orderid"]===NULL || $res[0]["orderid"]<0){
+       if($db->isNull($res[0]["orderid"]) || $res[0]["orderid"]<0){
                header("X-MagicSmoke-Status: Error");
-               die(tr("Ticket has no order."));
+               die(tr("Ticket/Voucher has no order."));
        }
        header("X-MagicSmoke-Status: Ok");
        echo $res[0]["orderid"];
index 41e9aa6..f103e3b 100644 (file)
@@ -284,7 +284,11 @@ function useVoucherXml($txt)
        }
        if($vc->payForOrder(trim($splt[1]))){
                header("X-MagicSmoke-Status: Ok");
-               print($vc->remainingValue());
+               print($vc->remainingValue()."\n");
+               global $db;
+               $res=$db->select("order","amountpaid","orderid=".$db->escapeInt(trim($splt[1])));
+               if(count($res)>0)
+                       print($res[0]["amountpaid"]);
        }else{
                header("X-MagicSmoke-Status: Error");
                echo tr("Unable to process payment via voucher.");
index 4c679a2..98b047f 100644 (file)
@@ -115,6 +115,10 @@ class DbScheme {
                        "cancelreason" => array("string")
                );
                $this->backup[]="event";
+               
+               //shopping item type
+//             $this->scheme[""]
+               
                //customer
                $this->scheme["customer"]=array(
                        "customerid" => array("seq32","primarykey"),