예제 #1
1
 public function cancel()
 {
     if ($this->input->post('cancel')) {
         $user = $this->ion_auth->user()->row();
         $order_number = $user->order_number;
         $invoice_id = $user->last_invoice;
         //Define API User and Password
         Twocheckout::setCredentials("APIuser1817037", "APIpass1817037");
         //Stop recurring billing
         $args = array('sale_id' => $order_number);
         Twocheckout_Sale::stop($args, 'array');
         $last_bill_date = $user->last_billed;
         $next_bill_date = strtotime('+1 month', $last_bill_date);
         $remaining_days = floor(abs(time() - $next_bill_date) / 60 / 60 / 24);
         $refund_amount = round(1.0 / 30 * $remaining_days, 2);
         //Refund remaining balance
         $args = array('invoice_id' => $invoice_id, 'category' => 5, 'amount' => $refund_amount, 'currency' => 'vendor', 'comment' => 'Refunding remaining balance');
         Twocheckout_Sale::refund($args, 'array');
         //Deactivate User
         $id = $user->id;
         $data = array('active' => 0);
         $this->ion_auth->update($id, $data);
         $this->ion_auth->logout();
         //Reinit $data array for view
         $data = array('remaining_days' => $remaining_days, 'refund_amount' => $refund_amount);
         $this->load->view('/include/header');
         $this->load->view('/include/navblank');
         $this->load->view('/order/cancel_success', $data);
         $this->load->view('/include/footer');
     } else {
         $this->load->view('/include/header');
         $this->load->view('/include/navblank');
         $this->load->view('/order/cancel');
         $this->load->view('/include/footer');
     }
 }
예제 #2
0
 public function testSaleRefundLineitem()
 {
     $params = array('lineitem_id' => 9093717693210, 'category' => 1, 'comment' => 'Order never sent.');
     try {
         $sale = Twocheckout_Sale::refund($params);
         $this->assertEquals("OK", $sale['response_code']);
     } catch (Twocheckout_Error $e) {
         $this->assertEquals("Lineitem was already refunded.", $e->getMessage());
     }
 }
예제 #3
0
 public function issue_creditmemo_refund(Varien_Object $payment)
 {
     $refund = Mage::getStoreConfig('payment/twocheckout/refund');
     if ($refund == '1') {
         $order = $payment->getCreditmemo()->getOrder();
         $creditmemo = $payment->getCreditmemo()->getOrder()->getData();
         $creditmemo_amount = $payment->getCreditmemo()->getData();
         $creditmemo_comment = $payment->getCreditmemo()->getCommentsCollection()->toArray();
         if (isset($creditmemo_comment['items'][0]['comment'])) {
             $comment = $creditmemo_comment['items'][0]['comment'];
         } else {
             $comment = 'Refund issued by seller';
         }
         $username = Mage::getStoreConfig('payment/twocheckout/username');
         $password = Mage::getStoreConfig('payment/twocheckout/password');
         $sandbox = Mage::getStoreConfig('payment/twocheckout/demo');
         Twocheckout::username($username);
         Twocheckout::password($password);
         if ($sandbox == "1") {
             Twocheckout::sandbox(true);
         } else {
             Twocheckout::sandbox(false);
         }
         $data = array();
         $data['invoice_id'] = $creditmemo['ext_order_id'];
         $data['comment'] = $comment;
         $data['category'] = '5';
         $data['amount'] = $creditmemo_amount['grand_total'];
         $data['currency'] = 'vendor';
         try {
             $response = Twocheckout_Sale::refund($data);
             $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
             $order->addStatusHistoryComment($response["response_message"]);
             $order->save();
         } catch (Twocheckout_Error $e) {
             Mage::throwException(Mage::helper('core')->__($e->getMessage()));
         }
     }
 }
예제 #4
0
 function tcheckout_refund($transaction_id, $partial_amt = false, $note)
 {
     $this->set_gateway_param();
     $params = array('invoice_id' => $transaction_id, 'comment' => $note, 'category' => 5);
     if ($partial_amt) {
         $params['amount'] = $partial_amt;
         $params['currency'] = 'vendor';
     }
     $result = false;
     try {
         $result = Twocheckout_Sale::refund($params, 'array');
     } catch (Exception $e) {
         //
         $result = array('response_code' => 'FAIL', 'errors' => array(array('message' => $e->getMessage())));
     }
     return $result;
 }