COOKIE = '../data/'.time().'.tmp'; } /** * Method: login * ------------------------------------------------------------------------- * This method will make the first request to login to the MOTO Interface. * Simply returning true or false. * * @access public * @return boolean */ public function login() { // Make the request $ch = curl_init(); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt_array($ch, array ( CURLOPT_URL => $GLOBALS['config']->MODS->BB->URL . 'login.s', CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_COOKIEJAR => $this->COOKIE, CURLOPT_POSTFIELDS => array ( 'mappedUrl' => '/BENDIGO', 'is-login-request' => 'true', 'ownerId' => $GLOBALS['config']->MODS->BB->MERCHANT_ID, 'userName' => $GLOBALS['config']->MODS->BB->USERNAME, 'password' => $GLOBALS['config']->MODS->BB->PASSWORD, 'loginForm' => 'LOG IN' ) )); $data = curl_exec($ch); curl_close($ch); // Process the request - did we manage to login or not if (strpos($data, 'Welcome')) { // Okay so we logged in, now we need to grab the stupid CSRF value $this->CSRF = substr($data, strpos($data, "{'csrf':'")+9); $this->CSRF = substr($this->CSRF, 0, strpos($this->CSRF, "'});")); return true; } else return false; } /** * Method: logout * ------------------------------------------------------------------------- * All this does is deletes the cookie * * @access public * @return boolean */ public function logout() { unlink($this->COOKIE); if (!file_exists($this->COOKIE)) return true; else return false; } /** * Method: process_card * ------------------------------------------------------------------------- * This method will process a card and return a response code. * * @access public * @return string */ public function process_card($card_number, $card_expiry_month, $card_expiry_year, $cvv, $amount, $name, $reference) { // Lets do some validation // testing... return $amount; if (!toolBox('ValidLuhn', array($card_number))) { return 'INVALID CREDIT CARD NUMBER'; } if (!is_numeric($card_expiry_month) || strlen($card_expiry_month) > 2) { return 'INVALID EXPIRY MONTH'; } if (!is_numeric($card_expiry_year) || strlen($card_expiry_year) > 2) { return 'INVALID EXPIRY YEAR'; } if (!empty($cvv) && (!is_numeric($cvv) || strlen($cvv) > 4)) { return 'INVALID CVV NUMBER'; } // Make the request $fh = fopen('/tmp/curl.out','w') or die($php_errormsg); $ch = curl_init(); curl_setopt_array($ch, array ( CURLOPT_VERBOSE => 1, CURLOPT_DEBUGFUNCTION => 1, CURLOPT_STDERR => $fh, CURLOPT_URL => $GLOBALS['config']->MODS->BB->URL . 'initialTransactionEntry.s?csrf='.$this->CSRF, CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_COOKIEFILE => $this->COOKIE, CURLOPT_POSTFIELDS => array ( 'requestType' => 'initTransaction', 'orderNumber' => $reference, 'amount' => $amount, 'avsData.cardholderName' => $name, 'cleartextCardNumber' => $card_number, 'cardExpiryMonth' => $card_expiry_month, 'cardExpiryYear' => $card_expiry_year, 'csc' => $cvv, 'avsData.address.countryCode' => 'AUS', 'submit' => 'Submit' ) )); $data = curl_exec($ch); curl_close($ch); // Process the request - what response code did we get if (strpos($data, '0 - Approved')) { return 'APPROVED'; } elseif (strpos($data, '2 - Declined')) { return 'DECLINED'; } elseif (strpos($data, 'Invalid card number')) { return 'INVALID CARD NUMBER'; } elseif (strpos($data, '4 - Expired Card')) { return 'EXPIRED CARD'; } elseif (strpos($data, '5 - Insufficient Funds')) { return 'INSUFFICIENT FUNDS'; } elseif (strpos($data, 'Entered amount is invalid.')) { return 'AMOUNT IS INVALID'; } elseif (strpos($data, '3 - Timed Out')) { return 'TIMED OUT'; } else { // Lets send an error report email $mail = new Zend_Mail('utf-8'); $mail->setType(Zend_Mime::MULTIPART_RELATED); $mail->setBodyHtml($data,null,Zend_Mime::MULTIPART_RELATED); $mail->setFrom('noreply@hugonet.com.au', 'No-Reply'); $mail->addTo($GLOBALS['config']->ERROR_TO); $mail->setSubject('TarkaPlus SERVER Bendigo Bank (9 - UNKNOWN ERROR)'); $mail->send(); return '9 - UNKNOWN ERROR'; } } /** * Method: refund_card * ------------------------------------------------------------------------- * This will refund a given transaction. * You must know the Order Id so that we know we are refunding * the correct card. And the amount that you wish to refund. * * NOTE: That you dont have to refund the whole amount... * * @access public * @return boolean */ public function refund_card($amount, $order_id) { // Search for the Transaction. $ch = curl_init(); curl_setopt_array($ch, array ( CURLOPT_URL => $GLOBALS['config']->MODS->BB->URL . 'orderSearch.s?csrf='.$this->CSRF, CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_COOKIEFILE => $this->COOKIE, CURLOPT_POSTFIELDS => array ( 'fromDate' => '', 'toDate' => '', 'orderId' => $order_id, 'acquirerId' => '', 'merchantTransactionSource' => '', 'transactionState' => '', 'submit' => 'Submit' ) )); $html = curl_exec($ch); curl_close($ch); // Extract the Order System Id $order_system_id = toolBox('StrBetween', array ( $html, '' )); // Extract the transaction type $transaction_type = toolBox('StrBetween', array ( $html, '' )); // Make sure we actually found a card if (is_numeric($order_system_id)) { // Make sure we have a card that can be refunded if ($transaction_type == 'RFND') { // Make the refund. $ch = curl_init(); curl_setopt_array($ch, array ( CURLOPT_URL => $GLOBALS['config']->MODS->BB->URL . 'orderDetails.s?csrf='.$this->CSRF, CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_COOKIEFILE => $this->COOKIE, CURLOPT_POSTFIELDS => array ( 'orderSystemId' => $order_system_id, 'orderId' => $order_id, 'transactionType' => 'RFND', 'amount' => $amount, 'submit' => 'Refund' ) )); $data = curl_exec($ch); curl_close($ch); } else { // This card has already been refunded... $data = 'CAN NOT REFUND'; } } else { // We could not find an extacrt match to the order id $data = 'ORDER ID NOT FOUND'; } // Process the request - what response code did we get if (strpos($data, '0 - Approved')) { return '0 - APPROVED'; } elseif($data == 'ORDER ID NOT FOUND') { return '1 - ORDER ID NOT FOUND'; } elseif($data == 'CAN NOT REFUND') { return '2 - CARD ALREADY REFUNDED'; } else { // Lets send an error report email $mail = new Zend_Mail('utf-8'); $mail->setType(Zend_Mime::MULTIPART_RELATED); $mail->setBodyHtml($data,null,Zend_Mime::MULTIPART_RELATED); $mail->setFrom('noreply@hugonet.com.au', 'No-Reply'); $mail->addTo($GLOBALS['config']->ERROR_TO); $mail->setSubject('TarkaPlus SERVER Bendigo Bank (9 - UNKNOWN ERROR)'); $mail->send(); return '9 - UNKNOWN ERROR'; } } }