$payment_mode = $vcred[9];
 include_once 'sdk' . DS . 'Velocity.php';
 if ($payment_mode) {
     $isTestAccount = TRUE;
 } else {
     $isTestAccount = FALSE;
 }
 try {
     $velocityProcessor = new VelocityProcessor($applicationprofileid, $merchantprofileid, $workflowid, $isTestAccount, $identitytoken);
 } catch (Exception $e) {
     echo $e->getMessage();
     exit;
 }
 try {
     // request for refund
     $response = $velocityProcessor->returnById(array('amount' => $total_refund, 'TransactionId' => $txtid));
     $xml = VelocityXmlCreator::returnByIdXML(number_format($total_refund, 2, '.', ''), $txtid);
     // got ReturnById xml object.
     $req = $xml->saveXML();
     if (is_array($response) && !empty($response) && isset($response['Status']) && $response['Status'] == 'Successful') {
         $date = JFactory::getDate();
         // for current datetime
         /* save the returnbyid response into 'velocity transactions' custom table.*/
         $queryR = $db->getQuery(true);
         $columns = array('transaction_id', 'transaction_status', 'virtuemart_order_id', 'request_obj', 'response_obj', 'created_on', 'created_by', 'modified_on', 'modified_by');
         $values = array($db->quote($response['TransactionId']), $db->quote($response['TransactionState']), (int) $_POST['orderid'], $db->quote(serialize($req)), $db->quote(serialize($response)), $db->quote($date->format(JDate::$format)), (int) $_POST['userid'], $db->quote($date->format(JDate::$format)), (int) $_POST['userid']);
         $queryR->insert($db->quoteName('#__virtuemart_payment_plg_velocity'))->columns($db->quoteName($columns))->values(implode(',', $values));
         $db->setQuery($queryR);
         $flagR = $db->execute();
         /* Update the refund detail into comment table at admin order detail..*/
         $comment = 'ApprovalCode: ' . $response['ApprovalCode'] . '<br>Refund Transaction_Id: ' . $response['TransactionId'] . '<br> Order Total: ' . round($order_total, 2) . ' ' . $_POST['currency'] . '<br>Refunded Amount:' . $response['Amount'] . ' ' . $_POST['currency'];
예제 #2
0
 /******************************************************Undo******************************************************************************** */
 try {
     $response = $velocityProcessor->undo(array('TransactionId' => $adjusttxnid));
     if (isset($response['Status']) && $response['Status'] == 'Successful') {
         echo 'Undo Successful!</br>';
         echo 'TransactionId: ' . $response['TransactionId'] . '</br></br>';
     } else {
         // some error
         print_r($response);
     }
 } catch (Exception $e) {
     echo $e->getMessage();
 }
 /******************************************************ReturnById************************************************************************* */
 try {
     $response = $velocityProcessor->returnById(array('amount' => 5.03, 'TransactionId' => $authCapTransactionid));
     if (isset($response['Status']) && $response['Status'] == 'Successful') {
         echo 'ReturnById Successful!</br>';
         echo 'ApprovalCode: ' . $response['ApprovalCode'] . '</br></br>';
     } else {
         // some error
         print_r($response);
     }
 } catch (Exception $e) {
     echo $e->getMessage();
 }
 /******************************************************ReturnUnlinked************************************************************************* */
 try {
     $response = $velocityProcessor->returnUnlinked(array('amount' => 1.03, 'avsdata' => $avsData, 'carddata' => $cardDataKeyed, 'order_id' => '629203', 'entry_mode' => 'Keyed', 'IndustryType' => 'Ecommerce', 'Reference' => 'xyz', 'EmployeeId' => '11'));
     if (isset($response['Status']) && $response['Status'] == 'Successful') {
         echo 'ReturnUnlinked Successful!</br>';
 $merchantprofileid = MODULE_PAYMENT_VELOCITY_MERCHANTPROFILEID;
 if (MODULE_PAYMENT_VELOCITY_TESTMODE == 'Test') {
     $isTestAccount = TRUE;
 } else {
     $isTestAccount = FALSE;
 }
 try {
     $velocityProcessor = new VelocityProcessor($applicationprofileid, $merchantprofileid, $workflowid, $isTestAccount, $identitytoken);
 } catch (Exception $e) {
     $messageStack->add_session($e->getMessage(), 'error');
     zen_redirect(zen_href_link('velocityRefund'));
 }
 if ($refund_amount <= $order->info['total']) {
     try {
         // request for refund
         $response = $velocityProcessor->returnById(array('amount' => $refund_amount, 'TransactionId' => $txnid->fields['transaction_id']));
         $xml = VelocityXmlCreator::returnByIdXML(number_format($refund_amount, 2, '.', ''), $txnid->fields['transaction_id']);
         // got ReturnById xml object.
         $req = $xml->saveXML();
         $myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
         $txt = print_r($response, 1);
         fwrite($myfile, $txt);
         fclose($myfile);
         if (is_array($response) && !empty($response) && isset($response['Status']) && $response['Status'] == 'Successful') {
             /* save the returnbyid response into 'zen_velocity_transactions' custom table.*/
             $sql = "insert into " . TABLE_PAYMENT_VELOCITY_TRANSACTIONS . " (transaction_id, transaction_status, order_id, request_obj, response_obj) values (:transactionId, :transactionStatus, :orderID, :requestOBJ, :responseOBJ)";
             $sql = $db->bindVars($sql, ':transactionId', $response['TransactionId'], 'string');
             $sql = $db->bindVars($sql, ':transactionStatus', $response['Status'], 'string');
             $sql = $db->bindVars($sql, ':orderID', $refundD['oID'], 'string');
             $sql = $db->bindVars($sql, ':requestOBJ', serialize($req), 'string');
             $sql = $db->bindVars($sql, ':responseOBJ', serialize($response), 'string');
예제 #4
0
 /**
  * Refund
  *
  * @param \XLite\Model\Payment\BackendTransaction $transaction Backend transaction
  *
  * @return boolean
  */
 protected function doRefund(\XLite\Model\Payment\BackendTransaction $transaction)
 {
     $this->includeVelocityLibrary();
     $backendTransactionStatus = $transaction::STATUS_FAILED;
     $errorData = '';
     if ($this->getSetting('mode') == 'test') {
         $isTestAccount = true;
     } else {
         $isTestAccount = false;
     }
     try {
         $velocityProcessor = new \VelocityProcessor(self::$applicationprofileid, self::$merchantprofileid, self::$workflowid, $isTestAccount, self::$identitytoken);
     } catch (Exception $e) {
         $transaction->setDataCell('error_message', $e->getMessage(), 'Velocity error message');
         $errorData .= $e->getMessage();
     }
     $refund_amount = $transaction->getValue();
     $txnid = $transaction->getPaymentTransaction()->getDataCell('velocity_payment_id')->getValue();
     try {
         // request for refund
         $response = $velocityProcessor->returnById(array('amount' => $refund_amount, 'TransactionId' => $txnid));
         $xml = \VelocityXmlCreator::returnByIdXML($refund_amount, $txnid);
         // got ReturnById xml object.
         $req = $xml->saveXML();
         $obj_req = serialize($req);
         if (is_array($response) && !empty($response) && isset($response['Status']) && $response['Status'] == 'Successful') {
             $backendTransactionStatus = $transaction::STATUS_SUCCESS;
             $transaction->setDataCell('velocity_refund_id', $response['TransactionId'], 'Velocity Refund ID');
             $transaction->setDataCell('approval_code', $response['ApprovalCode'], 'Velocity Approval Code');
             $transaction->setDataCell('request_refund_object', $obj_req, 'Velocity Request Refund Object');
             $transaction->setDataCell('response_refund_object', serialize($response), 'Velocity Response Refund Object');
             $transaction->setDataCell('refund_status', $response['TransactionState'], 'Refund Transaction Status');
             $transaction->setStatus($backendTransactionStatus);
             \XLite\Core\Database::getEM()->flush();
         } else {
             if (is_array($response) && !empty($response)) {
                 $transaction->setDataCell('error_message', $response['StatusMessage'], 'Velocity error message');
                 $errorData .= $response['StatusMessage'];
             } else {
                 if (is_string($response)) {
                     $transaction->setDataCell('error_message', $response, 'Velocity error message');
                     $errorData .= $response;
                 } else {
                     $transaction->setDataCell('error_message', 'Unknown Error please contact the site admin', 'Velocity error message');
                     $errorData .= 'Unknown Error please contact the site admin';
                 }
             }
         }
     } catch (Exception $e) {
         $transaction->setDataCell('error_message', $e->getMessage(), 'Velocity error message');
         $errorData .= $e->getMessage();
     }
     if (\XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS == $backendTransactionStatus) {
         $order = $transaction->getPaymentTransaction()->getOrder();
         $paymentTransactionSums = $order->getRawPaymentTransactionSums();
         $refunded = $paymentTransactionSums['refunded'];
         $status = $refunded < $transaction->getPaymentTransaction()->getValue() ? \XLite\Model\Order\Status\Payment::STATUS_PART_PAID : \XLite\Model\Order\Status\Payment::STATUS_REFUNDED;
         $order->setPaymentStatus($status);
         \XLite\Core\TopMessage::getInstance()->addInfo('Payment has been refunded successfully');
     } else {
         $msg = 'Transaction failure';
         if (!empty($errorData)) {
             $msg .= '-' . $errorData;
         }
         \XLite\Core\TopMessage::getInstance()->addError($msg);
     }
     return \XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS == $backendTransactionStatus;
 }
 public function refund()
 {
     $this->load->model('payment/velocitycreditcard');
     require_once '././../sdk/Velocity.php';
     $json['error'] = '';
     $json['success'] = '';
     $identitytoken = $this->config->get('velocitycreditcard_identitytoken');
     $workflowid = $this->config->get('velocitycreditcard_workflowid');
     $applicationprofileid = $this->config->get('velocitycreditcard_applicationprofileid');
     $merchantprofileid = $this->config->get('velocitycreditcard_merchantprofileid');
     if ($this->config->get('velocitycreditcard_test')) {
         $isTestAccount = TRUE;
     } else {
         $isTestAccount = FALSE;
     }
     try {
         $velocityProcessor = new VelocityProcessor($applicationprofileid, $merchantprofileid, $workflowid, $isTestAccount, $identitytoken);
     } catch (Exception $e) {
         echo $e->getMessage();
         $json['error'] .= $e->getMessage();
     }
     $this->load->model('sale/order');
     $order_info = $this->model_sale_order->getOrder($this->request->post['order_id']);
     $order_shipping = $this->model_payment_velocitycreditcard->getShipping($this->request->post['order_id']);
     $sub_total = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false) - $this->currency->format($order_shipping, $order_info['currency_code'], $order_info['currency_value'], false);
     if ((double) $sub_total >= (double) $this->request->post['amount']) {
         try {
             $query = $this->db->query("select transaction_id from " . DB_PREFIX . "velocity_transactions where order_id =" . $this->request->post['order_id']);
             if (!isset($query->row['transaction_id'])) {
                 throw new Exception('Transaction id not found for the Order', '500');
             }
             $transaction_id = $query->row['transaction_id'];
             $refund_amount = $this->request->post['shipping'] === 'true' ? $this->request->post['amount'] + $order_shipping : $this->request->post['amount'];
             // request for refund
             $response = $velocityProcessor->returnById(array('amount' => $refund_amount, 'TransactionId' => $transaction_id));
             if (is_array($response) && !empty($response) && isset($response['Status']) && $response['Status'] == 'Successful') {
                 $xml = VelocityXmlCreator::returnByIdXML(number_format($refund_amount, 2, '.', ''), $transaction_id);
                 // got ReturnById xml object.
                 $req = $xml->saveXML();
                 /* save the returnbyid response into 'zen_velocity_transactions' custom table.*/
                 $this->db->query("insert into " . DB_PREFIX . "velocity_transactions (transaction_id, transaction_status, order_id, request_obj, response_obj) values('" . $response['TransactionId'] . "', '" . $response['TransactionState'] . "', '" . $this->request->post['order_id'] . "', '" . serialize($req) . "', '" . serialize($response) . "')");
                 $json['success'] .= 'Refund has been done successfully, txnid : ' . $response['TransactionId'];
                 //order status pending code is 1
                 $this->model_payment_velocitycreditcard->addOrderHistory($this->request->post['order_id'], 11, "Velocity Txn id" . $response['TransactionId'] . "<br>Txn status is " . $response['TransactionState'] . " <br> Amount is " . $refund_amount);
             } else {
                 if (is_array($response) && !empty($response)) {
                     $json['error'] .= $response['StatusMessage'];
                 } else {
                     if (is_string($response)) {
                         $json['error'] .= $response;
                     } else {
                         $json['error'] .= 'Unknown Error please contact the site admin';
                     }
                 }
             }
         } catch (Exception $e) {
             $json['error'] .= $e->getMessage();
         }
     } else {
         $json['error'] .= 'Refund amount can not be greater than ' . $sub_total . '  + shipping.';
     }
     $this->response->setOutput(json_encode($json));
 }