示例#1
0
 /**
  * Mark fees as paid.
  *
  * This is called after a successful online payment.
  *
  * @param array $patron The patron array from patronLogin
  * @param int   $amount Amount to be registered as paid.
  *
  * @return mixed true if successfull, or PEAR_Error if registering failed.
  * @access public
  */
 public function markFeesAsPaid($patron, $amount)
 {
     $params = isset($this->config['OnlinePayment']['registrationParams']) ? $this->config['OnlinePayment']['registrationParams'] : array();
     $required = array('host', 'port', 'userId', 'password', 'locationCode');
     foreach ($required as $req) {
         if (!isset($params[$req])) {
             error_log("Missing SIP2 parameter {$req}");
             return new PEAR_Error('online_payment_registration_failed');
         }
     }
     $currency = $this->config['OnlinePayment']['currency'];
     $patronId = $patron['cat_username'];
     $errFun = function ($patronId, $error) {
         error_log("SIP2 payment error: {$error}");
         error_log("   patron: {$patronId}");
         return new PEAR_Error('online_payment_registration_failed');
     };
     $sip = new sip2();
     $sip->error_detection = false;
     $sip->msgTerminator = "\r";
     $sip->hostname = $params['host'];
     $sip->port = $params['port'];
     $sip->AO = '';
     // SIP expects payable amount to be a string
     // with ',' as a decimal point
     $amount = (string) ($amount / 100.0);
     $amount = str_replace('.', ',', $amount);
     if ($sip->connect()) {
         $sip->scLocation = $params['locationCode'];
         $sip->UIDalgorithm = 0;
         $sip->PWDalgorithm = 0;
         $login_msg = $sip->msgLogin($params['userId'], $params['password']);
         $login_response = $sip->get_message($login_msg);
         if (strncmp('94', $login_response, 2) == 0) {
             $login_result = $sip->parseLoginResponse($login_response);
             if ($login_result['fixed']['Ok'] == '1') {
                 $sip->patron = $patronId;
                 $feepaid_msg = $sip->msgFeePaid(1, 0, $amount, $currency);
                 $feepaid_response = $sip->get_message($feepaid_msg);
                 if (strncmp('38', $feepaid_response, 2) == 0) {
                     $feepaid_result = $sip->parseFeePaidResponse($feepaid_response);
                     if ($feepaid_result['fixed']['PaymentAccepted'] == 'Y') {
                         $sip->disconnect();
                         return true;
                     } else {
                         $sip->disconnect();
                         return $errFun($patronId, 'payment rejected');
                     }
                 } else {
                     $sip->disconnect();
                     return $errFun($patronId, 'payment failed');
                 }
             } else {
                 $sip->disconnect();
                 return $errFun($patronId, 'login failed');
             }
         } else {
             $sip->disconnect();
             return $errFun($patronId, 'login failed');
         }
     } else {
         return $errFun($patronId, 'connection error');
     }
     return true;
 }