Exemple #1
0
 public function test()
 {
     // In Kohana, all views are loaded and treated as objects.
     $this->template->content = new View('test_cc');
     $this->template->metaDescription = 'A new generation of custom chocolate favors is here with our state-of-the-art My Chocolate Hearts customizers. We help you design your own personalized and custom chocolate hearts for any occasion from party to wedding, bridal and baby shower, corporate and many more. Call us toll free at 1-866-230-7730.';
     $this->template->metaKeywords = 'chocolate hearts, custom chocolate hearts, personalized chocolate hearts, chocolate favors, custom chocolate favors, party favors, personalized chocolate favors, chocolate casino chips, chocolate poker chips, custom chocolate casino chips, casino party favors, wedding favors, personalized wedding favors, baby shower favors, bridal shower favors, chocolate gelt, chocolate gold hearts, chocolate party favors, chocolate candy favors, custom chocolate, custom chocolate poker chips, corporate favors';
     $payment = new Payment('Authorize');
     $attributes = array('card_num' => '4222222222222', 'exp_date' => '01/13', 'amount' => '2.00', 'ship_to_first_name' => 'Alexander', 'ship_to_last_name' => 'Finger', 'ship_to_address' => '600 Unicorn Park Dr.', 'ship_to_city' => 'Woburn', 'ship_to_state' => 'MA', 'ship_to_zip' => '01801', 'ship_to_country' => 'USA', 'first_name' => 'Alexander', 'last_name' => 'Finger', 'address' => '600 Unicorn Park Dr.', 'city' => 'Woburn', 'state' => 'MA', 'zip' => '01801', 'country' => 'USA', 'x_test_request' => 'TRUE');
     $status = 0;
     $payment->set_fields($attributes);
     $finance_state = 'CHARGING';
     echo "<pre>";
     var_dump($payment);
     echo "</pre>";
     break;
     if ($payment->process()) {
         $finance_state = 'CHARGED';
         $status = 2;
         echo "<pre>";
         var_dump($payment);
         var_dump($finance_state);
         var_dump($status);
         echo "</pre>";
         //$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() . ')');
     }
     // 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 = 'My Chocolate Hearts';
 }
Exemple #2
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() . ')');
     }
 }
    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;
    }