function sendToTwocheckout(&$order) { global $pmpro_currency; // Set up credentials Twocheckout::setCredentials(pmpro_getOption("twocheckout_apiusername"), pmpro_getOption("twocheckout_apipassword")); $tco_args = array('sid' => pmpro_getOption("twocheckout_accountnumber"), 'mode' => '2CO', 'li_0_type' => 'product', 'li_0_name' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127), 'li_0_quantity' => 1, 'li_0_tangible' => 'N', 'li_0_product_id' => $order->code, 'merchant_order_id' => $order->code, 'currency_code' => $pmpro_currency, 'pay_method' => 'CC', 'purchase_step' => 'billing-information', 'x_receipt_link_url' => admin_url("admin-ajax.php") . "?action=twocheckout-ins"); //taxes on initial amount $initial_payment = $order->InitialPayment; $initial_payment_tax = $order->getTaxForPrice($initial_payment); $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2); //taxes on the amount (NOT CURRENTLY USED) $amount = $order->PaymentAmount; $amount_tax = $order->getTaxForPrice($amount); $amount = round((double) $amount + (double) $amount_tax, 2); // Recurring membership if (pmpro_isLevelRecurring($order->membership_level)) { $tco_args['li_0_startup_fee'] = number_format($initial_payment - $amount, 2); //negative amount for lower initial payments $recurring_payment = $order->membership_level->billing_amount; $recurring_payment_tax = $order->getTaxForPrice($recurring_payment); $recurring_payment = round((double) $recurring_payment + (double) $recurring_payment_tax, 2); $tco_args['li_0_price'] = number_format($recurring_payment, 2); $tco_args['li_0_recurrence'] = $order->BillingFrequency == 1 ? $order->BillingFrequency . ' ' . $order->BillingPeriod : $order->BillingFrequency . ' ' . $order->BillingPeriod . 's'; if (property_exists($order, 'TotalBillingCycles')) { $tco_args['li_0_duration'] = $order->BillingFrequency * $order->TotalBillingCycles . ' ' . $order->BillingPeriod; } else { $tco_args['li_0_duration'] = 'Forever'; } } else { $tco_args['li_0_price'] = $initial_payment; } // Demo mode? $environment = pmpro_getOption("gateway_environment"); if ("sandbox" === $environment || "beta-sandbox" === $environment) { $tco_args['demo'] = 'Y'; } // Trial? //li_#_startup_fee Any start up fees for the product or service. Can be negative to provide discounted first installment pricing, but cannot equal or surpass the product price. if (!empty($order->TrialBillingPeriod)) { $trial_amount = $order->TrialAmount; $trial_tax = $order->getTaxForPrice($trial_amount); $trial_amount = round((double) $trial_amount + (double) $trial_tax, 2); $tco_args['li_0_startup_fee'] = $trial_amount; // Negative trial amount } $ptpStr = ''; foreach ($tco_args as $key => $value) { reset($tco_args); // Used to verify whether or not we're on the first argument $ptpStr .= $key == key($tco_args) ? '?' . $key . '=' . urlencode($value) : '&' . $key . '=' . urlencode($value); } //anything modders might add $additional_parameters = apply_filters('pmpro_twocheckout_return_url_parameters', array()); if (!empty($additional_parameters)) { foreach ($additional_parameters as $key => $value) { $ptpStr .= "&" . urlencode($key) . "=" . urlencode($value); } } $ptpStr = apply_filters('pmpro_twocheckout_ptpstr', $ptpStr, $order); //echo str_replace("&", "&<br />", $ptpStr); //exit; //redirect to 2checkout $tco_url = 'https://www.2checkout.com/checkout/purchase' . $ptpStr; //echo $tco_url; //die(); wp_redirect($tco_url); exit; }
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 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; }