function GetDomainConnection($sid) { if ($sid != "") { $param = LocalQuery("processing.edit", array("elid" => $sid)); return new DB($param->dbhost, $param->username, $param->password, $param->dbname); } else { return new DB("localhost", "root", "1", "domains"); // temporary default connection } }
} elseif ($command == "crvalidate") { $payment_form = simplexml_load_string(file_get_contents('php://stdin')); $ok = $payment_form->addChild("ok", "/mancgi/qiwipullpayment.php?elid=" . $payment_form->payment_id); $ok->addAttribute("type", "5"); echo $payment_form->asXML(); } elseif ($command == "crset") { $payment_id = $options['payment']; $info = LocalQuery("payment.info", array("elid" => $payment_id)); $phone = (string) $info->payment[0]->phone; $phone = preg_replace('/[^0-9]/', '', $phone); $lifetime = new DateTime(); if ($info->payment[0]->paymethod[1]->autoclearperiod != "") { $lifetime->add(new DateInterval("P" . $info->payment[0]->paymethod[1]->autoclearperiod . "D")); } else { $lifetime->add(new DateInterval("P30D")); } $input = array("user" => "tel:+" . $phone, "amount" => (string) $info->payment[0]->paymethodamount, "ccy" => (string) $info->payment[0]->currency[1]->iso, "pay_source" => (string) $info->payment[0]->paymethod[1]->pay_source, "prv_name" => (string) $info->payment[0]->project->name, "comment" => (string) $info->payment[0]->number, "lifetime" => $lifetime->format("Y-m-d\\TH:i:s")); Debug(print_r($input, true)); $out = HttpQuery("https://qiwi.com/api/v2/prv/" . $info->payment[0]->paymethod[1]->PRV_ID . "/bills/" . $payment_id, $input, "PUT", $info->payment[0]->paymethod[1]->API_ID, $info->payment[0]->paymethod[1]->API_PASSWORD); $out_xml = simplexml_load_string($out); if ($out_xml->result_code == "0") { LocalQuery("payment.setinpay", array("elid" => $payment_id)); } else { throw new Error("payment_process_error", "", "", array("error_msg" => $out_xml->description)); } } else { throw new Error("unknown command"); } } catch (Exception $e) { echo $e; }
} $signature = base64_encode(hash_hmac("sha1", $signature_string, $info->payment[0]->paymethod[1]->NOTIFY_PASSWORD, true)); if ($signature != $x_api_signature) { $out_xml->addChild("result_code", "151"); $out_xml->addChild("description", "invalid signature"); } else { if ($command == "bill") { if ($error == "0" && $amount == (string) $info->payment[0]->paymethodamount && $iso == (string) $info->payment[0]->currency[1]->iso) { if ($status == "paid") { LocalQuery("payment.setpaid", array("elid" => $param["bill_id"])); } else { if (status == "waiting") { LocalQuery("payment.setinpay", array("elid" => $param["bill_id"])); } else { if (status == "rejected" || status == "unpaid" || status == "expired") { LocalQuery("payment.setnopay", array("elid" => $param["bill_id"])); } } } $out_xml->addChild("result_code", "0"); } else { $out_xml->addChild("result_code", "5"); $out_xml->addChild("description", "invalid data"); } } else { $out_xml->addChild("result_code", "5"); $out_xml->addChild("description", "invalid command"); } } } }
#!/usr/bin/php <?php set_include_path(get_include_path() . PATH_SEPARATOR . "/usr/local/mgr5/include/php"); define('__MODULE__', "qiwipullpayment"); require_once 'bill_util.php'; echo "Content-Type: text/html\n\n"; $client_ip = ClientIp(); $param = CgiInput(); if ($param["auth"] == "") { throw new Error("no auth info"); } else { $info = LocalQuery("payment.info", array("elid" => $param["elid"])); $elid = (string) $info->payment[0]->id; echo "<html>\n"; echo "<head>\n"; echo "\t<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />\n"; echo "\t<link rel='shortcut icon' href='billmgr.ico' type='image/x-icon' />\n"; echo "\t<script language='JavaScript'>\n"; echo "\t\tfunction DoSubmit() {\n"; echo "\t\t\tdocument.qiwiform.submit();\n"; echo "\t\t}\n"; echo "\t</script>\n"; echo "</head>\n"; echo "<body onload='DoSubmit()'>\n"; echo "\t<form name='qiwiform' action='https://qiwi.com/order/external/main.action' method='post'>\n"; echo "\t\t<input type='hidden' name='shop' value='" . (string) $info->payment[0]->paymethod[1]->PRV_ID . "'>\n"; echo "\t\t<input type='hidden' name='transaction' value='" . $elid . "'>\n"; echo "\t\t<input type='hidden' name='successUrl' value='" . (string) $info->payment[0]->manager_url . "?func=payment.success&elid=" . $elid . "&module=" . __MODULE__ . "'>\n"; echo "\t\t<input type='hidden' name='failUrl' value='" . (string) $info->payment[0]->manager_url . "?func=payment.fail&elid=" . $elid . "&module=" . __MODULE__ . "'>\n"; echo "\t</form>\n"; echo "</body>\n";