Esempio n. 1
0
 public function pay($method)
 {
     $payment = new Payment($method);
     if ($method == 'Paypal') {
         Session::instance()->delete('paypal_token');
         $order = new Order_Model($this->order->id);
         //$inv = uniqid('payPal_');
         $inv = $this->getTransID();
         $order->trans_id = $inv;
         $order->save();
         $attributes = array('AMT' => $this->total(), 'INVNUM' => $inv, 'SHIPTONAME' => $this->order->shipping->first_name . ' ' . $this->order->shipping->last_name, 'SHIPTOSTREET' => $this->order->shipping->address1, 'SHIPTOCITY' => $this->order->shipping->city, 'SHIPTOCOUNTRYCODE' => $this->order->shipping->country, 'SHIPTOSTATE' => $this->order->shipping->state, 'SHIPTOZIP' => $this->order->shipping->zip);
         //$this->payment->GETDETAILS = FALSE;
     } else {
         if (!valid::credit_card($this->order->payment->card->card_num)) {
             throw new Exception('Invalid credit card data');
         }
         $attributes = array('card_num' => $this->order->payment->card->card_num, 'exp_date' => $this->order->payment->card->exp_date, 'amount' => $this->total(), 'ship_to_first_name' => $this->order->shipping->first_name, 'ship_to_last_name' => $this->order->shipping->last_name, 'ship_to_address' => $this->order->shipping->address1, 'ship_to_city' => $this->order->shipping->city, 'ship_to_state' => $this->order->shipping->state, 'ship_to_zip' => $this->order->shipping->zip, 'ship_to_country' => $this->order->shipping->country, 'first_name' => $this->order->billing->first_name, 'last_name' => $this->order->billing->last_name, 'address' => $this->order->billing->address1, 'city' => $this->order->billing->city, 'state' => $this->order->billing->state, 'zip' => $this->order->billing->zip, 'country' => $this->order->billing->country);
     }
     $payment->set_fields($attributes);
     $this->order->finance_state = 'CHARGING';
     if ($payment->process()) {
         $this->order->finance_state = 'CHARGED';
         $this->order->status = 2;
         //$this->order->save();
         return true;
     } else {
         $this->order->finance_state = 'DENIED';
         $this->order->status = 3;
         //$this->order->save();
         throw new Exception('Payment operation failed (' . $payment->getLastError() . ')');
     }
 }
Esempio n. 2
0
    public function order_status()
    {
        //-----------------------------------------------\\
        // This is the LAST checkout page where the      \\
        // payment is placed using Authorize.net and     \\
        // then lets the user know the payment status    \\
        //-----------------------------------------------\\
        $db = new Database();
        $this->template->content = new View('order_status');
        // Load Captcha library, you can supply the name of the config group you would like to use.
        //$captcha = new Captcha;
        // Ban bots (that accept session cookies) after 50 invalid responses.
        // Be careful not to ban real people though! Set the threshold high enough.
        //if ($captcha->invalid_count() > 49)
        //	exit('Bye! Stupid bot.');
        $this->template->metaDescription = $this->description;
        $this->template->metaKeywords = $this->keywords;
        $this->template->metaTitle = $this->title;
        // You can assign anything variable to a view by using standard OOP
        // methods. In my welcome view, the $title variable will be assigned
        // the value I give it here.
        $this->template->title = $this->title;
        // Captcha::valid() is a static method that can be used as a Validation rule also.
        //if (Captcha::valid($this->input->post('captcha_response'))) {
        //	echo '<p style="color:green">Good answer!</p>';
        //} else {
        //	$this->template->content->status = 3;
        //	$this->template->content->trans_status = "Your Captcha response was incorrect";
        //	exit();
        //}
        $order = ORM::factory('order')->where('id', $_POST['orderid'])->where('user_id', User_Model::logged_user()->id)->find();
        $order->shipping_total = $_POST["shippingtotal"];
        $order->save();
        $order->refreshTotals();
        $ccnum = isset($_POST["cnumber"]) ? $_POST["cnumber"] : '';
        $nameoncard = isset($_POST["cname"]) ? $_POST["cname"] : '';
        $cardexp = isset($_POST["expiration"]) ? $_POST["expiration"] : '';
        $cardcode = isset($_POST["verification"]) ? $_POST["verification"] : '';
        $this->template->content->order = $order;
        $billing_info = $order->user->user_billing_info;
        $shipping_info = $order->user->user_shipping_info;
        $cardfname = $billing_info->firstname;
        $cardlname = $billing_info->lastname;
        $this->template->content->shippingName = $shipping_info->firstname . ' ' . $shipping_info->lastname;
        $this->template->content->shippingAddress = trim($shipping_info->address1 . ' ' . $shipping_info->address2);
        $this->template->content->shippingCity = $shipping_info->city . ', ' . $shipping_info->state . ', ' . $shipping_info->country . ' ' . $shipping_info->zip;
        $this->template->content->billingName = $cardfname . ' ' . $cardlname;
        $this->template->content->billingAddress = trim($billing_info->address1 . ' ' . $billing_info->address2);
        $this->template->content->billingCity = $billing_info->city . ', ' . $billing_info->state . ', ' . $billing_info->country . ' ' . $billing_info->zip;
        $shippingInfo = $shipping_info->firstname . ' ' . $shipping_info->lastname . '<br/>';
        $shippingInfo .= trim($shipping_info->address1 . ' ' . $shipping_info->address2) . '<br />';
        $shippingInfo .= $shipping_info->city . ', ' . $shipping_info->state . ' ' . $shipping_info->zip . '<br />';
        $shippingInfo .= $shipping_info->country;
        $billingInfo = $cardfname . ' ' . $cardlname . '<br/>';
        $billingInfo .= trim($billing_info->address1 . ' ' . $billing_info->address2) . '<br />';
        $billingInfo .= $billing_info->city . ', ' . $billing_info->state . ' ' . $billing_info->zip . '<br />';
        $billingInfo .= $billing_info->country;
        $dateTime = date('Y-m-d H:i:s');
        $additionalFees = 0;
        $description = '';
        foreach ($order->orders_baskets as $ob) {
            $additionalFees += $ob->second_side_fee;
            $product_name = $ob->product->name;
            if ($ob->packaging_id != 0) {
                $product_name .= ' - ' . $ob->packaging->name;
            }
            $description .= $ob->qty . ' x ' . $product_name . ' = ' . money_format('%.2n', $ob->subtotal) . '<br/>';
        }
        if ($additionalFees != 0) {
            $description .= 'Additional Fees: ' . money_format('%.2n', $additionalFees) . '<br/>';
        }
        if (!empty($order->comment)) {
            $description .= 'Comment:' . $order->comment . '<br/>';
        }
        $total_text = 'Subtotal: ' . money_format('%.2n', $order->subtotal) . '<br/>';
        $total_text .= 'Shipping:' . money_format('%.2n', $order->shipping_total) . '<br/>';
        $total_text .= 'Total: ' . money_format('%.2n', $order->order_total);
        switch ($_POST['payment_method']) {
            case 'credit_card':
                $payment = new Payment('Authorize');
                $attributes = array('card_num' => $ccnum, 'exp_date' => $cardexp, 'card_code' => $cardcode, 'amount' => number_format($order->order_total, 2, '.', ''), 'ship_to_first_name' => $shipping_info->firstname, 'ship_to_last_name' => $shipping_info->lastname, 'ship_to_address' => trim($shipping_info->address1 . ' ' . $shipping_info->address2), 'ship_to_city' => $shipping_info->city, 'ship_to_state' => $shipping_info->state, 'ship_to_zip' => $shipping_info->zip, 'first_name' => $cardfname, 'last_name' => $cardlname, 'address' => trim($billing_info->address1 . ' ' . $billing_info->address2), 'city' => $billing_info->city, 'state' => $billing_info->state, 'zip' => $billing_info->zip, 'phone' => $billing_info->phone1, 'x_test_request' => 'FALSE');
                $payment->set_fields($attributes);
                if ($payment->process()) {
                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    // if the payment was SUCCESSFUL
                    $this->template->content->trans_status = $payment->get_response();
                    $this->template->content->status = 1;
                    $transaction_id = $payment->get_transaction_id();
                    $paymentstatus = 3;
                    $orderstatus = 2;
                } else {
                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    // if the payment FAILED
                    $this->template->content->status = 3;
                    $this->template->content->trans_status = $payment->get_response();
                    $orderstatus = 3;
                    $paymentstatus = 1;
                }
                break;
                //			case 'paypal':
                //					@todo: review this code when uncomment
                //					$payment = new Payment('Paypal');
                //					$order->billcountry = "US";
                //
                //					$attributes = array(
                //						'test_mode'			=> FALSE,
                //						'AMT'               => $order->subtotal,
                //						'INVNUM'            => $order->trans_id,
                //						'SHIPTONAME'        => $order->shipfname . ' '. $order->shiplname,
                //						'SHIPTOSTREET'      => $order->billaddress,
                //						'SHIPTOCITY'        => $order->billcity,
                //						'SHIPTOCOUNTRYCODE' => $order->billcountry ,
                //						'SHIPTOSTATE'       => $order->billstate,
                //						'SHIPTOZIP'         => $order->billzip,
                //					);
                //
                //					$payment->set_fields($attributes);
                //
                //					if($payment->process()) {
                //						// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
                //						// if the payment was SUCCESSFUL
                //						$this->template->content->trans_status = '';
                //						$this->template->content->status = 1;
                //						$transaction_id = $order->trans_id;
                //						$paymentstatus = 3;
                //						$orderstatus = 2;
                //					} else {
                //						// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
                //						// if the payment FAILED
                //						$paymentstatus = 1;
                //						$orderstatus = 3;
                //						$this->template->content->status = 3;
                //						$this->template->content->trans_status = '';
                //					}
                //
                //
                //					break;
            //			case 'paypal':
            //					@todo: review this code when uncomment
            //					$payment = new Payment('Paypal');
            //					$order->billcountry = "US";
            //
            //					$attributes = array(
            //						'test_mode'			=> FALSE,
            //						'AMT'               => $order->subtotal,
            //						'INVNUM'            => $order->trans_id,
            //						'SHIPTONAME'        => $order->shipfname . ' '. $order->shiplname,
            //						'SHIPTOSTREET'      => $order->billaddress,
            //						'SHIPTOCITY'        => $order->billcity,
            //						'SHIPTOCOUNTRYCODE' => $order->billcountry ,
            //						'SHIPTOSTATE'       => $order->billstate,
            //						'SHIPTOZIP'         => $order->billzip,
            //					);
            //
            //					$payment->set_fields($attributes);
            //
            //					if($payment->process()) {
            //						// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //						// if the payment was SUCCESSFUL
            //						$this->template->content->trans_status = '';
            //						$this->template->content->status = 1;
            //						$transaction_id = $order->trans_id;
            //						$paymentstatus = 3;
            //						$orderstatus = 2;
            //					} else {
            //						// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //						// if the payment FAILED
            //						$paymentstatus = 1;
            //						$orderstatus = 3;
            //						$this->template->content->status = 3;
            //						$this->template->content->trans_status = '';
            //					}
            //
            //
            //					break;
            case 'testpayment':
                if (FALSE === strpos($_SERVER['SERVER_NAME'], 'beta.polardesign.com')) {
                    $errors = 'Wrong payment method';
                } else {
                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    // if the payment was SUCCESSFUL
                    $this->template->content->trans_status = 'Test payment used';
                    $this->template->content->status = 1;
                    $transaction_id = 'TESTPAYMENT';
                    $paymentstatus = 3;
                    $orderstatus = 2;
                }
                break;
            default:
                $errors = 'Wrong payment method';
        }
        $order->statusID = $orderstatus;
        $order->date_modified = time();
        $order->refreshTotals();
        //includes ->save();
        $order_id = '';
        if ($orderstatus == 2) {
            //CREATE PAYMENT
            $db->query('INSERT INTO payments (transaction_number, statusID, transaction_date) VALUES (\'' . $transaction_id . '\', ' . $paymentstatus . ', ' . time() . ')');
            $paymentid = mysql_insert_id();
            //UPDATE THE ORDER TABLE
            $order->paymentID = $paymentid;
            $order->payment_method = 'Credit Card';
            $order->order_date = date("Y-m-d H:i:s");
            $order->save();
            $user_id = FALSE;
            if (User_Model::logged_in()) {
                $user_id = User_Model::logged_user()->id;
            }
            Session::instance()->regenerate();
            if ($user_id) {
                ORM::factory('user')->find($user_id)->forceLogin();
            }
            //CREATE Order ID Entry
            if (FALSE === ($order_id = $order->getOrderId())) {
                $db->query('INSERT INTO order_ids (order_id) VALUES (' . $order->id . ')');
                $order_id = $order->getOrderId();
            }
        }
        $to = array($order->user->email, '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
        foreach ($to as $address) {
            Autoresponder::sendEmail('order.status.changed', $address, $order, array('shipping_info' => $shippingInfo, 'billing_info' => $billingInfo, 'date_time' => $dateTime, 'description' => $description, 'total' => $total_text, 'order_id' => $order_id, 'email' => $order->user->email));
        }
        // After all the alterations and everything have been made, select the basket and pass on the this of items to the template
        $resultall = $db->query('
							SELECT 
								orders_baskets.*, 
								orders_baskets.id as orders_basket_id, 
								products.name as productname, 
								products_descriptions.image as productimage, 
								products_descriptions.image_alt 
							FROM orders_baskets 
							LEFT JOIN products 
								ON orders_baskets.product_id = products.id 
							LEFT JOIN products_descriptions 
								ON products.products_description_id = products_descriptions.id 
							WHERE orders_baskets.order_id = ' . $order->id);
        $this->template->content->itemsresults = $resultall;
    }
Esempio n. 3
0
 /**
  * Processes the shopping cart with the payment processor, saves the user's
  * cart, clears it and redirects to a success method.
  *
  * @return null
  */
 public function action_process()
 {
     $order = Auth::instance()->get_user()->cart();
     $user_post = arr::get($_POST, 'user', array());
     $user = arr::get($_POST, 'user', Auth::instance()->get_user());
     if (!is_object($user)) {
         $temp = $user;
         $user = AutoModeler_ORM::factory('user');
         $user->set_fields($temp);
     }
     $address = AutoModeler_ORM::factory('vendo_address');
     $address->set_fields(arr::get($_POST, 'address', array()));
     // Build the contact model
     $contact = new Model_Contact();
     $contact->set_fields(array('email' => $user->email, 'first_name' => $user->first_name, 'last_name' => $user->last_name));
     // Build the credit card model
     $credit_card_post = arr::get($_POST, 'payment');
     $credit_card = new Model_Credit_Card(arr::get($credit_card_post, 'card_number'), arr::get($credit_card_post, 'months') . arr::get($credit_card_post, 'years'), arr::get($credit_card_post, 'card_code'), $contact, $address);
     $errors = array();
     // Check for a new user registration, and make a user if so
     if ($this->should_create_account($user)) {
         $status = $this->process_new_account($user, $user_post, $address);
         if (!$status) {
             return;
         }
         $contact->save();
         $order->user_id = $user->id;
     } else {
         $user_address = $user->address->as_array();
         unset($user_address['id']);
         if ($user_address != $address and TRUE === $address->is_valid()) {
             $address->save();
             $user->address_id = $address->id;
         } elseif (TRUE !== $address->is_valid()) {
             $errors += $address->errors('form_errors');
         } else {
             $address = $user->address;
         }
         $contact->address_id = $address->id;
         if (TRUE !== $contact->is_valid()) {
             $errors += $contact->errors('form_errors');
         }
         if (Auth::instance()->logged_in()) {
             $order->user_id = $user->id;
         }
     }
     // Verify the credit card is valid
     if (TRUE !== ($cc_errors = $credit_card->validate())) {
         $errors += $cc_errors;
     }
     if ($errors) {
         // If we've failed, and we aren't registering a new user, delete
         // the address
         if (!$user->id) {
             $address->delete();
         }
         $this->request->response = new View_Checkout_Index();
         $this->request->response->set(array('user' => $user->as_array(), 'address' => $address->as_array(), 'cart' => Auth::instance()->get_user()->cart(), 'credit_card' => $credit_card));
         $errors = (string) View::factory('form_errors')->set(array('errors' => $errors));
         $this->request->response->errors = $errors;
         return;
     }
     $order->credit_card = $credit_card;
     // Process the credit card
     try {
         $status = Payment::process($order);
         if (1 != $status->response_code) {
             throw new Payment_Exception('Problem processing your payment.');
         }
         // Persist the order
         $contact->save();
         $order->contact_id = $contact->id;
         $order->address_id = $address->id;
         $order->save();
         Auth::instance()->get_user()->cart(new Model_Order());
         // Show success message!
         $this->request->response = new View_Checkout_Process();
     } catch (Payment_Exception $e) {
         // If we've failed, and we aren't registering a new user, delete
         // the address
         if (!$user->id) {
             $address->delete();
         }
         $this->request->response = new View_Checkout_Index();
         $this->request->response->set(array('user' => $user->as_array(), 'address' => $address->as_array(), 'cart' => Auth::instance()->get_user()->cart(), 'credit_card' => $credit_card));
         $errors = (string) View::factory('form_errors')->set(array('errors' => array('general' => $e->getMessage())));
         $this->request->response->errors = $errors;
         return;
     }
 }
Esempio n. 4
0
 public function process($values)
 {
     $order = parent::process($values);
 }