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());
                 }
             }
         }
     }
 }
 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;
 }
Пример #3
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');
     }
 }
Пример #4
1
 function set_gateway_param()
 {
     global $psts;
     Twocheckout::$sid = $psts->get_setting('2co_acc_number');
     Twocheckout::username($psts->get_setting('2co_api_username'));
     Twocheckout::password($psts->get_setting('2co_api_password'));
     if ($psts->get_setting('2co_checkout_mode') == 'Y') {
         Twocheckout::sandbox(true);
     }
 }
Пример #5
0
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_pay()
 {
     $this->auto_render = FALSE;
     //sandobx doesnt do the x_receipt_link_url redirect so in sanbbox instead we put the order id
     $id_order = Core::config('payment.twocheckout_sandbox') == 1 ? Core::request('x_receipt_link_url') : $this->request->param('id');
     //retrieve info for the item in DB
     $order = new Model_Order();
     $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         //its a fraud...lets let him know
         if ($order->is_fraud() === TRUE) {
             Alert::set(Alert::ERROR, __('We had, issues with your transaction. Please try paying with another paymethod.'));
             $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order)));
         }
         if (($order_id = twocheckout::validate_passback($order)) !== FALSE) {
             //mark as paid
             $order->confirm_payment('2checkout', $order_id, NULL, NULL, NULL, Twocheckout::calculate_fee($order->amount));
             //redirect him to his ads
             Alert::set(Alert::SUCCESS, __('Thanks for your payment!'));
             $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'goal', 'id' => $order->id_order)));
         } else {
             Alert::set(Alert::INFO, __('Please fill your card details.'));
             $this->redirect(Route::url('default', array('controller' => 'product', 'action' => 'checkout', 'id' => $order->id_order)));
         }
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default'));
     }
 }
Пример #6
0
 public function action_210()
 {
     //add new order fields
     try {
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders` ADD `amount_net`  DECIMAL(14,3) NOT NULL DEFAULT '0' AFTER `amount`;")->execute();
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders` ADD `gateway_fee` DECIMAL(14,3) NOT NULL DEFAULT '0' AFTER `amount_net`;")->execute();
         DB::query(Database::UPDATE, "ALTER TABLE  `" . self::$db_prefix . "orders` ADD `VAT_amount`  DECIMAL(14,3) NOT NULL DEFAULT '0' AFTER `VAT`;")->execute();
     } catch (exception $e) {
     }
     //make posts bigger description
     try {
         DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "posts` CHANGE `description` `description` LONGTEXT;")->execute();
     } catch (exception $e) {
     }
     try {
         DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "content` CHANGE `description` `description` LONGTEXT;")->execute();
     } catch (exception $e) {
     }
     //bigger configs
     try {
         DB::query(Database::UPDATE, "ALTER TABLE `" . self::$db_prefix . "config` CHANGE `config_value` `config_value` LONGTEXT;")->execute();
     } catch (exception $e) {
     }
     //recalculate all the orders
     $orders = new Model_Order();
     $orders = $orders->where('status', '=', Model_Order::STATUS_PAID)->where('amount_net', '=', 0)->find_all();
     foreach ($orders as $order) {
         if ($order->paymethod == 'stripe') {
             $order->gateway_fee = StripeKO::calculate_fee($order->amount);
         } elseif ($order->paymethod == '2checkout') {
             $order->gateway_fee = Twocheckout::calculate_fee($order->amount);
         } elseif ($order->paymethod == 'paymill') {
             $order->gateway_fee = Paymill::calculate_fee($order->amount);
         } elseif ($order->paymethod == 'authorize') {
             $order->gateway_fee = Controller_Authorize::calculate_fee($order->amount);
         } elseif ($order->paymethod == 'paypal') {
             //we dont have the history of the transactions so we clculate an aproximation using 4%
             $order->gateway_fee = 4 * $order->amount / 100;
         } else {
             $order->gateway_fee = 0;
         }
         //get VAT paid
         if ($order->VAT > 0) {
             $order->VAT_amount = $order->amount - 100 * $order->amount / (100 + $order->VAT);
         } else {
             $order->VAT_amount = 0;
         }
         //calculate net amount
         $order->amount_net = $order->amount - $order->gateway_fee - $order->VAT_amount;
         try {
             $order->save();
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
     }
     //new configs
     $configs = array(array('config_key' => 'stripe_alipay', 'group_name' => 'payment', 'config_value' => '0'), array('config_key' => 'captcha', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_active', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_secretkey', 'group_name' => 'general', 'config_value' => ''), array('config_key' => 'recaptcha_sitekey', 'group_name' => 'general', 'config_value' => ''));
     Model_Config::config_array($configs);
 }
Пример #7
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $this->locator = new ServiceLocator();
     \Twocheckout::sellerId($this->sellerId);
     if (!$this->secretWord) {
         throw new InvalidConfigException('Invalid secret word was specified');
     }
 }
Пример #8
0
 public function __construct()
 {
     if ($this->getDemo()) {
         Twocheckout::privateKey($this->getPrivateKey());
         Twocheckout::sellerId($this->getSid());
         Twocheckout::sandbox(true);
     } else {
         Twocheckout::privateKey($this->getPrivateKey());
         Twocheckout::sellerId($this->getSid());
         Twocheckout::sandbox(false);
     }
 }
Пример #9
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('/');
 }
Пример #12
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());
    }
}
Пример #13
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()));
         }
     }
 }
Пример #14
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $this->locator = new ServiceLocator();
     if ($this->username && $this->password) {
         \Twocheckout::username($this->username);
         \Twocheckout::password($this->password);
     }
     if (!$this->privateKey) {
         throw new InvalidConfigException('Invalid private key was specified');
     }
     \Twocheckout::privateKey($this->privateKey);
     if (!$this->sellerId) {
         throw new InvalidConfigException('Invalid seller id was specified');
     }
     \Twocheckout::sellerId($this->sellerId);
     if (!$this->secretWord) {
         throw new InvalidConfigException('Invalid secret word was specified');
     }
     \TwoCheckout::verifySSL($this->verifySSL);
     \Twocheckout::sandbox($this->sandbox);
     \Twocheckout::format($this->format);
 }
Пример #15
0
 public function setUp()
 {
     Twocheckout::username('testlibraryapi901248204');
     Twocheckout::password('testlibraryapi901248204PASS');
     Twocheckout::sandbox(true);
 }
Пример #16
0
<?php

$idp = $_POST["idp"];
// echo $IDPEDIDO;
require_once "2checkout-php-master/lib/Twocheckout.php";
Twocheckout::privateKey('422AEC8E-9A5E-4963-AE4C-52C3BEE3FBFF');
Twocheckout::sellerId('901308282');
Twocheckout::sandbox(true);
Twocheckout::verifySSL(false);
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') {
        header('Location:tarjeta.php?idp=' . $idp);
    }
} catch (Twocheckout_Error $e) {
    print_r($e->getMessage());
}
Пример #17
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;
 }
Пример #18
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());
}
 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;
 }
Пример #20
0
 static function setCredentials($user, $pass, $environment = "production")
 {
     self::$user = $user;
     self::$pass = $pass;
     self::$environment = $environment;
 }
Пример #21
0
 public static function format($value = null)
 {
     self::$format = $value;
 }
Пример #22
0
 static function setCredentials($user, $pass)
 {
     self::$user = $user;
     self::$pass = $pass;
 }
<?php

include dirname(__FILE__) . '/../../config/config.inc.php';
include dirname(__FILE__) . '/../../init.php';
include dirname(__FILE__) . '/twocheckout.php';
if (!defined('_PS_VERSION_')) {
    exit;
}
$twocheckout = new Twocheckout();
if ($twocheckout->active && isset($_POST['token'])) {
    $twocheckout->processPayment($_POST['token']);
} else {
    die('You must submit a valid token to use the 2Checkout Payment API.');
}
Пример #24
-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();
    }
}