コード例 #1
0
ファイル: admin.php プロジェクト: adrianlinner333/laravel-5
 /**
  * Action refund the transaction
  */
 public function actionRefund()
 {
     $result = array();
     $message = '';
     // Check original VendorTxCode
     if (filter_input(INPUT_GET, 'origVtx')) {
         $payment = new ModelPayment();
         $result = $payment->getByVendorTxCode(filter_input(INPUT_GET, 'origVtx'));
         $origVtx = filter_input(INPUT_GET, 'origVtx');
     } else {
         if (filter_input(INPUT_POST, 'origVtx')) {
             $payment = new ModelPayment();
             $result = $payment->getByVendorTxCode(filter_input(INPUT_POST, 'origVtx'));
             $origVtx = filter_input(INPUT_POST, 'origVtx');
             $data = array('VPSProtocol' => $this->sagepayConfig->getProtocolVersion(), 'TxType' => SAGEPAY_TXN_REFUND, 'Vendor' => $this->sagepayConfig->getVendorName(), 'VendorTxCode' => filter_input(INPUT_POST, 'VendorTxCode'), 'Amount' => filter_input(INPUT_POST, 'Amount'), 'Currency' => $this->sagepayConfig->getCurrency(), 'Description' => filter_input(INPUT_POST, 'Description'), 'RelatedVPSTxId' => $result['vpsTxId'], 'RelatedVendorTxCode' => filter_input(INPUT_POST, 'origVtx'), 'RelatedSecurityKey' => $result['securityKey'], 'RelatedTxAuthNo' => $result['txAuthNo']);
             $maxAmount = $result['capturedAmount'] - (double) $payment->getRelatedAmount($origVtx);
             $this->_rules['Amount'][] = array('range', array(0, $maxAmount));
             $errors = $this->validate($this->_rules, $data);
             $hMessage = new HelperMessage();
             $message = $hMessage->getAllMessages($errors);
             // Check if refund was failed
             if (!$errors) {
                 $response = SagepayCommon::requestPost($this->sagepayConfig->getSharedUrl('refund'), $data);
                 if ($response['Status'] == SAGEPAY_REMOTE_STATUS_OK) {
                     $response['StatusDetail'] = 'REFUND transaction taken through Order Admin area';
                 }
                 $result = $this->ucFirstFields($result);
                 unset($result['CapturedAmount']);
                 $refundedTx = array_merge($result, $data, $response);
                 $payment->insert($refundedTx);
                 $query = array('requestBody' => SagepayUtil::arrayToQueryString($data), 'resultBody' => SagepayUtil::arrayToQueryString($response), 'status' => $response['Status'], 'command' => SAGEPAY_TXN_REFUND);
                 $this->redirect($this->integrationType, 'admin_result', $query);
             } else {
                 $this->error = true;
             }
         }
     }
     // render refund page
     if (!empty($result)) {
         $view = new HelperView('admin/refund');
         $view->setData(array('env' => $this->sagepayConfig->getEnv(), 'vendorName' => $this->sagepayConfig->getVendorName(), 'integrationType' => $this->integrationType, 'result' => $result, 'refundVtx' => SagepayCommon::vendorTxCode(time(), SAGEPAY_TXN_REFUND, $this->sagepayConfig->getVendorName()), 'alreadyRefundedAmount' => number_format($payment->getRelatedAmount($origVtx), 2), 'val' => array('ok' => !$this->error, 'errorStatusString' => $message)));
         $view->render();
     } else {
         $this->redirect($this->integrationType, 'admin');
     }
 }