<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>
->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());
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;
void payment();
/**generate a refund*/
void refund();
+ /**pay with a voucher*/
+ void payvoucher();
/**change a ticket/voucher price*/
void changeItem();
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"];
}
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.");
"cancelreason" => array("string")
);
$this->backup[]="event";
+
+ //shopping item type
+// $this->scheme[""]
+
//customer
$this->scheme["customer"]=array(
"customerid" => array("seq32","primarykey"),