Пример #1
0
 /**
  * Test wc_empty_cart().
  *
  * @since 2.3.0
  */
 public function test_wc_empty_cart()
 {
     // Create dummy product
     $product = WC_Helper_Product::create_simple_product();
     // Add the product to the cart
     WC()->cart->add_to_cart($product->id, 1);
     // Empty the cart
     wc_empty_cart();
     // Check if the cart is empty
     $this->assertEquals(0, WC()->cart->get_cart_contents_count());
     // Delete the previously created product
     WC_Helper_Product::delete_product($product->id);
 }
 /**
  * Destroy all session data.
  */
 public function destroy_session()
 {
     // Clear cookie
     wc_setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, apply_filters('wc_session_use_secure_cookie', false));
     $this->delete_session($this->_customer_id);
     // Clear cart
     wc_empty_cart();
     // Clear data
     $this->_data = array();
     $this->_dirty = false;
     $this->_customer_id = $this->generate_customer_id();
 }
 /**
  * Verify a successful Payment!
  **/
 function check_voguepay_response($posted)
 {
     if (isset($_POST['transaction_id'])) {
         $transaction_id = $_POST['transaction_id'];
         $args = array('sslverify' => false);
         if ('demo' == $this->voguePayMerchantId) {
             $json = wp_remote_get('https://voguepay.com/?v_transaction_id=' . $transaction_id . '&type=json&demo=true', $args);
         } else {
             $json = wp_remote_get('https://voguepay.com/?v_transaction_id=' . $transaction_id . '&type=json', $args);
         }
         $transaction = json_decode($json['body'], true);
         $transaction_id = $transaction['transaction_id'];
         $order_id = $transaction['merchant_ref'];
         $order_id = (int) $order_id;
         $order = wc_get_order($order_id);
         $order_total = $order->get_total();
         $amount_paid = $transaction['total'];
         //after payment hook
         do_action('tbz_wc_voguepay_after_payment', $transaction);
         if ($transaction['status'] == 'Approved') {
             if ($transaction['merchant_id'] != $this->voguePayMerchantId) {
                 //Update the order status
                 $order->update_status('on-hold', '');
                 //Error Note
                 $message = 'Thank you for shopping with us.<br />Your payment transaction was successful, but the amount was paid to the wrong merchant account. Illegal hack attempt.<br />Your order is currently on-hold.<br />Kindly contact us for more information regarding your order and payment status.';
                 $message_type = 'notice';
                 //Add Customer Order Note
                 $order->add_order_note($message . '<br />Voguepay Transaction ID: ' . $transaction_id, 1);
                 //Add Admin Order Note
                 $order->add_order_note('Look into this order. <br />This order is currently on hold.<br />Reason: Illegal hack attempt. The order was successfull but the money was paid to the wrong Voguepay account.<br /> Your Voguepay Merchant ID ' . $this->voguePayMerchantId . ' the Merchant ID the payment was sent to ' . $transaction['merchant_id'] . '<br />Voguepay Transaction ID: ' . $transaction_id);
                 // Reduce stock levels
                 $order->reduce_order_stock();
                 // Empty cart
                 wc_empty_cart();
             } else {
                 // check if the amount paid is equal to the order amount.
                 if ($order_total != $amount_paid) {
                     //Update the order status
                     $order->update_status('on-hold', '');
                     //Error Note
                     $message = 'Thank you for shopping with us.<br />Your payment transaction was successful, but the amount paid is not the same as the total order amount.<br />Your order is currently on-hold.<br />Kindly contact us for more information regarding your order and payment status.';
                     $message_type = 'notice';
                     //Add Customer Order Note
                     $order->add_order_note($message . '<br />Voguepay Transaction ID: ' . $transaction_id, 1);
                     //Add Admin Order Note
                     $order->add_order_note('Look into this order. <br />This order is currently on hold.<br />Reason: Amount paid is less than the total order amount.<br />Amount Paid was &#8358; ' . $amount_paid . ' while the total order amount is &#8358; ' . $order_total . '<br />Voguepay Transaction ID: ' . $transaction_id);
                     // Reduce stock levels
                     $order->reduce_order_stock();
                     // Empty cart
                     wc_empty_cart();
                 } else {
                     if ($order->status == 'processing') {
                         $order->add_order_note('Payment Via Voguepay<br />Transaction ID: ' . $transaction_id);
                         //Add customer order note
                         $order->add_order_note('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />Voguepay Transaction ID: ' . $transaction_id, 1);
                         // Reduce stock levels
                         $order->reduce_order_stock();
                         // Empty cart
                         wc_empty_cart();
                         $message = 'Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.';
                         $message_type = 'success';
                     } else {
                         if ($order->has_downloadable_item()) {
                             //Update order status
                             $order->update_status('completed', 'Payment received, your order is now complete.');
                             //Add admin order note
                             $order->add_order_note('Payment Via Voguepay Payment Gateway<br />Transaction ID: ' . $transaction_id);
                             //Add customer order note
                             $order->add_order_note('Payment Received.<br />Your order is now complete.<br />Voguepay Transaction ID: ' . $transaction_id, 1);
                             $message = 'Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is now complete.';
                             $message_type = 'success';
                         } else {
                             //Update order status
                             $order->update_status('processing', 'Payment received, your order is currently being processed.');
                             //Add admin order noote
                             $order->add_order_note('Payment Via Voguepay Payment Gateway<br />Transaction ID: ' . $transaction_id);
                             //Add customer order note
                             $order->add_order_note('Payment Received.<br />Your order is currently being processed.<br />We will be shipping your order to you soon.<br />Voguepay Transaction ID: ' . $transaction_id, 1);
                             $message = 'Thank you for shopping with us.<br />Your transaction was successful, payment was received.<br />Your order is currently being processed.';
                             $message_type = 'success';
                         }
                         // Reduce stock levels
                         $order->reduce_order_stock();
                         // Empty cart
                         wc_empty_cart();
                     }
                 }
             }
             $voguepay_message = array('message' => $message, 'message_type' => $message_type);
             if (version_compare(WOOCOMMERCE_VERSION, "2.2") >= 0) {
                 add_post_meta($order_id, '_transaction_id', $transaction_id, true);
             }
             update_post_meta($order_id, '_tbz_voguepay_message', $voguepay_message);
             die('IPN Processed OK. Payment Successfully');
         } else {
             $message = 'Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t received.';
             $message_type = 'error';
             $transaction_id = $transaction['transaction_id'];
             //Add Customer Order Note
             $order->add_order_note($message . '<br />Voguepay Transaction ID: ' . $transaction_id, 1);
             //Add Admin Order Note
             $order->add_order_note($message . '<br />Voguepay Transaction ID: ' . $transaction_id);
             //Update the order status
             $order->update_status('failed', '');
             $voguepay_message = array('message' => $message, 'message_type' => $message_type);
             update_post_meta($order_id, '_tbz_voguepay_message', $voguepay_message);
             if (version_compare(WOOCOMMERCE_VERSION, "2.2") >= 0) {
                 add_post_meta($order_id, '_transaction_id', $transaction_id, true);
             }
             die('IPN Processed OK. Payment Failed');
         }
     } else {
         $message = 'Thank you for shopping with us. <br />However, the transaction wasn\'t successful, payment wasn\'t received.';
         $message_type = 'error';
         $voguepay_message = array('message' => $message, 'message_type' => $message_type);
         update_post_meta($order_id, '_tbz_voguepay_message', $voguepay_message);
         die('IPN Processed OK');
     }
 }
/**
 * @deprecated
 */
function woocommerce_empty_cart()
{
    wc_empty_cart();
}
Пример #5
0
 /**
  * Process an order that doesn't require payment.
  *
  * @since  2.7.0
  * @param  int $order_id
  */
 protected function process_order_without_payment($order_id)
 {
     $order = wc_get_order($order_id);
     $order->payment_complete();
     wc_empty_cart();
     if (is_ajax()) {
         wp_send_json(array('result' => 'success', 'redirect' => apply_filters('woocommerce_checkout_no_payment_needed_redirect', $order->get_checkout_order_received_url(), $order)));
     } else {
         wp_safe_redirect(apply_filters('woocommerce_checkout_no_payment_needed_redirect', $order->get_checkout_order_received_url(), $order));
         exit;
     }
 }
 /**
  * Show the thanks page.
  *
  * @param int $order_id
  */
 private static function order_received($order_id = 0)
 {
     wc_print_notices();
     $order = false;
     // Get the order
     $order_id = apply_filters('woocommerce_thankyou_order_id', absint($order_id));
     $order_key = apply_filters('woocommerce_thankyou_order_key', empty($_GET['key']) ? '' : wc_clean($_GET['key']));
     if ($order_id > 0) {
         $order = wc_get_order($order_id);
         if ($order->order_key != $order_key) {
             $order = false;
         }
     }
     // Empty awaiting payment session
     unset(WC()->session->order_awaiting_payment);
     // Empty current cart
     wc_empty_cart();
     wc_get_template('checkout/thankyou.php', array('order' => $order));
 }
 /**
  * 페이앱이 피드백 URL 에 대응하는 콜백.
  * 피드백 파라미터를 확인하고 올바른 경우에는 최종적으로 주문 내역을 결제된 것으로 업데이트한다.
  *
  * @action woocommerce_api_{wskl-payapp-feedback}
  */
 public static function callback_payapp_feedback()
 {
     error_log('페이앱 피드백 URL 호출됨! 일시 (UTC time): ' . date('Y-m-d H:i:s'));
     $payapp_uid = wskl_POST('userid');
     $link_key = wskl_POST('linkkey');
     $link_val = wskl_POST('linkval');
     $order_id = wskl_POST('var1', 'absint');
     $order_key = wskl_POST('var2', 'sanitize_text_field');
     $cst_url = wskl_POST('csturl', 'sanitize_text_field');
     // 전표 주소
     $pay_memo = wskl_POST('pay_memo', 'sanitize_text_field');
     // 구매자가 기록한 메모
     $mul_no = wskl_POST('mul_no', 'sanitize_text_field');
     // 결제요청번호
     $pay_state = wskl_POST('pay_state', 'absint');
     // 결제요청상태 (1: 요청, 4: 결제완료, 8, 16, 32: 요청취소, 9, 64: 승인취소)
     $pay_type = wskl_POST('pay_type', 'absint');
     // 결제수단 (1: 신용카드, 2: 휴대전화)
     $pay_date = wskl_POST('pay_date', 'sanitize_text_field');
     // check payapp_uid
     if ($payapp_uid != wskl_get_option('payapp_user_id')) {
         error_log(__('페이앱 USER ID 에러', 'wskl'));
         return;
     }
     // check link key and link val
     if ($link_key != wskl_get_option('payapp_link_key') || $link_val != wskl_get_option('payapp_link_val')) {
         error_log(__('페이앱 연동 KEY, 혹은 연동 VALUE가 올바르지 않음', 'wskl'));
         return;
     }
     $order = wc_get_order($order_id);
     if (!$order) {
         error_log(__('잘못된 주문 ID', 'wskl') . ": {$order_id}");
         return;
     }
     // check order key
     if ($order_key != $order->order_key) {
         error_log(__('잘못된 주문 KEY', 'wskl') . ": {$order_key}");
         return;
     }
     // 승인
     if ($pay_state == 4) {
         // 전표 기록
         update_post_meta($order_id, 'wskl_payapp_cst_url', $cst_url);
         switch ($pay_type) {
             case 1:
                 $card_name = wskl_POST('card_name', 'sanitize_text_field');
                 // 신용카드시 카드 이름
                 $order_note = sprintf(__('결제가 성공적으로 처리됨.<ul><li>결제방법: 신용카드</li><li>카드 이름: %s</li><li>페이앱 결제요청번호: %s</li><li>승인시각: %s</li><li>구매자의 결제창 메시지: %s</li></ul>', 'wskl'), $card_name, $mul_no, $pay_date, $pay_memo);
                 break;
             case 2:
                 $order_note = sprintf(__('결제가 성공적으로 처리됨.<ul><li>결제방법: 휴대전화</li><li>페이앱 결제요청번호: %s</li><li>승인시각: %s</li><li>구매자의 결제창 메시지: %s</li></ul>', 'wskl'), $mul_no, $pay_date, $pay_memo);
                 break;
             default:
                 $order_note = sprintf(__('결제가 성공적으로 처리됨.<ul><li>결제방법: 기타</li><li>페이앱 결제요청번호: %s</li><li>승인시각: %s</li><li>구매자의 결제창 메시지: %s</li></ul>', 'wskl'), $mul_no, $pay_date, $pay_memo);
         }
         $order->add_order_note($order_note);
         $order->payment_complete();
         $order->reduce_order_stock();
         wc_empty_cart();
     }
 }