$mollie = new Mollie_API_Client(); $mollie->setApiKey($partner_id); $payment = $mollie->payments->get($transaction_id); $order_id = $payment->metadata->order_id; debug_write($order_id, $payment); if ($payment->isPaid() == true) { $database->query("UPDATE " . TABLE_PREFIX . "mod_bakery_customer SET transaction_status = 'paid', status = 'ordered', submitted = 'molliev2' WHERE transaction_id = '{$transaction_id}'"); $payment_status = "success"; return; } elseif ($payment->isOpen() == true) { $database->query("UPDATE " . TABLE_PREFIX . "mod_bakery_customer SET transaction_status = 'pending', status = 'busy', submitted = 'molliev2' WHERE transaction_id = '{$transaction_id}'"); $payment_status = "pending"; return; } } debug_write($_SESSION['bakery']['order_id'], "Status: " . $transaction_status); // Check if the payment has been canceled by user if ($transaction_status != 'paid') { $payment_status = "canceled"; return; } elseif ($transaction_status == 'paid') { $payment_status = "success"; $email_sent = true; return; } else { $payment_status = "error"; return; } function debug_write($order_id, $status) { require dirname(__FILE__) . '/info.php';
function convert_to_xml() { // YAWC Online access details $conversionURL = 'http://www.yawconline.com/ye_convert.php?url='; // YOL login is extracted from the current server URL $login = '******' . $site_url; $password = '******'; // should be $USER->id or something a bit more secure // Request conversion to XML, expecting a Zip file back, and delete the public Word file once complete $file_to_convert = $urlbase . "/" . $working_folder_uri . basename($yolfriendly_name); $yolconvertURL = $conversionURL . $file_to_convert . "&username="******"&password="******"MQPreview: yolconvertURL = " . $yolconvertURL . "\n"); $yolzipdata = file_get_contents($yolconvertURL); debug_write("MQPreview: yolzipdata length/type = " . strlen($yolzipdata) . "/" . substr($yolzipdata, 0, 2) . "\n"); if (!debug_on())unlink($working_folder . $temp_doc_folder . $cleanfilename); // Check a non-zero length file is returned, and the file is a Zip file if((strlen($yolzipdata) == 0) || (substr($yolzipdata, 0, 2) !== "PK")) { unlink($cookiefile); header("HTTP/1.0 500 Internal Server Error"); die("Could not convert Word file.\n"); } // Save the Zip file to a regular temporary file, not publicly available $zipfile = tempnam($working_folder, "zip-") . ".zip"; debug_write("MQPreview: zipfile = " . $zipfile . "\n"); if(($fp = fopen($zipfile, "wb"))) { if(($nbytes = fwrite($fp, $yolzipdata)) == 0) { fclose($fp); unlink($cookiefile); header("HTTP/1.0 500 Internal Server Error"); die("Could not convert Word file.\n"); } fclose($fp); } // Open Zip file and get the Moodle Question XML file $zfh = zip_open($zipfile); if ($zfh) { while ($zip_entry = zip_read($zfh)) { if (zip_entry_open($zfh, $zip_entry, "r")) { $ze_filename = zip_entry_name($zip_entry); $ze_file_suffix = substr($ze_filename, -3, 3); $ze_filesize = zip_entry_filesize($zip_entry); debug_write("MQPreview: zip_entry_name = $ze_filename, $ze_file_suffix, $ze_filesize" . "\n"); if($ze_file_suffix === "xml" && $ze_filesize != 0) { $xmldata = zip_entry_read($zip_entry, $ze_filesize); debug_write("MQPreview: xmldata length = " . strlen($xmldata) . "\n"); } zip_entry_close($zip_entry); } else { debug_write("MQPreview: cannot open zipfile ", $zipfile . "\n"); if (!debug_on())unlink($zipfile); return false; } zip_close($zfh); if (!debug_on())unlink($zipfile); } } else { fwrite("MQPreview: cannot open zipfile ", $zipfile . "\n"); if (!debug_on())unlink($zipfile); unlink($cookiefile); header("HTTP/1.0 500 Internal Server Error"); die("Could not open preview XML file.\n"); } // Now over-write the original Word file with the XML file, so that default XML file handling will work if(($fp = fopen($yolfriendly_name, "wb"))) { if(($nbytes = fwrite($fp, $xmldata)) == 0) { debug_write("MQPreview: cannot write to tempfile", $yolfriendly_name); return false; } fclose($fp); } }
require '../../../../config.php'; require_once WB_PATH . '/framework/class.admin.php'; require_once dirname(__FILE__) . '/info.php'; require_once dirname(__FILE__) . '/Mollie/API/Autoloader.php'; // Get the payment method settings from db $partner_id = $database->get_one("SELECT value_1 FROM " . TABLE_PREFIX . "mod_bakery_payment_methods WHERE directory = 'molliev2'"); // Check if payment is completed if (isset($_POST['id'])) { try { $mollie = new Mollie_API_Client(); $mollie->setApiKey($partner_id); $payment = $mollie->payments->get($_REQUEST["id"]); $order_id = $payment->metadata->order_id; $method = $payment->method; $transaction_id = $payment->id; debug_write($order_id, $payment); if ($payment->isPaid() == true) { $new_invoice_id = $database->get_one("SELECT MAX(`invoice_id`) + 1 AS new_invoice_id FROM " . TABLE_PREFIX . "mod_bakery_customer"); $database->query("UPDATE " . TABLE_PREFIX . "mod_bakery_customer SET transaction_status = 'paid', status = 'ordered', submitted = 'molliev2', invoice_id = '{$new_invoice_id}' WHERE transaction_id = '{$transaction_id}'"); sendMail($transaction_id); } elseif ($payment->isOpen() == true) { $database->query("UPDATE " . TABLE_PREFIX . "mod_bakery_customer SET transaction_status = 'pending', status = 'busy', submitted = 'molliev2' WHERE transaction_id = '{$transaction_id}'"); } } catch (Mollie_API_Exception $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); } } function sendMail($transaction_id) { global $database; $query_payment_methods = $database->query("SELECT cust_email_subject, cust_email_body, shop_email_subject, shop_email_body FROM " . TABLE_PREFIX . "mod_bakery_payment_methods WHERE directory = 'molliev2'");