/**
  * Retrieve a customerInfo model filled with the addresses and the customer data
  * 
  * @param order $order
  * @param int $orderId
  * @return CustomerInfo
  */
 public static function getCustomerInfoModel(order $order, $orderId = null)
 {
     $customerInfo = new CustomerInfo();
     $customerInfo->setBillingAddressInfo(self::getBillingAdressInfo($order, $orderId))->setShippingAddressInfo(self::getShippingAdressInfo($order, $orderId));
     $customerInfo->setCreditInquiry('yes')->setDateOfBirth(rpDb::getCustomersDob($orderId, rpSession::getSessionEntry('customer_id')))->setEmail($order->customer['email_address'])->setFax(rpDb::getCustomersFax($orderId, rpSession::getSessionEntry('customer_id')))->setPhone($order->customer['telephone'])->setFirstName(is_null($orderId) ? $order->customer['firstname'] : rpDb::getShopOrderDataEntry($orderId, 'customers_firstname'))->setGender(is_null($orderId) ? $order->customer['gender'] : rpDb::getRatepayOrderDataEntry($orderId, 'gender'))->setIp(is_null($orderId) ? rpData::getCustomerIp() : $order->customer['cIP'])->setLastName(is_null($orderId) ? $order->customer['lastname'] : rpDb::getShopOrderDataEntry($orderId, 'customers_lastname'))->setNationality(is_array($order->customer['country']) ? $order->customer['country']['iso_code_2'] : rpDb::getRatepayOrderDataEntry($orderId, 'customers_country_code'));
     $vatId = rpDb::getCustomersVatId($orderId, rpSession::getSessionEntry('customer_id'));
     if (!empty($order->customer['company']) && !empty($vatId)) {
         $customerInfo->setCompany($order->customer['company'])->setVatId($vatId);
     }
     if ($order->info['payment_method'] === 'ratepay_sepa' && is_null($orderId)) {
         $payment = rpLoader::getRatepayPayment($order->info['payment_method']);
         $bankAccount = $payment->getBankData();
         $bankAccountInfo = new rpBankaccountInfo();
         $bankAccountInfo->setAccountNumber($bankAccount['accountnumber']);
         $bankAccountInfo->setBankName($bankAccount['bankname']);
         $bankAccountInfo->setOwner($bankAccount['owner']);
         if (!empty($bankAccount['bankcode'])) {
             $bankAccountInfo->setBankAccount($bankAccount['bankcode']);
         }
         $customerInfo->setBankAccount($bankAccountInfo);
     }
     return $customerInfo;
 }
 /**
  * Call PAYMENT_CHANGE with the subtype credit
  * and add a credit item to the order
  */
 public static function creditAction()
 {
     $post = rpGlobals::getPost();
     $orderId = rpGlobals::getPostEntry('order_number');
     $creditAmount = floatval($post['voucherAmount'] . '.' . $post['voucherAmountKomma']);
     $deliveredBasketAmount = rpDb::getRpBasketAmount($orderId);
     if ($creditAmount <= $deliveredBasketAmount) {
         $order = new order($orderId);
         $rate = $order->info['payment_method'] == 'ratepay_rate' ? true : false;
         $payment = rpLoader::getRatepayPayment($order->info['payment_method']);
         $transactionId = rpDb::getRatepayOrderDataEntry($orderId, 'transaction_id');
         $transactionShortId = rpDb::getRatepayOrderDataEntry($orderId, 'transaction_short_id');
         if ($rate) {
             $subType = 'return';
             $postCredit = self::getRefundPostData($post);
         } else {
             $subType = 'credit';
         }
         $postCredit['order_number'] = $post['order_number'];
         $postCredit['voucherAmount'] = $post['voucherAmount'];
         $postCredit['voucherAmountKomma'] = $post['voucherAmountKomma'];
         $data = array('HeadInfo' => rpRequestMapper::getHeadInfoModel($order, $transactionId, $transactionShortId, $orderId, $subType), 'BasketInfo' => rpRequestMapper::getBasketInfoModel($order, $orderId, $postCredit, $subType), 'PaymentInfo' => rpRequestMapper::getPaymentInfoModel($order, $orderId, $postCredit, $subType));
         $requestService = new rpRequestService($payment->sandbox, $data);
         $result = $requestService->callPaymentChange();
         rpDb::xmlLog($order, $requestService->getRequest(), $orderId, $requestService->getResponse());
         if (!array_key_exists('error', $result)) {
             rpSession::setRpSessionEntry('message_css_class', 'messageStackSuccess');
             rpSession::setRpSessionEntry('message', RATEPAY_ORDER_MESSAGE_CREDIT_SUCCESS);
             rpDb::setRpCreditItem(rpGlobals::getPost(), $rate ? 1 : 0);
             rpDb::setRpHistoryEntry($orderId, rpData::getCreditItem($post), 'PAYMENT_CHANGE', $subType);
             rpDb::addCreditToShop($orderId, $post);
             rpDb::updateShopOrderTotals($orderId);
         } else {
             rpSession::setRpSessionEntry('message_css_class', 'messageStackError');
             rpSession::setRpSessionEntry('message', RATEPAY_ORDER_MESSAGE_CREDIT_ERROR);
         }
         if ($rate) {
             xtc_redirect(xtc_href_link("ratepay_order.php", 'oID=' . $orderId, 'SSL'));
         } else {
             self::deliverAction(self::getDeliverPostArray($orderId, $post['items']));
         }
     } else {
         rpSession::setRpSessionEntry('message_css_class', 'messageStackError');
         rpSession::setRpSessionEntry('message', RATEPAY_ORDER_MESSAGE_CREDIT_ERROR);
         xtc_redirect(xtc_href_link("ratepay_order.php", 'oID=' . $orderId, 'SSL'));
     }
 }
示例#3
0
 /**
  * Retrieve the credntials for the requets
  *
  * @param string $payment
  * @return array
  */
 public static function getCredentials($payment)
 {
     $payment = rpLoader::getRatepayPayment($payment);
     return array('profileId' => $payment->profileId, 'securityCode' => $payment->securityCode);
 }
示例#4
0
 /**
  * This method save's all necessary request and response informations in the database
  *
  * @param order $order
  * @param rpSimpleXmlExtended $request
  * @param string $orderId
  * @param SimpleXMLElement $response
  */
 public static function xmlLog($order, $request, $orderId = 'N/A', $response = null)
 {
     require_once dirname(__FILE__) . '/../../../../lang/' . rpSession::getLang() . '/modules/payment/' . $order->info['payment_method'] . '.php';
     $payment = rpLoader::getRatepayPayment($order->info['payment_method']);
     if ($payment->logging) {
         $transactionId = 'N/A';
         $subType = 'N/A';
         if ($request->head->{'transaction-id'}) {
             $transactionId = (string) $request->head->{'transaction-id'};
         }
         if ($request->head->operation->attributes()->subtype) {
             $subType = (string) $request->head->operation->attributes()->subtype;
         }
         $operation = (string) $request->head->operation;
         $responseXml = 'N/A';
         if (!empty($response)) {
             $responseXml = $response->asXML();
             $result = (string) $response->head->processing->result;
             $resultCode = (string) $response->head->processing->result->attributes()->code;
             $reasonText = (string) $response->head->processing->reason;
             if ($response->head->{'transaction-id'}) {
                 $transactionId = (string) $response->head->{'transaction-id'};
             }
         } else {
             $result = "Service unavaible.";
             $resultCode = "Service unavaible.";
         }
         $sql = "INSERT INTO ratepay_log " . "(" . "order_number, " . "transaction_id, " . "payment_method, " . "payment_type,  " . "payment_subtype, " . "result, " . "request, " . "response, " . "result_code, " . "reason" . ") " . "VALUES ('" . xtc_db_input($orderId) . "', '" . xtc_db_input($transactionId) . "', '" . xtc_db_input($payment->title) . "', '" . xtc_db_input($operation) . "', '" . xtc_db_input($subType) . "', '" . xtc_db_input($result) . "','" . xtc_db_input(utf8_decode($request->asXML())) . "','" . xtc_db_input($responseXml) . "','" . xtc_db_input($resultCode) . "','" . xtc_db_input($reasonText) . "')";
         xtc_db_query($sql);
         if ($operation == "PAYMENT_CONFIRM" && $transactionId != 'N/A') {
             $sql = "UPDATE ratepay_log SET order_number = '" . xtc_db_input($orderId) . "' WHERE transaction_id = '" . xtc_db_input($transactionId) . "';";
             xtc_db_query($sql);
         }
     }
 }