/**
  * Get the order from the PayPal 'Custom' variable
  *
  * @param  string $raw_custom JSON Data passed back by PayPal
  * @return bool|WC_Order object
  */
 protected function get_paypal_order($raw_custom)
 {
     // We have the data in the correct format, so get the order
     if (($custom = json_decode($raw_custom)) && is_object($custom)) {
         $order_id = $custom->order_id;
         $order_key = $custom->order_key;
         // Fallback to serialized data if safe. This is @deprecated in 2.3.11
     } elseif (preg_match('/^a:2:{/', $raw_custom) && !preg_match('/[CO]:\\+?[0-9]+:"/', $raw_custom) && ($custom = maybe_unserialize($raw_custom))) {
         $order_id = $custom[0];
         $order_key = $custom[1];
         // Nothing was found
     } else {
         WC_Gateway_Paypal::log('Error: Order ID and key were not found in "custom".');
         return false;
     }
     if (!($order = wc_get_order($order_id))) {
         // We have an invalid $order_id, probably because invoice_prefix has changed
         $order_id = wc_get_order_id_by_order_key($order_key);
         $order = wc_get_order($order_id);
     }
     if (!$order || $order->order_key !== $order_key) {
         WC_Gateway_Paypal::log('Error: Order Keys do not match.');
         return false;
     }
     return $order;
 }
 /**
  * Get the order from the PayPal 'Custom' variable
  *
  * @param  string $custom
  * @return bool|WC_Order object
  */
 protected function get_paypal_order($custom)
 {
     $custom = maybe_unserialize($custom);
     if (is_array($custom)) {
         list($order_id, $order_key) = $custom;
         if (!($order = wc_get_order($order_id))) {
             // We have an invalid $order_id, probably because invoice_prefix has changed
             $order_id = wc_get_order_id_by_order_key($order_key);
             $order = wc_get_order($order_id);
         }
         if (!$order || $order->order_key !== $order_key) {
             $this->log('Error: Order Keys do not match.');
             return false;
         }
     } elseif (!($order = apply_filters('woocommerce_get_paypal_order', false, $custom))) {
         $this->log('Error: Order ID and key were not found in "custom".');
         return false;
     }
     return $order;
 }
 /**
  * Get the order from the PayPal 'Custom' variable.
  *
  * @param  string $raw_custom JSON Data passed back by PayPal
  * @return bool|WC_Order      Order object or false
  */
 protected function get_paypal_order($raw_custom)
 {
     // We have the data in the correct format, so get the order.
     if (($custom = json_decode($raw_custom)) && is_object($custom)) {
         $order_id = $custom->order_id;
         $order_key = $custom->order_key;
     } else {
         wc_gateway_ppec_log(sprintf('%s: %s', __FUNCTION__, 'Error: Order ID and key were not found in "custom".'));
         return false;
     }
     if (!($order = wc_get_order($order_id))) {
         // We have an invalid $order_id, probably because invoice_prefix has changed.
         $order_id = wc_get_order_id_by_order_key($order_key);
         $order = wc_get_order($order_id);
     }
     if (!$order || $order->order_key !== $order_key) {
         wc_gateway_ppec_log(sprintf('%s: %s', __FUNCTION__, 'Error: Order Keys do not match.'));
         return false;
     }
     return $order;
 }
 /**
  * Notification callback.
  *
  * @param void
  * @return void
  */
 public function coinsimple_callback()
 {
     // obtain body
     @ob_clean();
     $body = file_get_contents('php://input');
     $data = json_decode($body);
     $business = new \CoinSimple\Business($this->get_option("business_id"), $this->get_option('api_key'));
     if (!$business->validateHash($data->hash, $data->timestamp)) {
         $this->debug(__METHOD__, 'invalid callback hash');
         return;
     }
     $order = new WC_Order($data->custom->order_id);
     if (!isset($order->id)) {
         // orderId invalid, try alternate find
         $orderId = wc_get_order_id_by_order_key($data->custom->order_key);
         $order = new WC_Order($orderId);
     }
     if ($order->order_key !== $data->custom->order_key) {
         $this->debug(__METHOD__, 'invalid order key');
         return;
     }
     $order->payment_complete();
 }
/**
 * @deprecated
 */
function woocommerce_get_order_id_by_order_key($order_key)
{
    return wc_get_order_id_by_order_key($order_key);
}
 public static function check_payment_response()
 {
     if (!empty($_REQUEST['imp_uid'])) {
         //결제승인 결과조회
         require_once WSKL_PATH . '/includes/lib/iamport/iamport.php';
         $imp_uid = $_REQUEST['imp_uid'];
         $rest_key = wskl_get_option('iamport_rest_key');
         $rest_secret = wskl_get_option('iamport_rest_secret');
         $iamport = new Iamport($rest_key, $rest_secret);
         $result = $iamport->findByImpUID($imp_uid);
         if ($result->success) {
             $payment_data = $result->data;
             if (empty($_REQUEST['order_id'])) {
                 //call by iamport notification
                 $order_id = wc_get_order_id_by_order_key($payment_data->merchant_uid);
             } else {
                 $order_id = $_REQUEST['order_id'];
             }
             $order = wc_get_order($order_id);
             update_post_meta($order_id, '_iamport_provider', $payment_data->pg_provider);
             update_post_meta($order_id, '_iamport_paymethod', $payment_data->pay_method);
             update_post_meta($order_id, '_iamport_receipt_url', $payment_data->receipt_url);
             if ($payment_data->status == 'paid') {
                 if ($order->order_total == $payment_data->amount) {
                     if (!$order->has_status(array('processing', 'completed'))) {
                         $order->payment_complete($payment_data->imp_uid);
                         //imp_uid
                         wp_redirect($order->get_checkout_order_received_url());
                         return;
                     }
                 } else {
                     $order->add_order_note('요청하신 결제금액이 다릅니다.');
                     wc_add_notice('요청하신 결제금액이 다릅니다.', 'error');
                 }
             } else {
                 if ($payment_data->status == 'ready') {
                     if ($payment_data->pay_method == 'vbank') {
                         $vbank_name = $payment_data->vbank_name;
                         $vbank_num = $payment_data->vbank_num;
                         $vbank_date = $payment_data->vbank_date;
                         //가상계좌 입금할 계좌정보 기록
                         update_post_meta($order_id, '_iamport_vbank_name', $vbank_name);
                         update_post_meta($order_id, '_iamport_vbank_num', $vbank_num);
                         update_post_meta($order_id, '_iamport_vbank_date', $vbank_date);
                         //가상계좌 입금대기 중
                         $order->update_status('awaiting-vbank', __('가상계좌 입금대기 중', 'iamport'));
                         wp_redirect($order->get_checkout_order_received_url());
                         return;
                     } else {
                         $order->add_order_note('실제 결제가 이루어지지 않았습니다.');
                         wc_add_notice('실제 결제가 이루어지지 않았습니다.', 'error');
                     }
                 } else {
                     if ($payment_data->status == 'failed') {
                         $order->add_order_note('결제요청 승인에 실패하였습니다.');
                         wc_add_notice('결제요청 승인에 실패하였습니다.', 'error');
                     }
                 }
             }
         } else {
             $payment_data =& $result->data;
             if (!empty($_REQUEST['order_id'])) {
                 $order = new WC_Order($_REQUEST['order_id']);
                 $order->update_status('failed');
                 $order->add_order_note('결제승인정보를 받아오지 못했습니다. 관리자에게 문의해주세요' . $payment_data->error['message']);
                 wc_add_notice($payment_data->error['message'], 'error');
                 $redirect_url = $order->get_checkout_payment_url(TRUE);
                 wp_redirect($redirect_url);
             }
         }
     }
 }
 function woocommerce_pay_order_button_html($html)
 {
     $orderid = wc_get_order_id_by_order_key($_REQUEST['key']);
     if ($_available_gateways = WC()->payment_gateways->get_available_payment_gateways()) {
         if (isset($_available_gateways['inicis_card']) || isset($_available_gateways['inicis_bank']) || isset($_available_gateways['inicis_vbank']) || isset($_available_gateways['inicis_hpp']) || isset($_available_gateways['inicis_kpay']) || isset($_available_gateways['inicis_stdcard']) || isset($_available_gateways['inicis_escrow_bank'])) {
             if (wp_is_mobile()) {
                 wp_register_script('ifw-pay-for-order', $this->plugin_url() . '/assets/js/ifw_pay_for_order.mobile.js', array(), $this->version);
             } else {
                 wp_register_script('ifw-pay-for-order', $this->plugin_url() . '/assets/js/ifw_pay_for_order.js', array(), $this->version);
             }
             wp_enqueue_script('ifw-pay-for-order');
             wp_localize_script('ifw-pay-for-order', '_ifw_pay_for_order', array('ajax_loader_url' => $this->plugin_url() . '/assets/images/ajax_loader.gif', 'order_id' => $orderid, 'order_key' => $_REQUEST['key']));
         }
     }
     return $html;
 }
 /**
  * get_paypal_order function.
  *
  * @param  string $custom
  * @param  string $invoice
  * @return WC_Order object
  */
 private function get_paypal_order($custom, $invoice = '')
 {
     $custom = maybe_unserialize($custom);
     // Backwards comp for IPN requests
     if (is_numeric($custom)) {
         $order_id = (int) $custom;
         $order_key = $invoice;
     } elseif (is_string($custom)) {
         $order_id = (int) str_replace($this->invoice_prefix, '', $custom);
         $order_key = $custom;
     } else {
         list($order_id, $order_key) = $custom;
     }
     $order = new WC_Order($order_id);
     if (!isset($order->id)) {
         // We have an invalid $order_id, probably because invoice_prefix has changed
         $order_id = wc_get_order_id_by_order_key($order_key);
         $order = new WC_Order($order_id);
     }
     // Validate key
     if ($order->order_key !== $order_key) {
         if ('yes' == $this->debug) {
             $this->log->add('paypal', 'Error: Order Key does not match invoice.');
         }
         exit;
     }
     return $order;
 }
Ejemplo n.º 9
0
 private function generate_form($order, $URL_Request)
 {
     $order_key = $_GET['key'];
     $order_id = wc_get_order_id_by_order_key($order_key);
     return '<a class="button" href="' . get_site_url() . '/?TodoPago_redirect=true&form=ext&order=' . $order_id . '" id="submit_todopago_payment_form"> Pagar con TodoPago </a>  
       <a class="button cancel" href="' . $order->get_cancel_order_url() . '">' . ' Cancelar orden ' . '</a>';
 }
 /**
  * Return page of Alipay, show Alipay Trade No. 
  *
  * @access public
  * @param mixed Sync Notification
  * @return void
  */
 function thankyou_page($order_id)
 {
     $_GET = stripslashes_deep($_GET);
     if (isset($_GET['trade_status']) && !empty($_GET['trade_status'])) {
         require_once "lib/alipay_notify.class.php";
         $aliapy_config = $this->get_alipay_config();
         $alipayNotify = new AlipayNotify($aliapy_config);
         $order_key = $_GET['key'];
         // Delete parameters added by WC from $_GET
         if (isset($_GET['page_id'])) {
             unset($_GET['page_id']);
         }
         // When using default permlaink format
         if (isset($_GET['order-received'])) {
             unset($_GET['order-received']);
         }
         // When using default permlaink format
         unset($_GET['order']);
         unset($_GET['key']);
         if ($this->debug == 'yes') {
             $log = true;
         }
         $verify_result = $alipayNotify->verifyReturn($log);
         if ($verify_result) {
             $trade_no = $_GET['trade_no'];
             // Alipay Order Number
             $out_trade_no = $_GET['out_trade_no'];
             // Merchant Order Number
             // Check order ID
             if (is_numeric($out_trade_no)) {
                 if (!empty($this->order_prefix)) {
                     $check = (int) str_replace($this->order_prefix, '', $out_trade_no);
                 } else {
                     $check = (int) $out_trade_no;
                 }
             } else {
                 $check = (int) str_replace($this->order_prefix, '', $out_trade_no);
             }
             if ($order_id != $check) {
                 // We have an invalid $order_id, probably because order_prefix has changed
                 $check = wc_get_order_id_by_order_key($order_key);
                 if ($order_id != $check) {
                     _e("<p><strong>ERROR:</strong>The order ID doesn't match!</p>", 'alipay');
                     return;
                 }
             }
             // Order ID is correct.
             $order = new WC_Order($order_id);
             echo '<ul class="order_details">
                     <li class="alipayNo">' . __('Your Alipay Trade No.: ', 'alipay') . '<strong>' . $trade_no . '</strong></li>
                 </ul>';
             // Update the order according to data carried with the return_url
             $trade_status = $_GET['trade_status'];
             switch ($trade_status) {
                 case 'WAIT_SELLER_SEND_GOODS':
                     $order_needs_updating = in_array($order->status, array('processing', 'completed')) ? false : true;
                     $status = apply_filters('woocommerce_alipay_payment_successful_status', 'processing', $order);
                     if ($order_needs_updating) {
                         // Update order status if IPN has not process the order
                         update_post_meta($order_id, 'Alipay Trade No.', wc_clean($trade_no));
                         $order->update_status($status, __("Payment received, awaiting fulfilment. ", 'alipay'));
                         // Send deliver notification to alipay if the order is vitural and downloadable.
                         $success = $this->send_goods_confirm(wc_clean($trade_no), $order);
                         if (strpos($success, 'error') !== false) {
                             // Failed to update status
                             if ('yes' == $this->debug) {
                                 $message = sprintf(__('ERROR: Failed to send goods automatically for order %d, ', 'alipay'), $order_id);
                                 $message .= $success;
                                 $this->log->add('alipay', $message);
                             }
                         } else {
                             if ($success === true) {
                                 $order->add_order_note(__('Your order has been shipped, awaiting buyer\'s confirmation', 'alipay'));
                             }
                         }
                         // Reduce stock level
                         $order->reduce_order_stock();
                     }
                     break;
                 case 'TRADE_FINISHED':
                 case 'TRADE_SUCCESS':
                     if ($order->status != 'completed' && $order->status != 'processing') {
                         $order->payment_complete();
                     }
                     update_post_meta($order_id, 'Alipay Trade No.', wc_clean($trade_no));
                     break;
                 default:
                     break;
             }
         }
     }
 }
Ejemplo n.º 11
0
    public function wp_head()
    {
        //*** if the site is visited for the first time lets execute geo ip conditions
        $this->init_geo_currency();
        //***
        wp_enqueue_script('jquery');
        wp_enqueue_script('wc-price-slider');
        $currencies = $this->get_currencies();
        ?>
	<script type="text/javascript">
	    var woocs_is_mobile = <?php 
        echo (int) wp_is_mobile();
        ?>
;
	    var woocs_drop_down_view = "<?php 
        echo $this->get_drop_down_view();
        ?>
";
	    var woocs_current_currency = <?php 
        echo json_encode(isset($currencies[$this->current_currency]) ? $currencies[$this->current_currency] : $currencies[$this->default_currency]);
        ?>
;
	    var woocs_default_currency = <?php 
        echo json_encode($currencies[$this->default_currency]);
        ?>
;
	    var woocs_array_of_get = '{}';
	<?php 
        if (!empty($_GET)) {
            ?>
	    <?php 
            //sanitization of $_GET array
            $sanitized_get_array = array();
            foreach ($_GET as $key => $value) {
                $sanitized_get_array[$this->escape($key)] = $this->escape($value);
            }
            ?>
	        woocs_array_of_get = '<?php 
            echo str_replace("'", "", json_encode($sanitized_get_array));
            ?>
';
	<?php 
        }
        ?>

	    woocs_array_no_cents = '<?php 
        echo json_encode($this->no_cents);
        ?>
';

	    var woocs_ajaxurl = "<?php 
        echo admin_url('admin-ajax.php');
        ?>
";
	    var woocs_lang_loading = "<?php 
        _e('loading', 'woocommerce-currency-switcher');
        ?>
";
	    var woocs_shop_is_cached =<?php 
        echo (int) $this->shop_is_cached;
        ?>
;
	</script>
	<?php 
        if ($this->get_drop_down_view() == 'ddslick') {
            wp_enqueue_script('jquery.ddslick.min', WOOCS_LINK . 'js/jquery.ddslick.min.js', array('jquery'));
        }
        if ($this->get_drop_down_view() == 'chosen' or $this->get_drop_down_view() == 'chosen_dark') {
            wp_enqueue_script('chosen-drop-down', WOOCS_LINK . 'js/chosen/chosen.jquery.min.js', array('jquery'));
            wp_enqueue_style('chosen-drop-down', WOOCS_LINK . 'js/chosen/chosen.min.css');
            //dark chosen
            if ($this->get_drop_down_view() == 'chosen_dark') {
                wp_enqueue_style('chosen-drop-down-dark', WOOCS_LINK . 'js/chosen/chosen-dark.css');
            }
        }
        if ($this->get_drop_down_view() == 'wselect') {
            wp_enqueue_script('woocs_wselect', WOOCS_LINK . 'js/wselect/wSelect.min.js', array('jquery'));
            wp_enqueue_style('woocs_wselect', WOOCS_LINK . 'js/wselect/wSelect.css');
        }
        //+++
        wp_enqueue_style('woocommerce-currency-switcher', WOOCS_LINK . 'css/front.css');
        wp_enqueue_script('woocommerce-currency-switcher', WOOCS_LINK . 'js/front.js', array('jquery'));
        //+++
        //trick for refreshing header cart after currency changing - code left just for history
        if (isset($_GET['currency'])) {
            //wp-content\plugins\woocommerce\includes\class-wc-cart.php
            //apply_filters('woocommerce_update_cart_action_cart_updated', true);
            //$this->current_currency = $_GET['currency'];
            //$_POST['update_cart'] = 1;
            //WC_Form_Handler::update_cart_action();
            //private function set_cart_cookies
            //wc_setcookie('woocommerce_items_in_cart', 0, time() - HOUR_IN_SECONDS);
            //wc_setcookie('woocommerce_cart_hash', '', time() - HOUR_IN_SECONDS);
            //do_action('woocommerce_cart_reset', WC()->cart, true);
            //do_action('woocommerce_calculate_totals', WC()->cart);
        }
        //if customer paying pending order from the front
        //checkout/order-pay/1044/?pay_for_order=true&key=order_55b764a4b7990
        if (isset($_GET['pay_for_order']) and is_checkout_pay_page()) {
            if ($_GET['pay_for_order'] == 'true' and isset($_GET['key'])) {
                $order_id = wc_get_order_id_by_order_key($_GET['key']);
                $currency = get_post_meta($order_id, '_order_currency', TRUE);
                $this->current_currency = $currency;
                $this->storage->set_val('woocs_current_currency', $currency);
            }
        }
        //+++
        //if we want to be paid in the basic currency - not multiple mode
        if (!$this->is_multiple_allowed) {
            if (is_checkout() or is_checkout_pay_page()) {
                $this->reset_currency();
            }
        }
        //logic hack for some cases when shipping for example is wrong in
        //non multiple mode but customer doesn work allow pay in user selected currency
        if ($this->is_multiple_allowed) {
            if ((is_checkout() or is_checkout_pay_page()) and $this->bones['reset_in_multiple']) {
                $this->reset_currency();
            }
        }
    }
 /**
  * AJAX 콜백. order key 에 대응해서 해당 order 의 주문 상태를 반환한다.
  *
  * 요구하는 파라미터: $_GET['order_key']
  * JSON 응답:
  *  success:      bool
  *  message:      string  success or 에러 메시지
  *  redirect:     string  리다이렉트 주소
  *  order_id:     int     success=true 이면 order id
  *  order_status: string  success=true 이면 order status 문자열.
  *  (pending|processing|completed)
  *
  * @action wc_ajax_{wskl-payapp-status}
  */
 public static function callback_payapp_status()
 {
     if (!defined('DOING_AJAX') || !defined('WC_DOING_AJAX')) {
         die(-1);
     }
     $order_key = isset($_GET['order_key']) ? sanitize_text_field($_GET['order_key']) : 0;
     $order = wc_get_order(wc_get_order_id_by_order_key($order_key));
     if (!$order) {
         wc_add_notice(__('주문 과정에 문제가 발생했습니다. 다시 시도해 주세요.', 'wskl'), 'error');
         wp_send_json(array('success' => FALSE, 'message' => 'An invalid order key received.', 'redirect' => wc_get_checkout_url()));
         die;
     }
     if ($order->has_status(array('processing', 'completed'))) {
         $redirect = $order->get_checkout_order_received_url();
     } else {
         $redirect = '';
     }
     wp_send_json(array('success' => TRUE, 'message' => 'success', 'order_id' => $order->id, 'order_status' => $order->get_status(), 'redirect' => $redirect));
     die;
 }
  
		dynx_pagetype: 'conversionintent',
		dynx_totalvalue: <?php 
    echo WC()->cart->total;
    ?>
		
		};
		</script>
<?php 
} elseif (is_order_received_page()) {
    ?>
<script type="text/javascript">
		var google_tag_params = {
		dynx_itemid: <?php 
    echo "[";
    $order = new WC_Order(wc_get_order_id_by_order_key($_GET['key']));
    $order_total = $order->get_total();
    $items = $order->get_items();
    $order_items = array();
    foreach ((array) $items as $item) {
        array_push($order_items, "'" . $item['product_id'] . "'");
    }
    echo implode(', ', $order_items);
    echo "]";
    ?>
,
		dynx_pagetype: 'conversion',
		dynx_totalvalue: <?php 
    echo $order_total;
    ?>
		
Ejemplo n.º 14
0
    <!-- * WordPress wp_head() ********************************************** -->
    <!-- ******************************************************************** -->
    
    <?php 
wp_head();
?>
</head>

<body <?php 
body_class();
?>
>

<?php 
if (is_wc_endpoint_url('order-received')) {
    $order_id = wc_get_order_id_by_order_key($_GET['key']);
    $order1 = new WC_order($order_id);
    $order_items = array_values($order1->get_items());
    $net_amount = $order_items[0]['line_subtotal'];
    $tax_amount = $order_items[0]['line_subtotal_tax'];
    $product_name = $order_items[0]['name'];
    $product_id = $order_items[0]['product_id'];
    $belboon = $_SESSION['belboon'];
    $url_home = home_url();
    ?>
		<img src="https://www1.belboon.de/adtracking/sale/000021772.gif/oc=<?php 
    echo $order_id;
    ?>
&sale=<?php 
    echo $net_amount;
    ?>
Ejemplo n.º 15
0
    public function wp_head()
    {
        wp_enqueue_script('jquery');
        $currencies = $this->get_currencies();
        ?>
        <script type="text/javascript">
            var woocs_drop_down_view = "<?php 
        echo $this->get_drop_down_view();
        ?>
";
            var woocs_current_currency = <?php 
        echo json_encode(isset($currencies[$this->current_currency]) ? $currencies[$this->current_currency] : $currencies[$this->default_currency]);
        ?>
;
            var woocs_default_currency = <?php 
        echo json_encode($currencies[$this->default_currency]);
        ?>
;
            var woocs_array_of_get = '{}';
        <?php 
        if (!empty($_GET)) {
            ?>
                woocs_array_of_get = '<?php 
            echo json_encode($_GET);
            ?>
';
        <?php 
        }
        ?>

            woocs_array_no_cents = '<?php 
        echo json_encode($this->no_cents);
        ?>
';

            var woocs_ajaxurl = "<?php 
        echo admin_url('admin-ajax.php');
        ?>
";
            var woocs_lang_loading = "<?php 
        _e('loading', 'woocommerce-currency-switcher');
        ?>
";
        </script>
        <?php 
        if ($this->get_drop_down_view() == 'ddslick') {
            wp_enqueue_script('jquery.ddslick.min', WOOCS_LINK . 'js/jquery.ddslick.min.js', array('jquery'));
        }
        if ($this->get_drop_down_view() == 'chosen' or $this->get_drop_down_view() == 'chosen_dark') {
            wp_enqueue_script('chosen-drop-down', WOOCS_LINK . 'js/chosen/chosen.jquery.min.js', array('jquery'));
            wp_enqueue_style('chosen-drop-down', WOOCS_LINK . 'js/chosen/chosen.min.css');
            //dark chosen
            if ($this->get_drop_down_view() == 'chosen_dark') {
                wp_enqueue_style('chosen-drop-down-dark', WOOCS_LINK . 'js/chosen/chosen-dark.css');
            }
        }
        if ($this->get_drop_down_view() == 'wselect') {
            wp_enqueue_script('woocs_wselect', WOOCS_LINK . 'js/wselect/wSelect.min.js', array('jquery'));
            wp_enqueue_style('woocs_wselect', WOOCS_LINK . 'js/wselect/wSelect.css');
        }
        //+++
        wp_enqueue_style('woocommerce-currency-switcher', WOOCS_LINK . 'css/front.css');
        wp_enqueue_script('woocommerce-currency-switcher', WOOCS_LINK . 'js/front.js', array('jquery'));
        //+++
        //trick for refreshing header cart after currency changing - code left just for history
        if (isset($_GET['currency'])) {
            //wp-content\plugins\woocommerce\includes\class-wc-cart.php
            //apply_filters('woocommerce_update_cart_action_cart_updated', true);
            //$this->current_currency = $_GET['currency'];
            //$_POST['update_cart'] = 1;
            //WC_Form_Handler::update_cart_action();
            //private function set_cart_cookies
            //wc_setcookie('woocommerce_items_in_cart', 0, time() - HOUR_IN_SECONDS);
            //wc_setcookie('woocommerce_cart_hash', '', time() - HOUR_IN_SECONDS);
            //do_action('woocommerce_cart_reset', WC()->cart, true);
            //do_action('woocommerce_calculate_totals', WC()->cart);
        }
        //if customer paying pending order from the front
        //checkout/order-pay/1044/?pay_for_order=true&key=order_55b764a4b7990
        if (isset($_GET['pay_for_order']) and is_checkout_pay_page()) {
            if ($_GET['pay_for_order'] == 'true' and isset($_GET['key'])) {
                $order_id = wc_get_order_id_by_order_key($_GET['key']);
                $currency = get_post_meta($order_id, '_order_currency', TRUE);
                $this->current_currency = $currency;
                $this->storage->set_val('woocs_current_currency', $currency);
            }
        }
        //+++
        //if we want to be paid in the basic currency - not multiple mode
        if (!$this->is_multiple_allowed) {
            if (is_checkout() or is_checkout_pay_page()) {
                $this->reset_currency();
            }
        }
    }
Ejemplo n.º 16
0
 /**
  * Validate the order details
  */
 function get_mlepay_order($payload)
 {
     if (is_numeric($payload)) {
         $order_id = (int) $payload;
         $order_key = $payload;
     } elseif (is_string($payload)) {
         $order_id = (int) $payload;
         $order_key = $payload;
     } else {
         list($order_id) = $payload;
     }
     $order = new WC_Order($order_id);
     if (!isset($order->id)) {
         $order_id = wc_get_order_id_by_order_key($order_key);
         $order = new WC_Order($order_id);
     }
     return $order;
 }
 /**
  * Process a PayPal Standard Subscription IPN request
  *
  * @param array $transaction_details Post data after wp_unslash
  * @since 2.0
  */
 protected function process_ipn_request($transaction_details)
 {
     // Get the subscription ID and order_key with backward compatibility
     $subscription_id_and_key = self::get_order_id_and_key($transaction_details, 'shop_subscription');
     $subscription = wcs_get_subscription($subscription_id_and_key['order_id']);
     $subscription_key = $subscription_id_and_key['order_key'];
     // We have an invalid $subscription, probably because invoice_prefix has changed since the subscription was first created, so get the subscription by order key
     if (!isset($subscription->id)) {
         $subscription = wcs_get_subscription(wc_get_order_id_by_order_key($subscription_key));
     }
     if ('recurring_payment_suspended_due_to_max_failed_payment' == $transaction_details['txn_type'] && empty($subscription)) {
         WC_Gateway_Paypal::log('Returning as "recurring_payment_suspended_due_to_max_failed_payment" transaction is for a subscription created with Express Checkout');
         return;
     }
     if (empty($subscription)) {
         WC_Gateway_Paypal::log('Subscription IPN Error: Could not find matching Subscription.');
         exit;
     }
     if ($subscription->order_key != $subscription_key) {
         WC_Gateway_Paypal::log('Subscription IPN Error: Subscription Key does not match invoice.');
         exit;
     }
     if (isset($transaction_details['ipn_track_id'])) {
         // Make sure the IPN request has not already been handled
         $handled_ipn_requests = get_post_meta($subscription->id, '_paypal_ipn_tracking_ids', true);
         if (empty($handled_ipn_requests)) {
             $handled_ipn_requests = array();
         }
         // The 'ipn_track_id' is not a unique ID and is shared between different transaction types, so create a unique ID by prepending the transaction type
         $ipn_id = $transaction_details['txn_type'] . '_' . $transaction_details['ipn_track_id'];
         if (in_array($ipn_id, $handled_ipn_requests)) {
             WC_Gateway_Paypal::log('Subscription IPN Error: IPN ' . $ipn_id . ' message has already been correctly handled.');
             exit;
         }
         // Make sure we're not in the process of handling this IPN request on a server under extreme load and therefore, taking more than a minute to process it (which is the amount of time PayPal allows before resending the IPN request)
         $ipn_lock_transient_name = 'wcs_pp_' . $ipn_id;
         // transient names need to be less than 45 characters and the $ipn_id will be around 30 characters, e.g. subscr_payment_5ab4c38e1f39d
         if ('in-progress' == get_transient($ipn_lock_transient_name) && 'recurring_payment_suspended_due_to_max_failed_payment' !== $transaction_details['txn_type']) {
             WC_Gateway_Paypal::log('Subscription IPN Error: an older IPN request with ID ' . $ipn_id . ' is still in progress.');
             // We need to send an error code to make sure PayPal does retry the IPN after our lock expires, in case something is actually going wrong and the server isn't just taking a long time to process the request
             status_header(503);
             exit;
         }
         // Set a transient to block IPNs with this transaction ID for the next 5 minutes
         set_transient($ipn_lock_transient_name, 'in-progress', apply_filters('woocommerce_subscriptions_paypal_ipn_request_lock_time', 5 * MINUTE_IN_SECONDS));
     }
     if (isset($transaction_details['txn_id'])) {
         // Make sure the IPN request has not already been handled
         $handled_transactions = get_post_meta($subscription->id, '_paypal_transaction_ids', true);
         if (empty($handled_transactions)) {
             $handled_transactions = array();
         }
         $transaction_id = $transaction_details['txn_id'];
         if (isset($transaction_details['txn_type'])) {
             $transaction_id .= '_' . $transaction_details['txn_type'];
         }
         // The same transaction ID is used for different payment statuses, so make sure we handle it only once. See: http://stackoverflow.com/questions/9240235/paypal-ipn-unique-identifier
         if (isset($transaction_details['payment_status'])) {
             $transaction_id .= '_' . $transaction_details['payment_status'];
         }
         if (in_array($transaction_id, $handled_transactions)) {
             WC_Gateway_Paypal::log('Subscription IPN Error: transaction ' . $transaction_id . ' has already been correctly handled.');
             exit;
         }
     }
     WC_Gateway_Paypal::log('Subscription transaction details: ' . print_r($transaction_details, true));
     WC_Gateway_Paypal::log('Subscription Transaction Type: ' . $transaction_details['txn_type']);
     $is_renewal_sign_up_after_failure = false;
     // If the invoice ID doesn't match the default invoice ID and contains the string '-wcsfrp-', the IPN is for a subscription payment to fix up a failed payment
     if (in_array($transaction_details['txn_type'], array('subscr_signup', 'subscr_payment')) && false !== strpos($transaction_details['invoice'], '-wcsfrp-')) {
         $renewal_order = wc_get_order(substr($transaction_details['invoice'], strrpos($transaction_details['invoice'], '-') + 1));
         // check if the failed signup has been previously recorded
         if ($renewal_order->id != get_post_meta($subscription->id, '_paypal_failed_sign_up_recorded', true)) {
             $is_renewal_sign_up_after_failure = true;
         }
     }
     // If the invoice ID doesn't match the default invoice ID and contains the string '-wcscpm-', the IPN is for a subscription payment method change
     if ('subscr_signup' == $transaction_details['txn_type'] && false !== strpos($transaction_details['invoice'], '-wcscpm-')) {
         $is_payment_change = true;
     } else {
         $is_payment_change = false;
     }
     // Ignore IPN messages when the payment method isn't PayPal
     if ('paypal' != $subscription->payment_method) {
         // The 'recurring_payment_suspended' transaction is actually an Express Checkout transaction type, but PayPal also send it for PayPal Standard Subscriptions suspended by admins at PayPal, so we need to handle it *if* the subscription has PayPal as the payment method, or leave it if the subscription is using a different payment method (because it might be using PayPal Express Checkout or PayPal Digital Goods)
         if ('recurring_payment_suspended' == $transaction_details['txn_type']) {
             WC_Gateway_Paypal::log('"recurring_payment_suspended" IPN ignored: recurring payment method is not "PayPal". Returning to allow another extension to process the IPN, like PayPal Digital Goods.');
             return;
         } elseif (false === $is_renewal_sign_up_after_failure && false === $is_payment_change) {
             WC_Gateway_Paypal::log('IPN ignored, recurring payment method has changed.');
             exit;
         }
     }
     if ($is_renewal_sign_up_after_failure || $is_payment_change) {
         // Store the old profile ID on the order (for the first IPN message that comes through)
         $existing_profile_id = wcs_get_paypal_id($subscription);
         if (empty($existing_profile_id) || $existing_profile_id !== $transaction_details['subscr_id']) {
             update_post_meta($subscription->id, '_old_paypal_subscriber_id', $existing_profile_id);
             update_post_meta($subscription->id, '_old_payment_method', $subscription->payment_method);
         }
     }
     // Save the profile ID if it's not a cancellation/expiration request
     if (isset($transaction_details['subscr_id']) && !in_array($transaction_details['txn_type'], array('subscr_cancel', 'subscr_eot'))) {
         wcs_set_paypal_id($subscription, $transaction_details['subscr_id']);
         if (wcs_is_paypal_profile_a($transaction_details['subscr_id'], 'out_of_date_id') && 'disabled' != get_option('wcs_paypal_invalid_profile_id')) {
             update_option('wcs_paypal_invalid_profile_id', 'yes');
         }
     }
     $is_first_payment = $subscription->get_completed_payment_count() < 1 ? true : false;
     if ($subscription->has_status('switched')) {
         WC_Gateway_Paypal::log('IPN ignored, subscription has been switched.');
         exit;
     }
     switch ($transaction_details['txn_type']) {
         case 'subscr_signup':
             // Store PayPal Details on Subscription and Order
             $this->save_paypal_meta_data($subscription, $transaction_details);
             $this->save_paypal_meta_data($subscription->order, $transaction_details);
             // When there is a free trial & no initial payment amount, we need to mark the order as paid and activate the subscription
             if (!$is_payment_change && !$is_renewal_sign_up_after_failure && 0 == $subscription->order->get_total()) {
                 // Safe to assume the subscription has an order here because otherwise we wouldn't get a 'subscr_signup' IPN
                 $subscription->order->payment_complete();
                 // No 'txn_id' value for 'subscr_signup' IPN messages
                 update_post_meta($subscription->id, '_paypal_first_ipn_ignored_for_pdt', 'true');
             }
             // Payment completed
             if ($is_payment_change) {
                 // Set PayPal as the new payment method
                 WC_Subscriptions_Change_Payment_Gateway::update_payment_method($subscription, 'paypal');
                 // We need to cancel the subscription now that the method has been changed successfully
                 if ('paypal' == get_post_meta($subscription->id, '_old_payment_method', true)) {
                     self::cancel_subscription($subscription, get_post_meta($subscription->id, '_old_paypal_subscriber_id', true));
                 }
                 $subscription->add_order_note(_x('IPN subscription payment method changed to PayPal.', 'when it is a payment change, and there is a subscr_signup message, this will be a confirmation message that PayPal accepted it being the new payment method', 'woocommerce-subscriptions'));
             } else {
                 $subscription->add_order_note(__('IPN subscription sign up completed.', 'woocommerce-subscriptions'));
             }
             if ($is_payment_change) {
                 WC_Gateway_Paypal::log('IPN subscription payment method changed for subscription ' . $subscription->id);
             } else {
                 WC_Gateway_Paypal::log('IPN subscription sign up completed for subscription ' . $subscription->id);
             }
             break;
         case 'subscr_payment':
             if (!$is_first_payment && !$is_renewal_sign_up_after_failure) {
                 if ($subscription->has_status('active')) {
                     remove_action('woocommerce_subscription_on-hold_paypal', 'WCS_PayPal_Status_Manager::suspend_subscription');
                     $subscription->update_status('on-hold');
                     add_action('woocommerce_subscription_on-hold_paypal', 'WCS_PayPal_Status_Manager::suspend_subscription');
                 }
                 // Generate a renewal order to record the payment (and determine how much is due)
                 $renewal_order = wcs_create_renewal_order($subscription);
                 // Set PayPal as the payment method (we can't use $renewal_order->set_payment_method() here as it requires an object we don't have)
                 $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
                 $renewal_order->set_payment_method($available_gateways['paypal']);
             }
             if ('completed' == strtolower($transaction_details['payment_status'])) {
                 // Store PayPal Details
                 $this->save_paypal_meta_data($subscription, $transaction_details);
                 // Subscription Payment completed
                 $subscription->add_order_note(__('IPN subscription payment completed.', 'woocommerce-subscriptions'));
                 WC_Gateway_Paypal::log('IPN subscription payment completed for subscription ' . $subscription->id);
                 // First payment on order, process payment & activate subscription
                 if ($is_first_payment) {
                     $subscription->order->payment_complete($transaction_details['txn_id']);
                     // Store PayPal Details on Order
                     $this->save_paypal_meta_data($subscription->order, $transaction_details);
                     // IPN got here first or PDT will never arrive. Normally PDT would have arrived, so the first IPN would not be the first payment. In case the the first payment is an IPN, we need to make sure to not ignore the second one
                     update_post_meta($subscription->id, '_paypal_first_ipn_ignored_for_pdt', 'true');
                     // Ignore the first IPN message if the PDT should have handled it (if it didn't handle it, it will have been dealt with as first payment), but set a flag to make sure we only ignore it once
                 } elseif ($subscription->get_completed_payment_count() == 1 && '' !== WCS_PayPal::get_option('identity_token') && 'true' != get_post_meta($subscription->id, '_paypal_first_ipn_ignored_for_pdt', true) && false === $is_renewal_sign_up_after_failure) {
                     WC_Gateway_Paypal::log('IPN subscription payment ignored for subscription ' . $subscription->id . ' due to PDT previously handling the payment.');
                     update_post_meta($subscription->id, '_paypal_first_ipn_ignored_for_pdt', 'true');
                     // Process the payment if the subscription is active
                 } elseif (!$subscription->has_status(array('cancelled', 'expired', 'switched', 'trash'))) {
                     if (true === $is_renewal_sign_up_after_failure && is_object($renewal_order)) {
                         update_post_meta($subscription->id, '_paypal_failed_sign_up_recorded', $renewal_order->id);
                         // We need to cancel the old subscription now that the method has been changed successfully
                         if ('paypal' == get_post_meta($subscription->id, '_old_payment_method', true)) {
                             $profile_id = get_post_meta($subscription->id, '_old_paypal_subscriber_id', true);
                             // Make sure we don't cancel the current profile
                             if ($profile_id !== $transaction_details['subscr_id']) {
                                 self::cancel_subscription($subscription, $profile_id);
                             }
                             $subscription->add_order_note(__('IPN subscription failing payment method changed.', 'woocommerce-subscriptions'));
                         }
                     }
                     try {
                         // to cover the case when PayPal drank too much coffee and sent IPNs early - needs to happen before $renewal_order->payment_complete
                         $update_dates = array();
                         if ($subscription->get_time('trial_end') > gmdate('U')) {
                             $update_dates['trial_end'] = gmdate('Y-m-d H:i:s', gmdate('U') - 1);
                             WC_Gateway_Paypal::log(sprintf('IPN subscription payment for subscription %d: trial_end is in futute (date: %s) setting to %s.', $subscription->id, $subscription->get_date('trial_end'), $update_dates['trial_end']));
                         } else {
                             WC_Gateway_Paypal::log(sprintf('IPN subscription payment for subscription %d: trial_end is in past (date: %s).', $subscription->id, $subscription->get_date('trial_end')));
                         }
                         if ($subscription->get_time('next_payment') > gmdate('U')) {
                             $update_dates['next_payment'] = gmdate('Y-m-d H:i:s', gmdate('U') - 1);
                             WC_Gateway_Paypal::log(sprintf('IPN subscription payment for subscription %d: next_payment is in future (date: %s) setting to %s.', $subscription->id, $subscription->get_date('next_payment'), $update_dates['next_payment']));
                         } else {
                             WC_Gateway_Paypal::log(sprintf('IPN subscription payment for subscription %d: next_payment is in past (date: %s).', $subscription->id, $subscription->get_date('next_payment')));
                         }
                         if (!empty($update_dates)) {
                             $subscription->update_dates($update_dates);
                         }
                     } catch (Exception $e) {
                         WC_Gateway_Paypal::log(sprintf('IPN subscription payment exception subscription %d: %s.', $subscription->id, $e->getMessage()));
                     }
                     remove_action('woocommerce_subscription_activated_paypal', 'WCS_PayPal_Status_Manager::reactivate_subscription');
                     try {
                         $renewal_order->payment_complete($transaction_details['txn_id']);
                     } catch (Exception $e) {
                         WC_Gateway_Paypal::log(sprintf('IPN subscription payment exception calling $renewal_order->payment_complete() for subscription %d: %s.', $subscription->id, $e->getMessage()));
                     }
                     $renewal_order->add_order_note(__('IPN subscription payment completed.', 'woocommerce-subscriptions'));
                     add_action('woocommerce_subscription_activated_paypal', 'WCS_PayPal_Status_Manager::reactivate_subscription');
                     wcs_set_paypal_id($renewal_order, $transaction_details['subscr_id']);
                 }
             } elseif (in_array(strtolower($transaction_details['payment_status']), array('pending', 'failed'))) {
                 // Subscription Payment completed
                 // translators: placeholder is payment status (e.g. "completed")
                 $subscription->add_order_note(sprintf(_x('IPN subscription payment %s.', 'used in order note', 'woocommerce-subscriptions'), $transaction_details['payment_status']));
                 if (!$is_first_payment) {
                     update_post_meta($renewal_order->id, '_transaction_id', $transaction_details['txn_id']);
                     // translators: placeholder is payment status (e.g. "completed")
                     $renewal_order->add_order_note(sprintf(_x('IPN subscription payment %s.', 'used in order note', 'woocommerce-subscriptions'), $transaction_details['payment_status']));
                     $subscription->payment_failed();
                 }
                 WC_Gateway_Paypal::log('IPN subscription payment failed for subscription ' . $subscription->id);
             } else {
                 WC_Gateway_Paypal::log('IPN subscription payment notification received for subscription ' . $subscription->id . ' with status ' . $transaction_details['payment_status']);
             }
             break;
             // Admins can suspend subscription at PayPal triggering this IPN
         // Admins can suspend subscription at PayPal triggering this IPN
         case 'recurring_payment_suspended':
             if ($subscription->has_status('active')) {
                 // We don't need to suspend the subscription at PayPal because it's already on-hold there
                 remove_action('woocommerce_subscription_on-hold_paypal', 'WCS_PayPal_Status_Manager::suspend_subscription');
                 $subscription->update_status('on-hold', __('IPN subscription suspended.', 'woocommerce-subscriptions'));
                 add_action('woocommerce_subscription_on-hold_paypal', 'WCS_PayPal_Status_Manager::suspend_subscription');
                 WC_Gateway_Paypal::log('IPN subscription suspended for subscription ' . $subscription->id);
             } else {
                 WC_Gateway_Paypal::log(sprintf('IPN "recurring_payment_suspended" ignored for subscription %d. Subscription already %s.', $subscription->id, $subscription->get_status()));
             }
             break;
         case 'subscr_cancel':
             // Make sure the subscription hasn't been linked to a new payment method
             if (wcs_get_paypal_id($subscription) != $transaction_details['subscr_id']) {
                 WC_Gateway_Paypal::log('IPN subscription cancellation request ignored - new PayPal Profile ID linked to this subscription, for subscription ' . $subscription->id);
             } else {
                 $subscription->cancel_order(__('IPN subscription cancelled.', 'woocommerce-subscriptions'));
                 WC_Gateway_Paypal::log('IPN subscription cancelled for subscription ' . $subscription->id);
             }
             break;
         case 'subscr_eot':
             // Subscription ended, either due to failed payments or expiration
             WC_Gateway_Paypal::log('IPN EOT request ignored for subscription ' . $subscription->id);
             break;
         case 'subscr_failed':
             // Subscription sign up failed
         // Subscription sign up failed
         case 'recurring_payment_suspended_due_to_max_failed_payment':
             // Recurring payment failed
             $ipn_failure_note = __('IPN subscription payment failure.', 'woocommerce-subscriptions');
             if (!$is_first_payment && !$is_renewal_sign_up_after_failure && $subscription->has_status('active')) {
                 // Generate a renewal order to record the failed payment
                 $renewal_order = wcs_create_renewal_order($subscription);
                 // Set PayPal as the payment method
                 $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
                 $renewal_order->set_payment_method($available_gateways['paypal']);
                 $renewal_order->add_order_note($ipn_failure_note);
             }
             WC_Gateway_Paypal::log('IPN subscription payment failure for subscription ' . $subscription->id);
             // Subscription Payment completed
             $subscription->add_order_note($ipn_failure_note);
             try {
                 $subscription->payment_failed();
             } catch (Exception $e) {
                 WC_Gateway_Paypal::log(sprintf('IPN subscription payment failure, unable to process payment failure. Exception: %s ', $e->getMessage()));
             }
             break;
     }
     // Store the transaction IDs to avoid handling requests duplicated by PayPal
     if (isset($transaction_details['ipn_track_id'])) {
         $handled_ipn_requests[] = $ipn_id;
         update_post_meta($subscription->id, '_paypal_ipn_tracking_ids', $handled_ipn_requests);
     }
     if (isset($transaction_details['txn_id'])) {
         $handled_transactions[] = $transaction_id;
         update_post_meta($subscription->id, '_paypal_transaction_ids', $handled_transactions);
     }
     // And delete the transient that's preventing other IPN's being processed
     if (isset($ipn_lock_transient_name)) {
         delete_transient($ipn_lock_transient_name);
     }
     // Log completion
     $log_message = 'IPN subscription request processed for ' . $subscription->id;
     if (isset($ipn_id) && !empty($ipn_id)) {
         $log_message .= sprintf(' (%s)', $ipn_id);
     }
     WC_Gateway_Paypal::log($log_message);
     // Prevent default IPN handling for subscription txn_types
     exit;
 }
Ejemplo n.º 18
-1
function get_order_item_totals1( $tax_display = '' ) {
	if(is_wc_endpoint_url( 'order-received' ))
	{
		
		$order_id=wc_get_order_id_by_order_key( $_GET['key']);
		$order=new WC_Order($order_id);
		/*echo '<pre>';
		print_r($order);
		echo '</pre>';*/
		$coupons=$order->get_used_coupons();
		$coupon_code=$coupons[0];
		$coupon_data=new WC_Coupon($coupon_code);
		$discount = get_post_meta($coupon_data->id,'coupon_amount',true);
		$type = get_post_meta($coupon_data->id,'discount_type',true);
		
		if($type=='percent'){
			$coupon_label=$discount.'&#37; Rabatt';
		}
		else{
			$coupon_label='Rabatt';
		}
		if ( ! $tax_display ) {
			$tax_display = $order->tax_display_cart;
		}
		
		
		if ( 'itemized' == get_option( 'woocommerce_tax_total_display' ) ) {
			
			
			foreach ( $order->get_tax_totals() as $code => $tax ) {
				$tax->rate = WC_Tax::get_rate_percent( $tax->rate_id );
				
				if ( ! isset( $tax_array[ 'tax_rate'] ) )
					$tax_array[ 'tax_rate' ] = array( 'tax' => $tax, 'amount' => $tax->amount, 'contains' => array( $tax ) );
				else {
					array_push( $tax_array[ 'tax_rate' ][ 'contains' ], $tax );
					$tax_array[ 'tax_rate' ][ 'amount' ] += $tax->amount;
				}
			}
			if(isset($tax_array['tax_rate']['tax']->rate))
			$tax_label='<span class="include_tax">(inkl.&nbsp;'.$tax_array['tax_rate']['tax']->rate.'&nbsp;'.$tax_array['tax_rate']['tax']->label.')</span>';
		}
			
		$total_rows = array();
		
		$shippingcost='0 '.get_woocommerce_currency_symbol();
		
		if ( $order->get_total_discount() > 0 ) {
			$total_rows['discount'] = array(
				'label' => __( $coupon_label, 'woocommerce' ),
				'value'	=> '-' . $order->get_discount_to_display( $tax_display )
			);
		}

		
			$total_rows['shipping'] = array(
				'label' => __( 'Versandkosten', 'woocommerce' ),
				'value'	=>$shippingcost
			);
		

		$total_rows['order_total'] = array(
			'label' => __( 'Gesamtsumme '.$tax_label, 'woocommerce' ),
			'value'	=> $order->get_formatted_order_total( $tax_display )
		);

		return $total_rows;
	}
}