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());
                 }
             }
         }
     }
 }
Пример #2
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());
     }
 }
Пример #3
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);
     }
 }
 function PMProGateway_Twocheckout($gateway = NULL)
 {
     if (!class_exists("Twocheckout")) {
         require_once dirname(__FILE__) . "/../../includes/lib/Twocheckout/Twocheckout.php";
     }
     //set API connection vars
     Twocheckout::sellerId(pmpro_getOption('twocheckout_accountnumber'));
     Twocheckout::privateKey(pmpro_getOption('twocheckout_privatekey'));
     Twocheckout::username(pmpro_getOption('twocheckout_apiusername'));
     Twocheckout::password(pmpro_getOption('twocheckout_apipassword'));
     Twocheckout::$verifySSL = false;
     $this->gateway = $gateway;
     return $this->gateway;
 }
 /**
  * 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('/');
 }
Пример #7
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());
    }
}
Пример #8
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);
 }
 public static function privateKey($value = null)
 {
     self::$privateKey = $value;
 }
Пример #10
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());
}
Пример #11
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());
}
Пример #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();
    }
}