public function checkout(Request $request)
 {
     $response = new stdClass();
     if ($request->isMethod('post')) {
         $postData = $request->all();
         $userId = $postData['id'];
         $token = $postData['token'];
         $amount = $postData['money'];
         $name = $postData['name'];
         $addrLine1 = $postData['addrLine1'];
         $city = $postData['city'];
         $state = $postData['state'];
         $country = $postData['country'];
         $email = $postData['email'];
         $zipCode = $postData['zipCode'];
         $phoneNumber = $postData['phoneNumber'];
         $authFlag = false;
         if (isset($postData['api_token'])) {
             $apiToken = $postData['api_token'];
             if ($apiToken == $this->API_TOKEN) {
                 $authFlag = true;
             } else {
                 $authFlag = false;
             }
         }
         if ($authFlag) {
             $rules = array('money' => 'required|regex:/^[0-9]+([.][0-9]{0,2}+)?$/', 'name' => 'required', 'addrLine1' => 'required', 'city' => 'required', 'state' => 'required', 'zipCode' => 'required', 'country' => 'required', 'email' => 'required', 'phoneNumber' => 'required');
             $message = array('money.required' => 'Please Enter Amount that you want to add to your wallet', 'money.regex' => 'Please Enter a valid Amount i.e. number or decimal value ', 'name.required' => 'please enter your name', 'addrLine1.required' => 'please enter address', 'city.required' => 'please enter city', 'state.required' => 'please enter state', 'zipCode.required' => 'please provide zip code', 'country.required' => 'please specify country name', 'email.required' => 'please enter your email', 'phoneNumber.required' => 'please enter your phone number');
             $validator = Validator::make($request->all(), $rules, $message);
             if (!$validator->fails()) {
                 \Twocheckout::privateKey('1768AF13-92B6-4B9D-8493-66E884E98FEF');
                 \Twocheckout::sellerId('901311477');
                 \Twocheckout::sandbox(true);
                 #Uncomment to use Sandbox
                 \Twocheckout::verifySSL(false);
                 try {
                     $charge = \Twocheckout_Charge::auth(array("merchantOrderId" => "123", "token" => $token, "currency" => 'USD', "total" => $amount, "billingAddr" => array("name" => $name, "addrLine1" => $addrLine1, "city" => $city, "state" => $state, "zipCode" => $zipCode, "country" => $country, "email" => $email, "phoneNumber" => $phoneNumber)));
                     //                        echo json_encode($charge,true);die;
                     //                        echo '<pre>';
                     //            print_r($charge);die;
                     if ($charge['response']['responseCode'] == 'APPROVED') {
                         //                            echo "Thanks for your Order!";
                         //                            echo "<h3>Return Parameters:</h3>";
                         //                            echo "<pre>";
                         //                            print_r($charge);
                         //                            echo "</pre>";
                         //                            echo die;
                         $transactionId = $charge['response']['transactionId'];
                         $objModelTransaction = new Transaction();
                         $input = array('tx_id' => '', 'tx_type' => '1', 'tx_mode' => '1', 'tx_code' => ' ', 'transaction_id' => $transactionId, 'user_id' => $userId, 'amount' => $amount, 'payment_time' => time() + 19800);
                         $result = $objModelTransaction->addNewTransaction($input);
                         //code for increasing the amount (updating the account bal)
                         // first checking that user has details in usersmeta table or not, if not then acc_bal will be 0 & add users with amount
                         // or if yes then update accountbalance
                         $objModelUsermeta = new Usersmeta();
                         $whereForUpdateUser = array('rawQuery' => 'user_id = ?', 'bindParams' => [$userId]);
                         $isUserAvailable = $objModelUsermeta->getUsermetaWhere($whereForUpdateUser);
                         if ($isUserAvailable) {
                             $accountBal = $isUserAvailable->account_bal;
                             $totalBalance = $accountBal + $amount;
                             $dataForUpdateUser = array('account_bal' => $totalBalance);
                             //                        return $dataForUpdateUser;
                             $updated = $objModelUsermeta->updateUsermetaWhere($dataForUpdateUser, $whereForUpdateUser);
                         } else {
                             $accountBal = 0;
                             $totalBalance = $accountBal + $amount;
                             $addData = array('user_id' => $userId, 'account_bal' => $totalBalance);
                             $addUsermeta = $objModelUsermeta->addUsermeta($addData);
                         }
                         // code for generating NOTIFICATION
                         $objModelNotification = Notification::getInstance();
                         $input = array('notification_id' => '', 'user_id' => $userId, 'notifications_txt' => '$ ' . $amount . ' is successfully credited to your account through 2CO credit card payment');
                         $addNotification = $objModelNotification->addNewNotification($input);
                         $response->code = 200;
                         $response->message = "Payment Approved";
                         $response->data = $totalBalance;
                         echo json_encode($response, true);
                     }
                 } catch (\Twocheckout_Error $e) {
                     echo json_encode($e->getMessage(), true);
                     //                        print_r($e->getMessage());
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function initialize($paymentAction, $stateObject)
 {
     $payment = $this->getInfoInstance();
     $order = $payment->getOrder();
     $billing = $order->getBillingAddress();
     $shipping = $order->getShippingAddress();
     $amount = round($order->getGrandTotal(), 2);
     try {
         $params = array("sellerId" => $this->getSid(), "merchantOrderId" => $order->getIncrementId(), "token" => Mage::app()->getRequest()->getParam('token'), "currency" => $order->getOrderCurrencyCode(), "total" => $amount, "billingAddr" => array("name" => $billing->getName(), "addrLine1" => $billing->getStreet(1), "addrLine2" => $billing->getStreet(2), "city" => $billing->getCity(), "state" => $billing->getRegion(), "zipCode" => $billing->getPostcode(), "country" => $billing->getCountry(), "email" => $order->getCustomerEmail(), "phoneNumber" => $billing->getTelephone()));
         if ($shipping) {
             $shippingAddr = array("name" => $shipping->getName(), "addrLine1" => $shipping->getStreet(1), "addrLine2" => $shipping->getStreet(2), "city" => $shipping->getCity(), "state" => $shipping->getRegion(), "zipCode" => $shipping->getPostcode(), "country" => $shipping->getCountry(), "email" => $order->getCustomerEmail(), "phoneNumber" => $billing->getTelephone());
             array_merge($shippingAddr, $params);
         }
         $charge = Twocheckout_Charge::auth($params);
     } catch (Twocheckout_Error $e) {
         Mage::throwException(Mage::helper('paygate')->__('Authorization Failed'));
     }
     if ($charge['response']['responseCode'] == 'APPROVED') {
         $payment->setTransactionId($charge['response']['transactionId'])->setIsTransactionClosed(false);
         $order->setData('ext_order_id', $charge['response']['transactionId'])->save();
     } else {
         Mage::throwException(Mage::helper('paygate')->__('Payment capturing error: %s', "Could not Authorize Transaction"));
     }
     return $this;
 }
 public function send()
 {
     $this->load->model('checkout/order');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $params = array("sellerId" => $this->config->get('twocheckout_account'), "merchantOrderId" => $this->session->data['order_id'], "token" => $this->request->get['token'], "currency" => $order_info['currency_code'], "total" => $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false), "billingAddr" => array("name" => $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'], "addrLine1" => $order_info['payment_address_1'], "addrLine2" => $order_info['payment_address_2'], "city" => $order_info['payment_city'], "state" => $order_info['payment_iso_code_2'] == 'US' || $order_info['payment_iso_code_2'] == 'CA' ? $order_info['payment_zone'] : 'XX', "zipCode" => $order_info['payment_postcode'], "country" => $order_info['payment_country'], "email" => $order_info['email'], "phoneNumber" => $order_info['telephone']));
     if ($this->cart->hasShipping()) {
         $shipping = array("shippingAddr" => array("name" => $order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname'], "addrLine1" => $order_info['shipping_address_1'], "addrLine2" => $order_info['shipping_address_2'], "city" => $order_info['shipping_city'], "state" => $order_info['shipping_zone'], "zipCode" => $order_info['shipping_postcode'], "country" => $order_info['shipping_country'], "email" => $order_info['email'], "phoneNumber" => $order_info['telephone']));
         $params = array_merge($params, $shipping);
     }
     try {
         if ($this->config->get('twocheckout_test')) {
             TwocheckoutApi::setCredentials($this->config->get('twocheckout_account'), $this->config->get('twocheckout_private_key'), 'sandbox');
         } else {
             TwocheckoutApi::setCredentials($this->config->get('twocheckout_account'), $this->config->get('twocheckout_private_key'));
         }
         $charge = Twocheckout_Charge::auth($params);
         $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));
         $message = '2Checkout Order: ' . $charge['response']['orderNumber'];
         $this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('twocheckout_order_status_id'), $message, false);
         $charge['oc_redirect'] = $this->url->link('checkout/success', '', 'SSL');
         $this->response->setOutput(json_encode($charge));
     } catch (Twocheckout_Error $e) {
         $error = array("error" => $e->getMessage());
         $this->response->setOutput(json_encode($error));
     }
 }
Esempio n. 4
0
 public static function testChargeAuth()
 {
     Twocheckout::privateKey('BE632CB0-BB29-11E3-AFB6-D99C28100996');
     Twocheckout::sellerId('901248204');
     Twocheckout::sandbox(true);
     try {
         $charge = Twocheckout_Charge::auth(array("sellerId" => "901248204", "merchantOrderId" => "123", "token" => 'MjFiYzIzYjAtYjE4YS00ZmI0LTg4YzYtNDIzMTBlMjc0MDlk', "currency" => 'USD', "total" => '10.00', "billingAddr" => array("name" => 'Testing Tester', "addrLine1" => '123 Test St', "city" => 'Columbus', "state" => 'OH', "zipCode" => '43123', "country" => 'USA', "email" => '*****@*****.**', "phoneNumber" => '555-555-5555'), "shippingAddr" => array("name" => 'Testing Tester', "addrLine1" => '123 Test St', "city" => 'Columbus', "state" => 'OH', "zipCode" => '43123', "country" => 'USA', "email" => '*****@*****.**', "phoneNumber" => '555-555-5555')));
         $this->assertEquals('APPROVED', $charge['response']['responseCode']);
     } catch (Twocheckout_Error $e) {
         $this->assertEquals('Bad request - parameter error', $e->getMessage());
     }
 }
 /**
  * Process registration
  *
  * @since 2.3
  */
 public function process_signup()
 {
     Twocheckout::privateKey($this->secret_key);
     Twocheckout::sellerId($this->seller_id);
     Twocheckout::sandbox($this->test_mode);
     $member = new RCP_Member($this->user_id);
     if (empty($_POST['twoCheckoutToken'])) {
         rcp_errors()->add('missing_card_token', __('Missing 2Checkout token, please try again or contact support if the issue persists.', 'rcp'), 'register');
         return;
     }
     $paid = false;
     if ($this->auto_renew) {
         $payment_type = 'Credit Card';
         $line_items = array(array("recurrence" => $this->length . ' ' . ucfirst($this->length_unit), "type" => 'product', "price" => $this->amount, "productId" => $this->subscription_id, "name" => $this->subscription_name, "quantity" => '1', "tangible" => 'N', "startupFee" => $this->signup_fee));
     } else {
         $payment_type = 'Credit Card One Time';
         $line_items = array(array("recurrence" => 0, "type" => 'product', "price" => $this->amount, "productId" => $this->subscription_id, "name" => $this->subscription_name, "quantity" => '1', "tangible" => 'N', "startupFee" => $this->signup_fee));
     }
     try {
         $charge = Twocheckout_Charge::auth(array('merchantOrderId' => $this->subscription_key, 'token' => $_POST['twoCheckoutToken'], 'currency' => strtolower($this->currency), 'billingAddr' => array('name' => sanitize_text_field($_POST['rcp_card_name']), 'addrLine1' => sanitize_text_field($_POST['rcp_card_address']), 'city' => sanitize_text_field($_POST['rcp_card_city']), 'state' => sanitize_text_field($_POST['rcp_card_state']), 'zipCode' => sanitize_text_field($_POST['rcp_card_zip']), 'country' => sanitize_text_field($_POST['rcp_card_country']), 'email' => $this->email), "lineItems" => $line_items));
         if ($charge['response']['responseCode'] == 'APPROVED') {
             // Look to see if we have an existing subscription to cancel
             if ($member->just_upgraded() && rcp_can_member_cancel($member->ID)) {
                 $cancelled = rcp_cancel_member_payment_profile($member->ID, false);
             }
             $payment_data = array('date' => date('Y-m-d H:i:s', current_time('timestamp')), 'subscription' => $this->subscription_name, 'payment_type' => $payment_type, 'subscription_key' => $this->subscription_key, 'amount' => $this->amount + $this->signup_fee, 'user_id' => $this->user_id, 'transaction_id' => $charge['response']['transactionId']);
             $rcp_payments = new RCP_Payments();
             $rcp_payments->insert($payment_data);
             $paid = true;
         }
     } catch (Twocheckout_Error $e) {
         wp_die($e->getMessage(), __('Error', 'rcp'), array('response' => '401'));
     }
     if ($paid) {
         // set this user to active
         $member->renew($this->auto_renew);
         $member->add_note(__('Subscription started in 2Checkout', 'rcp'));
         $member->set_payment_profile_id('2co_' . $charge['response']['orderNumber']);
         if (!is_user_logged_in()) {
             // log the new user in
             rcp_login_user_in($this->user_id, $this->user_name, $_POST['rcp_user_pass']);
         }
         do_action('rcp_2co_signup', $this->user_id, $this);
     }
     // redirect to the success page, or error page if something went wrong
     wp_redirect($this->return_url);
     exit;
 }
 public function payment($id = null, $contract_id = null)
 {
     Twocheckout::privateKey('5DAC98FE-EF3E-4A2D-B42E-36DE611EE4B7');
     Twocheckout::sellerId('901255149');
     Twocheckout::sandbox(true);
     #Uncomment to use Sandbox
     var_dump($contract_id);
     $contract = $this->Session->read('contract_' . $contract_id);
     if ($contract) {
         $this->loadModel('Order');
         $order = $this->Order->find('first', array('conditions' => array('Order.id=' . $id), 'fields' => array('Order.*', 'Membership.*'), 'joins' => array(array('alias' => 'Membership', 'table' => 'memberships', 'type' => 'LEFT', 'conditions' => array('Membership.id = Order.membership_id')))));
         if ($order['Order']["paid"] == TRUE) {
             $this->redirect('/contracts/review_finalize/' . $id);
         }
         try {
             $charge = Twocheckout_Charge::auth(array("merchantOrderId" => $this->userDb["User"]["id"], "token" => $_POST['token'], "currency" => 'USD', "total" => $order['Membership']['month_price'], "billingAddr" => array("name" => 'Testing Tester', "addrLine1" => '123 Test St', "city" => 'Columbus', "state" => 'OH', "zipCode" => '43123', "country" => 'USA', "email" => $this->userDb["User"]["email"], "phoneNumber" => '555-555-5555')));
             if ($charge['response']['responseCode'] == 'APPROVED') {
                 $this->loadModel('Transaction');
                 $transaction = array('user_id' => $this->u_id, 'paymentstatus' => 'paid', 'type' => '2checkout', 'transactionId' => $charge['response']['transactionId'], 'transactionData' => json_encode($charge));
                 $this->Transaction->save($transaction);
                 $order = array('id' => $id, 'paid' => 1);
                 $save = $this->Order->save($order);
                 if ($save) {
                     if ($contract['Order']['id'] == $save['Order']['id']) {
                         $contract['Order'] = $save['Order'];
                         $this->Session->write('contract_' . $id, $contract);
                     }
                     $this->redirect('/contracts/review_finalize/' . $id);
                 } else {
                     $this->Session->setFlash(__('error'), 'flash', array('class' => 'danger', 'noteType' => 'bootstrap'));
                     $this->redirect('/');
                 }
             } else {
                 $this->Session->setFlash(__('Transaction error!'), 'flash', array('class' => 'danger', 'noteType' => 'bootstrap'));
                 $this->redirect('/');
             }
         } catch (Twocheckout_Error $e) {
             $this->Session->setFlash(__($e->getMessage()), 'flash', array('class' => 'danger', 'noteType' => 'bootstrap'));
         }
         //$this->Session->setFlash(__( 'Error. No order Id!'), 'flash', array('class' => 'danger', 'noteType' => 'bootstrap'));
     } else {
         $this->Session->setFlash(__('Cant find contract session!'), 'flash', array('class' => 'danger', 'noteType' => 'bootstrap'));
     }
     $this->redirect('/');
 }
Esempio n. 7
0
 public function register()
 {
     //validate form input
     $this->form_validation->set_rules('first_name', 'First Name', 'required|xss_clean');
     $this->form_validation->set_rules('last_name', 'Last Name', 'required|xss_clean');
     $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
     $this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
     $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');
     if ($this->form_validation->run() == true) {
         $username = strtolower($this->input->post('first_name')) . ' ' . strtolower($this->input->post('last_name'));
         $email = $this->input->post('email');
         $password = $this->input->post('password');
         $additional_data = array('first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), 'last_billed' => time());
     }
     if ($this->form_validation->run() == true && $this->ion_auth->register($username, $password, $email, $additional_data)) {
         //check to see if we are creating the user
         $this->session->set_flashdata('message', $this->ion_auth->messages());
         //get user id
         $query = $this->db->query("SELECT * FROM users WHERE email = '{$email}'");
         $row = $query->row();
         $id = $row->id;
         $args = array('sid' => 1817037, 'mode' => "2CO", 'li_0_name' => "Monthly Subscription", 'li_0_price' => "1.00", 'li_0_recurrence' => "1 Month", 'merchant_order_id' => $id);
         Twocheckout_Charge::redirect($args);
     } else {
         //display the create user form
         //set the flash data error message if there is one
         $this->data['message'] = validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message'));
         $this->data['first_name'] = array('name' => 'first_name', 'id' => 'first_name', 'type' => 'text', 'value' => $this->form_validation->set_value('first_name'));
         $this->data['last_name'] = array('name' => 'last_name', 'id' => 'last_name', 'type' => 'text', 'value' => $this->form_validation->set_value('last_name'));
         $this->data['email'] = array('name' => 'email', 'id' => 'email', 'type' => 'text', 'value' => $this->form_validation->set_value('email'));
         $this->data['password'] = array('name' => 'password', 'id' => 'password', 'type' => 'password', 'value' => $this->form_validation->set_value('password'));
         $this->data['password_confirm'] = array('name' => 'password_confirm', 'id' => 'password_confirm', 'type' => 'password', 'value' => $this->form_validation->set_value('password_confirm'));
     }
     $this->load->view('/include/header');
     $this->load->view('/include/navblank');
     $this->load->view('/order/register', $this->data);
     $this->load->view('/include/footer');
 }
Esempio n. 8
0
 /**
  * @param $blog_id
  *   This function will handler
  *   Checkout process
  *   -With Coupon
  *   -Without Coupon
  *   -Recurring
  *   -One time
  *   -DownGrade level
  *   -UpGrade level
  *   -Manual extends subscription time
  */
 public function process_checkout($blog_id, $domain = false)
 {
     global $current_site, $current_user, $psts, $wpdb;
     $site_name = $current_site->site_name;
     if (!empty($domain)) {
         //Get blog name from signup as per WP Signup or BP Signup
         $site_name = $domain;
     }
     //Processing User submitted form
     if (isset($_POST['2co_checkout_button'])) {
         //validate
         if (!$this->check_nonce()) {
             $psts->errors->add('general', __('Whoops, looks like you may have tried to submit your payment twice so we prevented it. Check your subscription info below to see if it was created. If not, please try again.', 'psts'));
         }
         if (!isset($_POST['period']) || !isset($_POST['level'])) {
             $psts->errors->add('general', __('Please choose your desired level and payment plan.', 'psts'));
             return;
         }
         //If free level is selected, activate a trial
         if (!empty($domain) && !$psts->prevent_dismiss() && '0' === $_POST['level'] && '0' === $_POST['period']) {
             $psts->activate_user_blog($domain, true, $_POST['level'], $_POST['period']);
             $esc_domain = esc_url($domain);
             //Set complete message
             $this->complete_message = __('Your trial blog has been setup at <a href="' . $esc_domain . '">' . $esc_domain . '</a>', 'psts');
             return;
         }
         add_action('wp_head', array(&$this, 'checkout_js'));
         wp_enqueue_script(array('jquery'));
         //prepare vars
         $amount_off = false;
         $payment_amount = $init_amount = $psts->get_level_setting($_POST['level'], 'price_' . $_POST['period']);
         $trial_days = $psts->get_setting('trial_days', 0);
         $cp_code = false;
         $is_trial = $psts->is_trial_allowed($blog_id);
         $setup_fee = (double) $psts->get_setting('setup_fee', 0);
         $has_coupon = isset($_SESSION['COUPON_CODE']) && $psts->check_coupon($_SESSION['COUPON_CODE'], $blog_id, $_POST['level']) ? true : false;
         $has_setup_fee = $psts->has_setup_fee($blog_id, $_POST['level']);
         $recurring = $psts->get_setting('recurring_subscriptions', 1);
         $params = array('sid' => $psts->get_setting('2co_acc_number'), 'currency' => $psts->get_setting('2co_currency', 'USD'), 'x_receipt_link_url' => $psts->checkout_url($blog_id, $domain), 'mode' => '2CO', 'merchant_order_id' => $blog_id, 'period' => esc_attr($_POST['period']), 'level' => esc_attr($_POST['level']), '2co_cart_type' => 'ProSites', 'demo' => $psts->get_setting('2co_checkout_mode'));
         //build products params
         $addition_params = array('li_0_type' => 'product', 'li_0_name' => $site_name . ' ' . $psts->get_level_setting($_POST['level'], 'name'), 'li_0_price' => $init_amount);
         //if have setup fee
         if ($has_setup_fee) {
             $addition_params['li_0_startup_fee'] = $setup_fee;
         }
         //if have trial time
         if ($is_trial) {
             $init_amount = $init_amount - $payment_amount;
         }
         //case have coupon
         if ($has_coupon) {
             $coupon_value = $psts->coupon_value($_SESSION['COUPON_CODE'], $payment_amount);
             $amount_off = $payment_amount - $coupon_value['new_total'];
             $init_amount -= $amount_off;
             $addition_params = array_merge($addition_params, array('li_1_type' => 'coupon', 'li_1_name' => $_SESSION['COUPON_CODE'], 'li_1_price' => $amount_off));
         }
         if ($recurring) {
             $addition_params = array_merge($addition_params, array('li_0_recurrence' => esc_attr($_POST['period']) . ' Month', 'li_0_duration' => 'Forever'));
         }
         //check if this is downgrade,require no money
         if (!empty($blog_id)) {
             $cur_level = $psts->get_level($blog_id);
             //To Do: Update downgrade logic, to avoid free subscription for next period if downgraded at the end of subscription
             if ($cur_level > 0) {
                 if ($cur_level > $_POST['level']) {
                     /**
                      * Case downgrade
                      * If period is same,so it is simple.When the current level expire,we will downgrade the leve.
                      * For cost for first period of new level will be nearly free.
                      */
                     $old = $wpdb->get_row($wpdb->prepare("SELECT expire, level, term, amount FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = %d", $blog_id));
                     if ($old->term == $_POST['period']) {
                         $addition_params = array_merge($addition_params, array_merge(array('li_2_type' => 'coupon', 'li_2_name' => __('First month is free due to new level apply to next month', 'ptst'), 'li_2_price' => $init_amount - 0.01)));
                     } elseif ($old->term < $_POST['period'] || $old->term > $_POST['period']) {
                         /**
                          * This case is when the new period smaller than current or larger
                          * 2checkout not support for update customer infomation,
                          * and the only way is using the checkout.Some issue will happend
                          * Example current is 3 months,but user want to downgrade to 1 month.The point is if we subscription for client now,it will
                          * make client need to pay for 3 months before the old expire end. So for this case,we only cancel the subscription,
                          * and send the checkout url when this subscrition expire via email.
                          */
                         update_option('psts_2co_recuring_next_plan', array('action' => 'downgrade', 'level' => $_POST['level'], 'type' => 'email'));
                         $this->complete_message = __('Your 2Checkout subscription modification was not done automate! You will recive an email about the new upgrade when current subsciprion expire.', 'psts');
                     }
                 } elseif ($cur_level < $_POST['level']) {
                     /**
                      * Case upgrade
                      */
                     //get the unuse balance
                     $balance_left = $this->cal_unused_balance($blog_id);
                     $addition_params = array_merge($addition_params, array_merge(array('li_2_type' => 'coupon', 'li_2_name' => __('Balance left of last subscription', 'ptst'), 'li_2_price' => $balance_left)));
                 }
             }
         }
         //create form
         $params = array_merge($params, $addition_params);
         $this->set_gateway_param();
         //all set,now generate the form and submit
         Twocheckout_Charge::redirect($params, 'checkout');
         exit;
     } elseif (isset($_REQUEST['credit_card_processed']) && strtolower($_REQUEST['credit_card_processed']) == 'y') {
         //Processing 2checkout response after user returns from 2checkout site
         $check = Twocheckout_Return::check($_REQUEST, $psts->get_setting('2co_secret_word'), 'array');
         if ($check['response_code'] == 'Success') {
             //Activate the blog
             $blog_id = $psts->activate_user_blog($domain);
             if (!$this->check_profile_id_exist($blog_id, $_REQUEST['order_number'])) {
                 //profile not exist
                 //do the check
                 //get current level
                 $cur_level = $psts->get_level($blog_id);
                 $modify = false;
                 if (is_pro_site($blog_id) && !is_pro_trial($blog_id)) {
                     $modify = true;
                     if ($cur_level != 0 && $cur_level == $_REQUEST['level']) {
                         $modify = false;
                     }
                 }
                 //now go
                 if ($modify) {
                     //this case user is modify the subscription,we will need to check upgrade or downgrade,and refund the diff
                     $scenario = '';
                     if ($cur_level < $_REQUEST['level']) {
                         $scenario = 'upgrade';
                     } elseif ($cur_level > $_REQUEST['level']) {
                         $scenario = 'downgrade';
                     }
                     $this->tcheckout_modify_subscription($blog_id, $scenario);
                 } elseif ($modify == false && (is_pro_site($blog_id) && !is_pro_trial($blog_id))) {
                     //site is in subscription,but user extend to longer
                     //$this->tcheckout_modify_subscription( $blog_id, 'extend' );
                 } else {
                     $this->tcheckout_hander_new_subscription($blog_id);
                 }
             } else {
                 $psts->errors->add('general', __('Your transaction has already settled!', 'psts'));
             }
         } else {
             $psts->errors->add('general', __('There was a problem validating the 2Checkout payment:<br /><strong>MD5 Hash did not match!</strong><br />Please contact the seller directly for assistance.', 'psts'));
         }
     }
 }
 /**
  * Process the payment and return the result
  *
  * @access public
  * @param int $order_id
  * @return array
  */
 function process_payment($order_id)
 {
     global $woocommerce;
     $order = new WC_Order($order_id);
     if ('yes' == $this->debug) {
         $this->log('Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url);
     }
     // 2Checkout Args
     $twocheckout_args = array('token' => $_POST['token'], 'sellerId' => $this->seller_id, 'currency' => get_woocommerce_currency(), 'total' => $order->get_total(), 'merchantOrderId' => $order->get_order_number(), "billingAddr" => array('name' => $order->billing_first_name . ' ' . $order->billing_last_name, 'addrLine1' => $order->billing_address_1, 'addrLine2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zipCode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phoneNumber' => $order->billing_phone));
     try {
         if ($this->sandbox == 'yes') {
             TwocheckoutApi::setCredentials($this->seller_id, $this->private_key, 'sandbox');
         } else {
             TwocheckoutApi::setCredentials($this->seller_id, $this->private_key);
         }
         $charge = Twocheckout_Charge::auth($twocheckout_args);
         if ($charge['response']['responseCode'] == 'APPROVED') {
             $order->payment_complete();
             return array('result' => 'success', 'redirect' => $this->get_return_url($order));
         }
     } catch (Twocheckout_Error $e) {
         wc_add_notice($e->getMessage(), $notice_type = 'error');
         return;
     }
 }
 function processPayment($token)
 {
     include dirname(__FILE__) . '/lib/Twocheckout/TwocheckoutApi.php';
     $cart = $this->context->cart;
     $user = $this->context->customer;
     $delivery = new Address(intval($cart->id_address_delivery));
     $invoice = new Address(intval($cart->id_address_invoice));
     $customer = new Customer(intval($cart->id_customer));
     $currencies = Currency::getCurrencies();
     $authorized_currencies = array_flip(explode(',', $this->currencies));
     $currencies_used = array();
     foreach ($currencies as $key => $currency) {
         if (isset($authorized_currencies[$currency['id_currency']])) {
             $currencies_used[] = $currencies[$key];
         }
     }
     foreach ($currencies_used as $currency) {
         if ($currency['id_currency'] == $cart->id_currency) {
             $order_currency = $currency['iso_code'];
         }
     }
     try {
         $params = array("sellerId" => Configuration::get('TWOCHECKOUT_SID'), "merchantOrderId" => $cart->id, "token" => $token, "currency" => $order_currency, "total" => number_format($cart->getOrderTotal(true, 3), 2, '.', ''), "billingAddr" => array("name" => $invoice->firstname . ' ' . $invoice->lastname, "addrLine1" => $invoice->address1, "addrLine2" => $invoice->address2, "city" => $invoice->city, "state" => $invoice->country == "United States" || $invoice->country == "Canada" ? State::getNameById($invoice->id_state) : 'XX', "zipCode" => $invoice->postcode, "country" => $invoice->country, "email" => $customer->email, "phoneNumber" => $invoice->phone));
         if ($delivery) {
             $shippingAddr = array("name" => $delivery->firstname . ' ' . $delivery->lastname, "addrLine1" => $delivery->address1, "addrLine2" => $delivery->address2, "city" => $delivery->city, "state" => (Validate::isLoadedObject($delivery) and $delivery->id_state) ? new State(intval($delivery->id_state)) : 'XX', "zipCode" => $delivery->postcode, "country" => $delivery->country);
             array_merge($shippingAddr, $params);
         }
         if (Configuration::get('TWOCHECKOUT_SANDBOX')) {
             TwocheckoutApi::setCredentials(Configuration::get('TWOCHECKOUT_SID'), Configuration::get('TWOCHECKOUT_PRIVATE'), 'sandbox');
         } else {
             TwocheckoutApi::setCredentials(Configuration::get('TWOCHECKOUT_SID'), Configuration::get('TWOCHECKOUT_PRIVATE'));
         }
         $charge = Twocheckout_Charge::auth($params);
     } catch (Twocheckout_Error $e) {
         $message = 'Payment Authorization Failed';
         Tools::redirect('index.php?controller=order&step=3&twocheckouterror=' . $message);
     }
     if (isset($charge['response']['responseCode'])) {
         $order_status = (int) Configuration::get('TWOCHECKOUT_ORDER_STATUS');
         $message = $charge['response']['responseMsg'];
         $this->validateOrder((int) $this->context->cart->id, _PS_OS_PAYMENT_, $charge['response']['total'], $this->displayName, $message, array(), null, false, $this->context->customer->secure_key);
         Tools::redirect('index.php?controller=order-confirmation?key=' . $user->secure_key . '&id_cart=' . (int) $cart->id . '&id_module=' . (int) $this->module->id . '&id_order=' . (int) $this->module->currentOrder);
     } else {
         $message = 'Payment Authorization Failed';
         Tools::redirect('index.php?controller=order&step=3&twocheckouterror=' . $message);
     }
 }
Esempio n. 11
0
<?php

require_once "lib/Twocheckout.php";
Twocheckout::privateKey('sandbox-private-key');
//Private Key
Twocheckout::sellerId('sandbox-seller-id');
// 2Checkout Account Number
Twocheckout::sandbox(true);
// Set to false for production accounts.
try {
    $charge = Twocheckout_Charge::auth(array("merchantOrderId" => "123", "token" => $_POST['token'], "currency" => 'USD', "total" => '10.00', "billingAddr" => array("name" => 'Testing Tester', "addrLine1" => '123 Test St', "city" => 'Columbus', "state" => 'OH', "zipCode" => '43123', "country" => 'USA', "email" => '*****@*****.**', "phoneNumber" => '555-555-5555')));
    if ($charge['response']['responseCode'] == 'APPROVED') {
        echo "Thanks for your Order!";
        echo "<h3>Return Parameters:</h3>";
        echo "<pre>";
        print_r($charge);
        echo "</pre>";
    }
} catch (Twocheckout_Error $e) {
    print_r($e->getMessage());
}
Esempio n. 12
-1
function callGateway($orderId, $package, $user, $post)
{
    $twoCheckout = new Twocheckout();
    $twoCheckout->privateKey('E5FC384C-50A5-443B-B51E-4077F76927AC');
    $twoCheckout->sellerId('901271052');
    $twoCheckout->verifySSL(false);
    $twoCheckout->sandbox(true);
    try {
        $params = array("merchantOrderId" => $orderId, "token" => $post['token'], "currency" => 'USD', "total" => $package->amount, "billingAddr" => array("name" => $post['ccFname'] . ' ' . $post['ccLname'], "email" => $user->email, "addrLine1" => $post['addressLine1'], "city" => $post['city'], "state" => $post['state'], "zipCode" => $post['zip'], "country" => $post['country'], "phoneNumber" => $user->phone));
        $charge = Twocheckout_Charge::auth($params);
        if ($charge['response']['responseCode'] == 'APPROVED') {
            return $charge;
        }
    } catch (Twocheckout_Error $e) {
        return $e->getMessage();
    }
}