예제 #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');
     }
 }
 public static function active($params = array(), $format = 'json')
 {
     if (array_key_exists("sale_id", $params)) {
         $result = Twocheckout_Sale::retrieve($params);
         $array = Twocheckout_Util::return_resp($result, 'array');
         if (!array_key_exists('errors', $array)) {
             $lineitemData = Twocheckout_Util::get_recurring_lineitems($array);
             if (isset($lineitemData[0])) {
                 if ($format == 'array') {
                     return Twocheckout_Util::return_resp($lineitemData, $format);
                 } else {
                     return Twocheckout_Util::return_resp($lineitemData, 'force_json');
                 }
             } else {
                 $result = Twocheckout_Message::message('Notice', 'No recurring lineitems.');
                 return Twocheckout_Util::return_resp($result, $format);
             }
         } else {
             return Twocheckout_Util::return_resp($result, $format);
         }
     } else {
         $result = Twocheckout_Message::message('Error', 'You must pass a sale_id to use this method.');
         return Twocheckout_Util::return_resp($result, $format);
     }
 }
예제 #3
0
 public static function active($params = array())
 {
     if (array_key_exists("sale_id", $params)) {
         $result = Twocheckout_Sale::retrieve($params);
         if (!is_array($result)) {
             $result = Twocheckout_Util::returnResponse($result, 'array');
         }
         $lineitemData = Twocheckout_Util::getRecurringLineitems($result);
         if (isset($lineitemData[0])) {
             $result = Twocheckout_Message::message('OK', $lineitemData);
             return Twocheckout_Util::returnResponse($result);
         } else {
             throw new Twocheckout_Error("No active recurring lineitems.");
         }
     } else {
         throw new Twocheckout_Error("You must pass a sale_id to use this method.");
     }
 }
예제 #4
0
 public static function active($params = array(), $format = 'json')
 {
     if (array_key_exists("sale_id", $params)) {
         $result = Twocheckout_Sale::retrieve($params);
         $array = Twocheckout_Util::return_resp($result, 'array');
         $lineitemData = Twocheckout_Util::get_recurring_lineitems($array);
         if (isset($lineitemData[0])) {
             $result = Twocheckout_Message::message('OK', $lineitemData);
             if ($format == 'array') {
                 return Twocheckout_Util::return_resp($result, $format);
             } else {
                 return Twocheckout_Util::return_resp($result, 'force_json');
             }
         } else {
             throw new Twocheckout_Error("No active recurring lineitems.");
         }
     } else {
         throw new Twocheckout_Error("You must pass a sale_id to use this method.");
     }
 }
예제 #5
0
/**
 * Cancel a 2checkout subscriber
 *
 * @access      private
 * @since       2.4
 */
function rcp_2checkout_cancel_member($member_id = 0)
{
    global $rcp_options;
    $user_name = defined('TWOCHECKOUT_ADMIN_USER') ? TWOCHECKOUT_ADMIN_USER : '';
    $password = defined('TWOCHECKOUT_ADMIN_PASSWORD') ? TWOCHECKOUT_ADMIN_PASSWORD : '';
    if (empty($user_name) || empty($password)) {
        return new WP_Error('missing_username_or_password', __('The 2Checkout API username and password must be defined', 'rcp'));
    }
    if (!class_exists('Twocheckout')) {
        require_once RCP_PLUGIN_DIR . 'includes/libraries/twocheckout/Twocheckout.php';
    }
    $secret_word = isset($rcp_options['sandbox']) ? trim($rcp_options['twocheckout_secret_word']) : '';
    $test_mode = isset($rcp_options['sandbox']);
    if ($test_mode) {
        $secret_key = isset($rcp_options['twocheckout_test_private']) ? trim($rcp_options['twocheckout_test_private']) : '';
        $publishable_key = isset($rcp_options['twocheckout_test_publishable']) ? trim($rcp_options['twocheckout_test_publishable']) : '';
        $seller_id = isset($rcp_options['twocheckout_test_seller_id']) ? trim($rcp_options['twocheckout_test_seller_id']) : '';
        $environment = 'sandbox';
    } else {
        $secret_key = isset($rcp_options['twocheckout_live_private']) ? trim($rcp_options['twocheckout_live_private']) : '';
        $publishable_key = isset($rcp_options['twocheckout_live_publishable']) ? trim($rcp_options['twocheckout_live_publishable']) : '';
        $seller_id = isset($rcp_options['twocheckout_live_seller_id']) ? trim($rcp_options['twocheckout_live_seller_id']) : '';
        $environment = 'production';
    }
    try {
        Twocheckout::privateKey($secret_key);
        Twocheckout::sellerId($seller_id);
        Twocheckout::username(TWOCHECKOUT_ADMIN_USER);
        Twocheckout::password(TWOCHECKOUT_ADMIN_PASSWORD);
        Twocheckout::sandbox($test_mode);
        $member = new RCP_Member($member_id);
        $sale_id = str_replace('2co_', '', $member->get_payment_profile_id());
        $cancelled = Twocheckout_Sale::stop(array('sale_id' => $sale_id));
        if ($cancelled['response_code'] == 'OK') {
            return true;
        }
    } catch (Twocheckout_Error $e) {
        return new WP_Error('2checkout_cancel_failed', $e->getMessage());
    }
}
예제 #6
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()));
         }
     }
 }
예제 #7
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;
 }
 function cancel(&$order)
 {
     // If recurring, stop the recurring payment
     if (pmpro_isLevelRecurring($order->membership_level)) {
         $params['sale_id'] = $order->payment_transaction_id;
         $result = Twocheckout_Sale::stop($params);
         // Stop the recurring billing
         // Successfully cancelled
         if (isset($result['response_code']) && $result['response_code'] === 'OK') {
             $order->updateStatus("cancelled");
             return true;
         } else {
             $order->status = "error";
             $order->errorcode = $result->getCode();
             $order->error = $result->getMessage();
             return false;
         }
     }
     return $order;
 }
예제 #9
0
 public function onAKPaymentCancelRecurring($paymentmethod, $data)
 {
     // Check if we're supposed to handle this
     if ($paymentmethod != $this->ppName) {
         return false;
     }
     // No subscription id? Stop here
     if (!$data['sid']) {
         return false;
     }
     // No cURL? Well, that's no point on continuing...
     if (!function_exists('curl_init')) {
         if (version_compare(JVERISON, '3.0', 'ge')) {
             throw new Exception('2CO payment plugin needs cURL extension in order to cancel recurring payments', 500);
         } else {
             JError::raiseError(500, '2CO payment plugin needs cURL extension in order to cancel recurring payments');
         }
     }
     // No API credentials? Let's stop here
     if (!$this->params->get('api_username') || !$this->params->get('api_password')) {
         if (version_compare(JVERISON, '3.0', 'ge')) {
             throw new Exception('You need to provide API username and password in order to cancel recurring payments', 500);
         } else {
             JError::raiseError(500, 'You need to provide API username and password in order to cancel recurring payments');
         }
     }
     require_once '2conew/lib/Twocheckout.php';
     $sub = F0FModel::getTmpInstance('Subscriptions', 'AkeebasubsModel')->getTable();
     $sub->load($data['sid']);
     list($sale_id, ) = explode('/', $sub->processor_key);
     Twocheckout::setCredentials($this->params->get('api_username'), $this->params->get('api_password'));
     $args = array('sale_id' => $sale_id);
     try {
         $result = Twocheckout_Sale::stop($args, 'array');
     } catch (Twocheckout_Error $e) {
         // Uh oh.. something bad happened. Let's log it
         $log['subid'] = $data['sid'];
         $log['sale_id'] = $sale_id;
         $log['message'] = $e->getMessage();
         $this->logData($log, false, 'CANCEL RECURRING');
         return false;
     }
     // Request was ok, but there was an error processing it
     if (strtoupper($result['response_code']) != 'OK') {
         $log['subid'] = $data['sid'];
         $log['sale_id'] = $sale_id;
         $log['result'] = print_r($result, true);
         $this->logData($log, false, 'CANCEL RECURRING');
         return false;
     }
     // Everything went ok, let's log it
     $log['subid'] = $data['sid'];
     $log['sale_id'] = $sale_id;
     $log['result'] = print_r($result, true);
     $this->logData($log, true, 'CANCEL RECURRING');
     return true;
 }
예제 #10
0
 public function testSaleReauth()
 {
     $params = array('sale_id' => 9093717691800);
     try {
         $result = Twocheckout_Sale::reauth($params);
         $this->assertEquals("OK", $result['response_code']);
     } catch (Exception $e) {
         $this->assertEquals("Payment is already pending or deposited and cannot be reauthorized.", $e->getMessage());
     }
 }
 function cancel(&$order)
 {
     //no matter what happens below, we're going to cancel the order in our system
     $order->updateStatus("cancelled");
     //require a subscription id
     if (empty($order->subscription_transaction_id)) {
         return false;
     }
     //build api params
     $params = array();
     $params['sale_id'] = $order->subscription_transaction_id;
     // Demo mode?
     if (empty($order->gateway_environment)) {
         $gateway_environment = pmpro_getOption("gateway_environment");
     } else {
         $gateway_environment = $order->gateway_environment;
     }
     if ("sandbox" === $gateway_environment || "beta-sandbox" === $gateway_environment) {
         Twocheckout::sandbox(true);
         $params['demo'] = 'Y';
     } else {
         Twocheckout::sandbox(false);
     }
     $result = Twocheckout_Sale::stop($params);
     // Stop the recurring billing
     // Successfully cancelled
     if (isset($result['response_code']) && $result['response_code'] === 'OK') {
         $order->updateStatus("cancelled");
         return true;
     } else {
         $order->status = "error";
         $order->errorcode = $result->getCode();
         $order->error = $result->getMessage();
         return false;
     }
     return $order;
 }