예제 #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 testSaleStopLineitem()
 {
     $params = array('lineitem_id' => 9093717693210);
     try {
         $response = Twocheckout_Sale::stop($params);
         $this->assertEquals("OK", $response['response_code']);
     } catch (Twocheckout_Error $e) {
         $this->assertEquals("Lineitem is not scheduled to recur.", $e->getMessage());
     }
 }
예제 #3
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());
    }
}
예제 #4
0
 function tcheckout_cancel_subscription($profile_id)
 {
     $this->set_gateway_param();
     //check does this has cancel or not
     if (!$this->tcheckout_is_subscription_cancel($profile_id)) {
         $result = Twocheckout_Sale::stop(array('sale_id' => $profile_id), 'array');
         return $result;
     }
     return false;
 }
 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;
 }
예제 #6
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;
 }
 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;
 }