needs_payment() 공개 메소드

Checks if an order needs payment, based on status and order total.
public needs_payment ( ) : boolean
리턴 boolean
 public function WX_Loop_Order_Status()
 {
     //ajax loop
     Log::DEBUG(' start loop !');
     $order_id = $_GET['orderId'];
     $order = new WC_Order($order_id);
     $isPaid = !$order->needs_payment();
     Log::DEBUG(" check_wechatpay_response orderid:" . $order_id . "is need pay:" . $isPaid);
     if ($isPaid) {
         $returnUrl = urldecode($this->get_return_url($order));
         echo json_encode(array('status' => 'paid', 'message' => $returnUrl));
     } else {
         echo json_encode(array('status' => 'nPaid', 'message' => 'nPaid'));
     }
     die('');
 }
예제 #2
0
 /**
  * @param WC_Order $order
  * @return bool
  */
 protected function orderNeedsPayment(WC_Order $order)
 {
     if ($order->needs_payment()) {
         return true;
     }
     // Has initial order status 'on-hold'
     if ($this->getInitialOrderStatus() === self::STATUS_ON_HOLD && Mollie_WC_Plugin::getDataHelper()->hasOrderStatus($order, self::STATUS_ON_HOLD)) {
         return true;
     }
     return false;
 }
예제 #3
0
 /**
  * Test: needs_payment
  */
 function test_needs_payment()
 {
     $object = new WC_Order();
     $object->set_status('pending');
     $this->assertFalse($object->needs_payment());
     $object->set_total(100);
     $this->assertTrue($object->needs_payment());
     $object->set_status('processing');
     $this->assertFalse($object->needs_payment());
 }
 /**
  * Process the pay form.
  */
 public function pay_action()
 {
     global $wp;
     if (isset($_POST['woocommerce_pay']) && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-pay')) {
         ob_start();
         // Pay for existing order
         $order_key = $_GET['key'];
         $order_id = absint($wp->query_vars['order-pay']);
         $order = new WC_Order($order_id);
         if ($order->id == $order_id && $order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) {
             // Set customer location to order location
             if ($order->billing_country) {
                 WC()->customer->set_country($order->billing_country);
             }
             if ($order->billing_state) {
                 WC()->customer->set_state($order->billing_state);
             }
             if ($order->billing_postcode) {
                 WC()->customer->set_postcode($order->billing_postcode);
             }
             if ($order->billing_city) {
                 WC()->customer->set_city($order->billing_city);
             }
             // Update payment method
             if ($order->needs_payment()) {
                 $payment_method = wc_clean($_POST['payment_method']);
                 $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
                 // Update meta
                 update_post_meta($order_id, '_payment_method', $payment_method);
                 if (isset($available_gateways[$payment_method])) {
                     $payment_method_title = $available_gateways[$payment_method]->get_title();
                 }
                 update_post_meta($order_id, '_payment_method_title', $payment_method_title);
                 // Validate
                 $available_gateways[$payment_method]->validate_fields();
                 // Process
                 if (wc_notice_count('error') == 0) {
                     $result = $available_gateways[$payment_method]->process_payment($order_id);
                     // Redirect to success/confirmation/payment page
                     if ('success' == $result['result']) {
                         wp_redirect($result['redirect']);
                         exit;
                     }
                 }
             } else {
                 // No payment was required for order
                 $order->payment_complete();
                 wp_safe_redirect($order->get_checkout_order_received_url());
                 exit;
             }
         }
     }
 }
 /**
  * Checks if the subscription has an unpaid order or renewal order (and therefore, needs payment).
  *
  * @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
  * @param int $user_id The ID of the user who owns the subscriptions. Although this parameter is optional, if you have the User ID you should pass it to improve performance.
  * @return bool True if the subscription has an unpaid renewal order, false if the subscription has no unpaid renewal orders.
  * @since 2.0
  */
 public function needs_payment()
 {
     $needs_payment = false;
     // First check if the subscription is pending or failed or is for $0
     if (parent::needs_payment()) {
         $needs_payment = true;
         // Now make sure the parent order doesn't need payment
     } elseif (false !== $this->order && ($this->order->needs_payment() || $this->order->has_status('on-hold'))) {
         $needs_payment = true;
         // And finally, check that the last renewal order doesn't need payment
     } else {
         $last_renewal_order_id = get_posts(array('posts_per_page' => 1, 'post_type' => 'shop_order', 'post_status' => 'any', 'fields' => 'ids', 'orderby' => 'ID', 'order' => 'DESC', 'meta_query' => array(array('key' => '_subscription_renewal', 'compare' => '=', 'value' => $this->id, 'type' => 'numeric'))));
         if (!empty($last_renewal_order_id)) {
             $renewal_order = new WC_Order($last_renewal_order_id[0]);
             if ($renewal_order->needs_payment() || $renewal_order->has_status(array('on-hold', 'failed', 'cancelled'))) {
                 $needs_payment = true;
             }
         }
     }
     return apply_filters('woocommerce_subscription_needs_payment', $needs_payment, $this);
 }
 /**
  * Validate a transaction response.
  *
  * @since 4.3.0
  * @param \WC_Order $order the order object
  * @param \SV_WC_Payment_Gateway_API_Payment_Notification_Response the response object
  * @throws \SV_WC_Payment_Gateway_Exception
  */
 protected function validate_transaction_response($order, $response)
 {
     // If the order is invalid, bail
     if (!$order || !$order->id) {
         throw new SV_WC_Payment_Gateway_Exception(sprintf(__('Could not find order %s', 'woocommerce-plugin-framework'), $response->get_order_id()));
     }
     // If the order has already been completed, bail
     if (!$order->needs_payment()) {
         /* translators: Placeholders: %s - payment gateway title (such as Authorize.net, Braintree, etc) */
         $order->add_order_note(sprintf(esc_html__('%s duplicate transaction received', 'woocommerce-plugin-framework'), $this->get_method_title()));
         throw new SV_WC_Payment_Gateway_Exception(sprintf(__('Order %s is already paid for.', 'woocommerce-plugin-framework'), $order->get_order_number()));
     }
 }
예제 #7
0
/**
 * Process the pay form.
 *
 * @access public
 * @return void
 */
function woocommerce_pay_action()
{
    global $woocommerce;
    if (isset($_POST['woocommerce_pay']) && $woocommerce->verify_nonce('pay')) {
        ob_start();
        // Pay for existing order
        $order_key = urldecode($_GET['order']);
        $order_id = absint($_GET['order_id']);
        $order = new WC_Order($order_id);
        if ($order->id == $order_id && $order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) {
            // Set customer location to order location
            if ($order->billing_country) {
                $woocommerce->customer->set_country($order->billing_country);
            }
            if ($order->billing_state) {
                $woocommerce->customer->set_state($order->billing_state);
            }
            if ($order->billing_postcode) {
                $woocommerce->customer->set_postcode($order->billing_postcode);
            }
            if ($order->billing_city) {
                $woocommerce->customer->set_city($order->billing_city);
            }
            // Update payment method
            if ($order->needs_payment()) {
                $payment_method = woocommerce_clean($_POST['payment_method']);
                $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
                // Update meta
                update_post_meta($order_id, '_payment_method', $payment_method);
                if (isset($available_gateways[$payment_method])) {
                    $payment_method_title = $available_gateways[$payment_method]->get_title();
                }
                update_post_meta($order_id, '_payment_method_title', $payment_method_title);
                // Validate
                $available_gateways[$payment_method]->validate_fields();
                // Process
                if ($woocommerce->error_count() == 0) {
                    $result = $available_gateways[$payment_method]->process_payment($order_id);
                    // Redirect to success/confirmation/payment page
                    if ($result['result'] == 'success') {
                        wp_redirect($result['redirect']);
                        exit;
                    }
                }
            } else {
                // No payment was required for order
                $order->payment_complete();
                wp_safe_redirect(get_permalink(woocommerce_get_page_id('thanks')));
                exit;
            }
        }
    }
}