Ejemplo n.º 1
0
function handlePaymentCompleted($order_id)
{
    echo "-- handlePaymentCompleted";
    $order = new WC_Order($order_id);
    $customer = new WC_Customer($order_id);
    $addresses = $order->get_address("shipping");
    /*
    $To = get_option('admin_email').",dev_support@soixanteseize.com";
        $Objet = $email_heading = "Vérifiez la commande ".$order_id;
        $message = $response[1];
        ob_start();
        include(COURIIERPATH.'views/mails/woo-couriier-order-ready.php');
        $Body = ob_get_clean();
        trace($Body);
        //sendCC($To, $Objet, $Body);
    
        return;
    */
    $adresse = $addresses["address_1"] . ", ";
    if ($addresses["address_2"] != "") {
        $adresse .= $addresses["address_2"] . ", ";
    }
    $adresse .= $addresses["city"] . " ";
    $adresse .= $addresses["postcode"] . " ";
    //$postcode = $addresses["postcode"];
    //trace($order);
    //trace($customer);
    //trace($order->get_address("shipping") );
    //trace($adresse);
    $chosen_methods = $order->get_shipping_methods();
    if (count($chosen_methods) > 0) {
        //$la_methode = object();
        foreach ($chosen_methods as $c_method) {
            //                trace($method);
            $chosen_method = $c_method['item_meta']['method_id'][0];
        }
        //trace($chosen_method);
        $available_methods = WC()->session->get('shipping_methods_' . $addresses["postcode"]);
        //trace($available_methods);
        $offerIdTarifs = '';
        foreach ($available_methods as $method) {
            //trace($method->speed);
            switch ($method->speed) {
                case 2:
                    if ($chosen_method == 'couriier_classic_shipping_method') {
                        $offerIdTarifs = $method->ref;
                    }
                    break;
                case 1:
                    if ($chosen_method == 'couriier_rapide_shipping_method') {
                        $offerIdTarifs = $method->ref;
                    }
                    break;
                case 0:
                    if ($chosen_method == 'couriier_flash_shipping_method') {
                        $offerIdTarifs = $method->ref;
                    }
                    break;
            }
        }
        //return;
        $adresse = $customer->get_address() . " " . $customer->get_postcode() . ", " . $customer->get_city();
        $recipientLatLng = geoloc($adresse);
        //trace($customer);
        //trace($recipientLatLng);
        //trace($offerIdTarifs);
        //return;
        $body = array(array('offerIdTarifs' => $offerIdTarifs, 'pickupName' => get_bloginfo("name"), 'pickupLatitude' => PICKUPLAT, 'pickupLongitude' => PICKUPLNG, 'pickupAddress' => PICKUPADRESSE, 'pickupAddress2' => "test", 'pickupTel' => PICKUPTEL, 'pickupZip' => PICKUPZIP, 'pickupCity' => PICKUPCITY, 'recipientName' => $order->get_formatted_shipping_full_name(), 'recipientLatitude' => $recipientLatLng["lat"], 'recipientLongitude' => $recipientLatLng["lng"], 'recipientAddress' => $addresses["address_1"], 'recipientAddress2' => $addresses["address_2"], 'recipientTel' => $order->billing_phone, 'recipientZip' => $addresses["postcode"], 'recipientCity' => $addresses["city"], 'timeManagement' => "2015-04-24 00:00:00", 'deliveryType' => "En main propre"));
        //trace($body);
        //return;
        $body = json_encode($body);
        $url = COURIIER_WS . '/orders';
        //trace($url);
        $response = api_call_post($url, $body);
        //trace($response);
        $response = json_decode($response['body']);
        //trace($response);
        $couriier_order_id = $response[0]->id;
        //trace($order_id);
        //return;
        if ($couriier_order_id) {
            /**
                url_order_follow
                    **/
            $url_order_follow = $response[0]->following_url;
            //trace($url_order_follow);
            if ($url_order_follow) {
                $To = $order->billing_email;
                $Objet = $email_heading = "Votre lien pour suivre la livraison Couriier";
                ob_start();
                include COURIIERPATH . 'views/mails/woo-couriier-order-follow.php';
                $Body = ob_get_clean();
                sendCC($To, $Objet, $Body);
            }
            /**
                url_order_ready
                    **/
            $url_rest_order_ready = get_bloginfo("url") . '/wc-api/couriier-order-ready?order_id=' . $order_id . '&couriier_order_id=' . $couriier_order_id;
            //$url_order_ready = COURIIER_WS.'/order/'.$couriier_order_id.'/ready';
            //trace($url_rest_order_ready);
            //return;
            $To = get_option('admin_email') . ",dev_support@soixanteseize.com";
            $Objet = $email_heading = "Votre lien pour lancer la livraison Couriier";
            ob_start();
            include COURIIERPATH . 'views/mails/woo-couriier-order-ready.php';
            $Body = ob_get_clean();
            //trace($Body);
            sendCC($To, $Objet, $Body);
            //return;
        }
    } else {
        $To = get_option('admin_email') . ",dev_support@soixanteseize.com";
        $Objet = $email_heading = "U+026A0 Vérifiez la commande " . $order_id;
        $message = $response[1];
        ob_start();
        include COURIIERPATH . 'views/mails/woo-couriier-blank.php';
        $Body = ob_get_clean();
        //trace($Body);
        sendCC($To, $Objet, $Body);
    }
    //sendCC($To, $Objet, $Body);
}
    /**
     * Generate form
     * @param $order_id
     * @return string
     */
    function generate_pagantis_eom_form($order_id)
    {
        //Logs
        $this->log->add('pagantis', 'Acceso al pago con Paga+Tarde');
        $order = new WC_Order($order_id);
        //Total Amount
        $transaction_amount = number_format((double) $order->get_total(), 2, '.', '');
        $transaction_amount = str_replace('.', '', $transaction_amount);
        $transaction_amount = floatval($transaction_amount);
        // Product Description
        $products = WC()->cart->cart_contents;
        $i = 1;
        $products_form = "";
        $description = "";
        foreach ($products as $product) {
            $products_form .= "\r\n              <input name='items[" . $i . "][description]' type='hidden' value='" . $product['data']->post->post_title . ' (' . $product['quantity'] . ')' . "'>\r\n              <input name='items[" . $i . "][quantity]' type='hidden' value='" . $product['quantity'] . "'>\r\n              <input name='items[" . $i . "][amount]' type='hidden' value='" . $product['data']->price * $product['quantity'] . "'>\r\n              ";
            $description[] = $product['data']->post->post_title . ' (' . $product['quantity'] . ')';
            $i++;
        }
        $shipping = $order->get_items('shipping');
        foreach ($shipping as $shipping_method) {
            if ($shipping_method['cost'] > 0) {
                $products_form .= "\r\n                <input name='items[" . $i . "][description]' type='hidden' value='" . __('Gastos de envio', 'pagantis') . "'>\r\n                <input name='items[" . $i . "][quantity]' type='hidden' value='1'>\r\n                <input name='items[" . $i . "][amount]' type='hidden' value='" . $shipping_method['cost'] . "'>\r\n                ";
                $description[] = 'Gastos de envio';
                $i++;
            }
        }
        $this->ok_url = $this->get_return_url($order);
        $this->ko_url = htmlspecialchars_decode($order->get_cancel_order_url());
        $account_id = "";
        $dataToEncode = "";
        //Test Environment Selected
        if ($this->environment == self::TEST_ENVIRONMENT) {
            $this->key = $this->test_key;
            $dataToEncode = $this->test_key . $this->test_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url;
            $account_id = $this->test_account;
        } else {
            $this->key = $this->real_key;
            $dataToEncode = $this->real_key . $this->real_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url;
            $account_id = $this->real_account;
        }
        $signature = sha1($dataToEncode);
        $form_url = $this->paga_mastarde_url;
        $adressInfo = explode("/", $order->billing_city);
        $customer = new WC_Customer();
        $countries = new WC_Countries();
        $address = $customer->get_address() . " " . $customer->get_address_2();
        $city = $customer->get_city();
        $postcode = $customer->get_postcode();
        $states = $countries->get_states();
        $state = $states[$order->shipping_country][$customer->get_state()];
        //todo can include shipping information
        //Create Form
        $buyer_name = $order->billing_first_name . " " . $order->billing_last_name;
        $pagantis_form_fields = "\r\n            <input name='order_id' type='hidden' value='" . $order_id . "' />\r\n            <input name='amount' type='hidden' value='" . $transaction_amount . "' />\r\n            <input name='currency' type='hidden' value='" . $this->currency . "' />\r\n\r\n            <input name='ok_url' type='hidden' value='" . $this->ok_url . "' />\r\n            <input name='nok_url' type='hidden' value='" . $this->ko_url . "' />\r\n\r\n            <input name='locale' type='hidden' value='" . $this->lang . "' />\r\n\r\n            <input name='full_name' type='hidden' value='" . $buyer_name . "'>\r\n            <input name='email' type='hidden' value='" . $order->billing_email . "'>\r\n\r\n            " . $products_form . "\r\n\r\n            <!-- firma de la operación -->\r\n            <input name='account_id' type='hidden' value='" . $account_id . "' />\r\n            <input name='signature' type='hidden' value='" . $signature . "' />\r\n\r\n            <!-- discount -->\r\n            <input name='iframe' type='hidden' value='" . $this->iframe . "' />\r\n\r\n            <!-- callback url -->\r\n            <input name='callback_url' type='hidden' value='" . $this->callback_url . "' />\r\n\r\n            <input name='description' type='hidden' value='" . implode(',', $description) . "' />\r\n\r\n            <!-- address -->\r\n            <input name='address[street]' type='hidden' value='" . $address . "'>\r\n            <input name='address[city]' type='hidden' value='" . $city . "'>\r\n            <input name='address[province]' type='hidden' value='" . $state . "'>\r\n            <input name='address[zipcode]' type='hidden' value='" . $postcode . "'>\r\n\r\n            <!-- eom -->\r\n            <input name='end_of_month' type='hidden' value='true'>\r\n            <!-- phone -->\r\n\r\n            <input name='phone' type='hidden' value='" . $order->billing_phone . "'>\r\n            ";
        $return_form = '<form action="' . $form_url . '" method="post" id="pagantis_payment_form">
            ' . $pagantis_form_fields . '
            <a class="button cancel floatLeft" href="' . $order->get_cancel_order_url() . '">' . __('Cancelar Pedido', 'pagantis') . '</a>
            <input type="submit" class="button-alt" id="submit_vme_payment_form" value="' . __('Realizar el pago', 'pagantis') . '" />

            </form>';
        if ($this->iframe == 'true') {
            $return_form .= "<script type='text/javascript'>\r\n\r\n            jQuery(document).ready(function() {\r\n              if (jQuery.isFunction(jQuery.fancybox) ){\r\n                 jQuery('#submit_vme_payment_form').on('click', function (e) {\r\n                  e.preventDefault(); // avoids calling success.php from the link\r\n                  //post data to get form url.\r\n                  jQuery.ajax({\r\n                    type: 'POST',\r\n                    url: '" . get_site_url() . "/wp-content/plugins/pagamastarde-payment-gateway-for-woocommerce/getPmtUrl.php',\r\n                    data: jQuery('#pagantis_payment_form').serialize(),\r\n                    success: function(data, textStatus, jqXHR)\r\n                    {\r\n                      jQuery.fancybox({\r\n                        // fancybox API options\r\n                        type: 'iframe',\r\n                        fitToView: false,\r\n                        openEffect: 'none',\r\n                        closeEffect: 'none',\r\n                        'width'  : 920,\r\n                        'minHeight' : 230,\r\n                        'href': data\r\n                      }); // fancybox\r\n                    }\r\n                  });\r\n                }); // on\r\n              }\r\n            }); //ready\r\n\r\n            </script>";
        }
        return $return_form;
    }
Ejemplo n.º 3
0
        $state = '';
        $zip = '';
        break;
}
if (isset($_COOKIE['builder_user'])) {
    $customer = unserialize(str_replace('\\"', '"', $_COOKIE['builder_user']));
    foreach ($customer as $field => $value) {
        if ($field == 'billing_state') {
            $state = $value;
        }
    }
} elseif (is_user_logged_in()) {
    $customer_data = new WC_Customer();
    global $current_user;
    get_currentuserinfo();
    $customer = array('billing_first_name' => $current_user->user_firstname, 'billing_last_name' => $current_user->user_lastname, 'billing_email' => $current_user->user_email, 'billing_phone' => '', 'billing_address_1' => $customer_data->get_address(), 'billing_address_2' => $customer_data->get_address_2(), 'billing_city' => $customer_data->get_city(), 'billing_postcode' => $customer_data->get_postcode(), 'billing_state' => $customer_data->get_state());
}
?>
						
						<style type="text/css" media="screen">
							#contact_form { padding-bottom:20px; }
							#contact_form .field_block { float:left; width:45%; margin-right:5%; padding-bottom:10px; }
							#contact_form .field_block label { display:block; font-weight:bold; }
							#contact_form .field_block input, #contact_form .field_block select { width:100%; }
						</style>
						
						<div id="contact_form">
							<div class="field_block">
								<label><?php 
echo $firstname;
?>
            /**
             * Generate form
             * @param $order_id
             * @return string
             */
            function generate_pagantis_form($order_id)
            {
                //Logs
                $this->log->add('pagantis', 'Acceso al pago con Paga+Tarde');
                $order = new WC_Order($order_id);
                //Total Amount
                $transaction_amount = number_format((double) $order->get_total(), 2, '.', '');
                $transaction_amount = str_replace('.', '', $transaction_amount);
                $transaction_amount = floatval($transaction_amount);
                // Product Description
                $products = WC()->cart->cart_contents;
                $i = 1;
                $products_form = "";
                $description = "";
                foreach ($products as $product) {
                    $products_form .= "\r\n                  <input name='items[" . $i . "][description]' type='hidden' value='" . $product['data']->post->post_title . ' (' . $product['quantity'] . ')' . "'>\r\n                  <input name='items[" . $i . "][quantity]' type='hidden' value='" . $product['quantity'] . "'>\r\n                  <input name='items[" . $i . "][amount]' type='hidden' value='" . round(($product['data']->price + $product['line_tax']) * $product['quantity'], 2) . "'>\r\n                  ";
                    $description[] = $product['data']->post->post_title . ' (' . $product['quantity'] . ')';
                    $i++;
                }
                $shipping = $order->get_items('shipping');
                foreach ($shipping as $shipping_method) {
                    if ($shipping_method['cost'] > 0) {
                        $products_form .= "\r\n                    <input name='items[" . $i . "][description]' type='hidden' value='" . __('Gastos de envio', 'pagantis') . "'>\r\n                    <input name='items[" . $i . "][quantity]' type='hidden' value='1'>\r\n                    <input name='items[" . $i . "][amount]' type='hidden' value='" . $shipping_method['cost'] . "'>\r\n                    ";
                        $description[] = 'Gastos de envio';
                        $i++;
                    }
                }
                $account_id = "";
                $dataToEncode = "";
                $this->ok_url = $this->get_return_url($order);
                $this->ko_url = htmlspecialchars_decode(WC_Cart::get_checkout_url());
                $this->cancelled_url = htmlspecialchars_decode(WC_Cart::get_checkout_url());
                //Test Environment Selected
                if ($this->environment == self::TEST_ENVIRONMENT) {
                    $this->key = $this->test_key;
                    $dataToEncode = $this->test_key . $this->test_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url . $this->discount . $this->cancelled_url;
                    $account_id = $this->test_account;
                } else {
                    $this->key = $this->real_key;
                    $dataToEncode = $this->real_key . $this->real_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url . $this->discount . $this->cancelled_url;
                    $account_id = $this->real_account;
                }
                $signature = hash('sha512', $dataToEncode);
                $form_url = $this->paga_mastarde_url;
                $adressInfo = explode("/", $order->billing_city);
                $customer = new WC_Customer();
                $countries = new WC_Countries();
                $address = $customer->get_address() . " " . $customer->get_address_2();
                $city = $customer->get_city();
                $postcode = $customer->get_postcode();
                $states = $countries->get_states();
                $state = $states[$order->shipping_country][$customer->get_state()];
                $saddress = $customer->shipping_address_1 . " " . $customer->shipping_address_2;
                $scity = $customer->shipping_city;
                $spostcode = $customer->shipping_postcode;
                $sstate = $states[$order->shipping_country][$customer->shipping_state];
                //Create Form
                $buyer_name = $order->billing_first_name . " " . $order->billing_last_name;
                $pagantis_form_fields = "\r\n                <input name='order_id' type='hidden' value='" . $order_id . "' />\r\n                <input name='amount' type='hidden' value='" . $transaction_amount . "' />\r\n                <input name='currency' type='hidden' value='" . $this->currency . "' />\r\n\r\n                <input name='ok_url' type='hidden' value='" . $this->ok_url . "' />\r\n                <input name='nok_url' type='hidden' value='" . $this->ko_url . "' />\r\n                <input name='cancelled_url' type='hidden' value='" . $this->cancelled_url . "' />\r\n\r\n                <input name='locale' type='hidden' value='" . $this->lang . "' />\r\n\r\n                <input name='full_name' type='hidden' value='" . $buyer_name . "'>\r\n                <input name='email' type='hidden' value='" . $order->billing_email . "'>\r\n\r\n                " . $products_form . "\r\n\r\n                <!-- firma de la operación -->\r\n                <input name='account_id' type='hidden' value='" . $account_id . "' />\r\n                <input name='signature' type='hidden' value='" . $signature . "' />\r\n\r\n                <!-- discount -->\r\n                <input name='discount[full]' type='hidden' value='" . $this->discount . "' />\r\n                <input name='iframe' type='hidden' value='" . $this->iframe . "' />\r\n\r\n                <!-- callback url -->\r\n                <input name='callback_url' type='hidden' value='" . $this->callback_url . "' />\r\n\r\n                <input name='description' type='hidden' value='" . implode(',', $description) . "' />\r\n\r\n                <!-- address -->\r\n                <input name='address[street]' type='hidden' value='" . $address . "'>\r\n                <input name='address[city]' type='hidden' value='" . $city . "'>\r\n                <input name='address[province]' type='hidden' value='" . $state . "'>\r\n                <input name='address[zipcode]' type='hidden' value='" . $postcode . "'>\r\n\r\n                <input name='shipping[street]' type='hidden' value='" . $saddress . "'>\r\n                <input name='shipping[city]' type='hidden' value='" . $scity . "'>\r\n                <input name='shipping[province]' type='hidden' value='" . $sstate . "'>\r\n                <input name='shipping[zipcode]' type='hidden' value='" . $spostcode . "'>\r\n\r\n                <!-- phone -->\r\n\r\n                <input name='mobile_phone' type='hidden' value='" . $order->billing_phone . "'>\r\n                ";
                $return_form = '<form action="' . $form_url . '" method="post" id="pagantis_payment_form">
                ' . $pagantis_form_fields . '
                <input type="submit" class="button-alt" id="submit_vme_payment_form" value="' . __('Realizar el pago', 'pagantis') . '" />

                </form>';
                if ($this->iframe == 'true') {
                    wp_enqueue_style('style', esc_url(plugins_url('pages/assets/css/iframe.css', __FILE__)));
                    $return_form .= '<div id="myModal" class="paylater_modal">
                    <!-- Modal content -->
                    <div class="paylater_modal-content">
                      <span id="paylater_close">x</span>
                      <iframe id="iframe-pagantis" name="iframe-pagantis" style="width:100%;height:600px;display:block"></iframe>
                    </div>
                  </div>';
                    $return_form .= '<script type="text/javascript">
                  el = document.getElementById("submit_vme_payment_form");
                  el.addEventListener("click", function (e){
                    e.preventDefault();
                    document.getElementById("pagantis_payment_form").setAttribute("target", "iframe-pagantis");
                    document.getElementById("pagantis_payment_form").submit();
                    document.getElementById("iframe-pagantis").style.display = "block";
                    document.getElementById("myModal").style.display = "block";
                  });

                  var closeModal = function closeModal(evt) {
                   evt.preventDefault();
                   document.getElementById("myModal").style.display = "none";
                  };

                  var elements = document.querySelectorAll("#paylater_close, #myModal");
                   Array.prototype.forEach.call(elements, function(el){
                   el.addEventListener("click", closeModal);
                  });

                  document.addEventListener("DOMContentLoaded", function(event) {
                    document.getElementById("pagantis_payment_form").setAttribute("target", "iframe-pagantis");
                    document.getElementById("pagantis_payment_form").submit();
                    document.getElementById("iframe-pagantis").style.display = "block";
                    document.getElementById("myModal").style.display = "block";
                    });
                  </script>';
                } else {
                    $return_form .= "<script type='text/javascript'>\r\n                  jQuery(document).ready(function() {\r\n                    jQuery('#submit_vme_payment_form').click();\r\n                  });\r\n                  </script>";
                }
                return $return_form;
            }