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()); } } } } }
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)); } }
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('/'); }
/** * 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); } }
<?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 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(); } }