s2dpaywp.php /// Art: Payment /// Inhalt: Transaktionsscript für Worldpay /// Beschreibung: Nimmt die Rückmeldung von Worldpay entgegen und wertet diese entsprechend aus. /// Benötigt: normal /// CCML-Parsing: notwendig /// //////////////////////////////////////////////////////////////////////////// /// /// Letzte Änderungen: /// 16.02.2009 Bugfix /// //////////////////////////////////////////////////////////////////////////// ///<16.02.2009/6.0.3.9/> define('ROOT', './'); define('ASSETS', ROOT.'assets/'); require(ASSETS.'s2diconf.php'); require(CC_INCLUDE_INIT); $log = handle_transaction(); // Log speichern if (LOG_PAYMENT) save_to_file(FILE_PAYMENTLOG, "\nWorldPay Log ".time()."\n".$log); if ($log != 'success') { if (!$myorder || !$payment_id) script_die(CC_RESSOURCE_FORBIDDEN, __FILE__, __LINE__); $log = 'error'; } echo ''.CC_RESSOURCE_BASKETNEXT.''; echo ''; //////////////////////////////////////////////////////////////////////////// function handle_transaction() { global $payment_id, $myorder; // Host checken if (!preg_match('/\.worldpay\.com$/', $host = gethostbyaddr($_SERVER['REMOTE_ADDR']))) return "Invalid host $host\n"; //////////////////////////////////////////////////////////////////////////// Überprüfungen // Bezahlmethode einlesen $payment_id = is_post('MC_payment_id') ? post('MC_payment_id') : null; $payment = new payment(); if (!$pm = $payment->get($payment_id)) return "Cannot open payment $payment_id\n"; // Verkäuferkonto Überprüfen $inst_id = is_post('instId') ? intval(post('instId', CHECK_NUM)) : null; if ($inst_id != $pm->parameter[1]) return "InstId mismatch: '$inst_id' and '".$pm->parameter[1]."' \n"; // Passwort überprüfen $pw = is_post('callbackPW') ? post('callbackPW', CHECK_ALL) : null; if ($pw != $pm->parameter[2]) return "Password mismatch: '$pw' and '".$pm->parameter[2]."' \n"; // Bestellung laden und Bestellnummer überprüfen $order_id = is_post('cartId') ? intval(post('cartId', CHECK_NUM)) : null; $myorder = new order($order_id); if ($myorder->order_id != $order_id) return "Order ID mismatch: '$order_id' and '".$myorder->order_id."' \n"; // Preis überprüfen $price = is_post('authAmount') ? floatval(post('authAmount', CHECK_REALNUMVALUE)) : null; if ($price != $myorder->get_totalprice()) return "Price mismatch: '$price' and '".$myorder->get_totalprice()."' \n"; // Währung überprüfen $currency_code = is_post('currency') ? post('currency') : ''; if ($currency_code != $pm->parameter[3]) return "Currency mismatch: '$currency_code' and '".$pm->parameter[3]."' \n"; // Schlüssel überprüfen $key = is_post('MC_key') ? post('MC_key') : null; if ($myorder->generate_key() != $key) return "Key mismatch: '$key' and '".$myorder->generate_key()."' \n"; // Status Y = Zahlung erfolgt, C = Abbruch $result = is_post('transStatus') && post('transStatus') == 'Y' ? 'success' : 'error'; //////////////////////////////////////////////////////////////////////////// Zahlung abschliessen // Falls Sofortspeicherung aktiviert ist, neuen Status eintragen if ($result == 'success' && $pm->autocharge) { $myorder->set_status(CC_RESSOURCE_ORDERSTATUSSHORT_WAITINGITEMS, true); $myorder->send_status_email(); } return $result; } ?>