当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Subscriptions_Manager::set_next_payment_date方法代码示例

本文整理汇总了PHP中WC_Subscriptions_Manager::set_next_payment_date方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::set_next_payment_date方法的具体用法?PHP WC_Subscriptions_Manager::set_next_payment_date怎么用?PHP WC_Subscriptions_Manager::set_next_payment_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Subscriptions_Manager的用法示例。


在下文中一共展示了WC_Subscriptions_Manager::set_next_payment_date方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: paymill_webhooks


//.........这里部分代码省略.........
            			
            			*/
            //error_log($sub_cache['woo_user_id']."\n\n".$sub_cache['woo_offer_id']."\n\n", 3, PAYMILL_DIR.'lib/debug/PHP_errors.log');
            $subscription = WC_Subscriptions_Manager::get_subscription($sub_cache['woo_offer_id']);
            // update subscriptions when webhook is triggered
            if (isset($sub_cache['woo_offer_id']) && strlen($sub_cache['woo_offer_id']) > 0) {
                // subscription successfully created
                if ($event_json['event']['event_type'] == 'subscription.created') {
                }
                // tell WooCommerce when payment for subscription is successfully processed
                if ($event_json['event']['event_type'] == 'subscription.succeeded') {
                    /* example data WC_Subscriptions_Manager::get_subscription:
                    				array(15) {
                    				  ["order_id"]=>
                    				  string(3) "201"
                    				  ["product_id"]=>
                    				  string(2) "91"
                    				  ["variation_id"]=>
                    				  string(0) ""
                    				  ["status"]=>
                    				  string(6) "active"
                    				  ["period"]=>
                    				  string(3) "day"
                    				  ["interval"]=>
                    				  string(1) "1"
                    				  ["length"]=>
                    				  string(2) "12"
                    				  ["start_date"]=>
                    				  string(19) "2014-01-12 17:17:10"
                    				  ["expiry_date"]=>
                    				  string(19) "2014-01-24 17:17:10"
                    				  ["end_date"]=>
                    				  string(1) "0"
                    				  ["trial_expiry_date"]=>
                    				  string(1) "0"
                    				  ["failed_payments"]=>
                    				  string(1) "0"
                    				  ["completed_payments"]=>
                    				  array(1) {
                    					[0]=>
                    					string(19) "2014-01-12 17:17:10"
                    				  }
                    				  ["suspension_count"]=>
                    				  string(1) "0"
                    				  ["last_payment_date"]=>
                    				  string(19) "2014-01-12 17:17:10"
                    				}
                    			*/
                    error_log(var_export($subscription, true) . "\n\n", 3, PAYMILL_DIR . 'lib/debug/PHP_errors.log');
                    // prevent multiple subscription renewals because of multiple webhook attempts.
                    $whole_period = 0;
                    switch ($subscription['period']) {
                        case 'day':
                        default:
                            $whole_period = intval($subscription['interval']) * 86400;
                            break;
                        case 'week':
                            $whole_period = intval($subscription['interval']) * 604800;
                            break;
                        case 'month':
                            $whole_period = intval($subscription['interval']) * 2160000;
                            // using 25 days to prevent problems with shorter months
                            break;
                        case 'year':
                            $whole_period = intval($subscription['interval']) * 30240000;
                            // using 350 days to prevent any timezone problems whatsoever
                            break;
                    }
                    if (count($subscription['completed_payments']) >= 1) {
                        if (strtotime(date(DATE_RFC822)) > strtotime($subscription['last_payment_date']) + $whole_period - 18000) {
                            // minus 5 hours to prevent any problems with pending triggers
                            $order = new WC_Order($subscription['order_id']);
                            //WC_Subscriptions_Manager::process_subscription_payments_on_order($order, $subscription['product_id']);
                            WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
                        }
                    } else {
                        $order = new WC_Order($subscription['order_id']);
                        $order->payment_complete();
                        WC_Subscriptions_Manager::activate_subscriptions_for_order($subscription['order_id']);
                    }
                    WC_Subscriptions_Manager::set_next_payment_date($sub_cache['woo_offer_id'], $order->customer_user);
                }
                // cancel subscription, as it was deleted through Paymill dashboard
                if ($event_json['event']['event_type'] == 'subscription.deleted') {
                    $sql = $wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'paymill_subscriptions WHERE woo_user_id=%s AND woo_offer_id=%s', array($sub_cache['woo_user_id'], $sub_cache['woo_offer_id']));
                    $wpdb->query($sql);
                    error_log("\n\n" . $sql . "\n\n", 3, PAYMILL_DIR . 'lib/debug/PHP_errors.log');
                    //WC_Subscriptions_Manager::cancel_subscriptions_for_order( $order );
                    WC_Subscriptions_Manager::cancel_subscription($sub_cache['woo_user_id'], $sub_cache['woo_offer_id']);
                }
                // tell WC that payment failure occured
                if ($event_json['event']['event_type'] == 'subscription.failed') {
                    WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($subscription['order_id'], $subscription['product_id']);
                }
            }
        }
        error_log(date(DATE_RFC822) . ' - Webhook ' . $event_json['event']['event_type'] . ' finished - end processing' . "\n\n", 3, PAYMILL_DIR . 'lib/debug/PHP_errors.log');
        error_log("\n\n########################################################################################################################\n\n", 3, PAYMILL_DIR . 'lib/debug/PHP_errors.log');
    }
}
开发者ID:cyrrill,项目名称:paymill-wordpress,代码行数:101,代码来源:woocommerce.inc.php

示例2: process_paypal_ipn_request


//.........这里部分代码省略.........
                 } else {
                     self::$log->add('paypal', 'IPN subscription sign up completed for order ' . $order_id);
                 }
             }
             break;
         case 'subscr_payment':
             if ('completed' == strtolower($transaction_details['payment_status'])) {
                 // Store PayPal Details
                 update_post_meta($order_id, 'PayPal Transaction ID', $transaction_details['txn_id']);
                 update_post_meta($order_id, 'Payer PayPal first name', $transaction_details['first_name']);
                 update_post_meta($order_id, 'Payer PayPal last name', $transaction_details['last_name']);
                 update_post_meta($order_id, 'PayPal Payment type', $transaction_details['payment_type']);
                 // Subscription Payment completed
                 $order->add_order_note(__('IPN subscription payment completed.', 'woocommerce-subscriptions'));
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription payment completed for order ' . $order_id);
                 }
                 // First payment on order, process payment & activate subscription
                 if ($is_first_payment) {
                     $order->payment_complete();
                     WC_Subscriptions_Manager::activate_subscriptions_for_order($order);
                     // 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 (count($subscription['completed_payments']) == 1 && !empty(self::$paypal_settings['identity_token']) && 'true' != get_post_meta($order_id, '_paypal_first_ipn_ignored_for_pdt', true)) {
                     if (self::$debug) {
                         self::$log->add('paypal', 'IPN subscription payment ignored for order ' . $order_id . ' due to PDT previously handling the payment.');
                     }
                     update_post_meta($order_id, '_paypal_first_ipn_ignored_for_pdt', 'true');
                     // Process the payment if the subscription is active
                 } elseif (!in_array($subscription['status'], array('cancelled', 'expired', 'switched', 'trash'))) {
                     // We don't need to reactivate the subscription because Subs didn't suspend it
                     remove_action('reactivated_subscription_paypal', __CLASS__ . '::reactivate_subscription_with_paypal', 10, 2);
                     WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
                     // Make sure the next payment date is sync with when PayPal processes the payments
                     WC_Subscriptions_Manager::set_next_payment_date($subscription_key, $order->customer_user);
                     add_action('reactivated_subscription_paypal', __CLASS__ . '::reactivate_subscription_with_paypal', 10, 2);
                 }
             } elseif ('failed' == strtolower($transaction_details['payment_status'])) {
                 // Subscription Payment completed
                 $order->add_order_note(__('IPN subscription payment failed.', 'woocommerce-subscriptions'));
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription payment failed for order ' . $order_id);
                 }
                 // First payment on order, don't generate a renewal order
                 if ($is_first_payment) {
                     remove_action('processed_subscription_payment_failure', 'WC_Subscriptions_Renewal_Order::generate_failed_payment_renewal_order', 10, 2);
                 }
                 WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
             } else {
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription payment notification received for order ' . $order_id . ' with status ' . $transaction_details['payment_status']);
                 }
             }
             break;
         case 'subscr_cancel':
             // Make sure the subscription hasn't been linked to a new payment method
             if ($transaction_details['subscr_id'] != self::get_subscriptions_paypal_id($order)) {
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription cancellation request ignored - new PayPal Profile ID linked to this subscription, for order ' . $order_id);
                 }
             } else {
                 WC_Subscriptions_Manager::cancel_subscriptions_for_order($order);
                 // Subscription Cancellation Completed
                 $order->add_order_note(__('IPN subscription cancelled for order.', 'woocommerce-subscriptions'));
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription cancelled for order ' . $order_id);
                 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:67,代码来源:gateway-paypal-standard-subscriptions.php

示例3: process_shop_order_item_meta

 /**
  * Work around a bug in WooCommerce which ignores order item meta values of 0.
  *
  * Code in this function is identical to a section of the @see woocommerce_process_shop_order_meta() function, except
  * that it doesn't include the bug which ignores item meta with a 0 value.
  *
  * @param int $post_id The ID of the post which is the WC_Order object.
  * @param Object $post The post object of the order.
  * @since 1.2.4
  */
 public static function process_shop_order_item_meta($post_id, $post)
 {
     global $woocommerce;
     $product_ids = array();
     if (isset($_POST['order_item_id'])) {
         foreach ($_POST['order_item_id'] as $order_item_id) {
             // WC 2.0+ has unique order item IDs and the product ID is a piece of meta
             $product_ids[$order_item_id] = woocommerce_get_order_item_meta($order_item_id, '_product_id');
         }
     }
     // Now that meta has been updated, we can update the schedules (if there were any changes to schedule related meta)
     if (!empty($product_ids)) {
         $user_id = (int) $_POST['customer_user'];
         foreach ($product_ids as $product_id) {
             $subscription_key = WC_Subscriptions_Manager::get_subscription_key($post_id, $product_id);
             // Order is important here, expiration date takes into account trial expriation date and next payment date takes into account expiration date
             if (in_array($product_id, self::$requires_update['trial_expiration'])) {
                 WC_Subscriptions_Manager::set_trial_expiration_date($subscription_key, $user_id);
             }
             if (in_array($product_id, self::$requires_update['expiration_date'])) {
                 WC_Subscriptions_Manager::set_expiration_date($subscription_key, $user_id);
             }
             if (in_array($product_id, self::$requires_update['next_billing_date'])) {
                 WC_Subscriptions_Manager::set_next_payment_date($subscription_key, $user_id);
             }
         }
     }
 }
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:38,代码来源:class-wc-subscriptions-order.php

示例4: process_shop_order_item_meta

 /**
  * Work around a bug in WooCommerce which ignores order item meta values of 0.
  *
  * Code in this function is identical to a section of the @see woocommerce_process_shop_order_meta() function, except
  * that it doesn't include the bug which ignores item meta with a 0 value.
  *
  * @param $post_id int The ID of the post which is the WC_Order object.
  * @param $post Object The post object of the order.
  * @since 1.2.4
  */
 public static function process_shop_order_item_meta($post_id, $post)
 {
     global $woocommerce;
     // Only needs to function on WC 1.x where the bug existed
     if (isset($_POST['item_id'])) {
         $order_items = array();
         $item_id = $_POST['item_id'];
         $item_variation = $_POST['item_variation'];
         $item_name = $_POST['item_name'];
         $item_quantity = $_POST['item_quantity'];
         $line_subtotal = $_POST['line_subtotal'];
         $line_subtotal_tax = $_POST['line_subtotal_tax'];
         $line_total = $_POST['line_total'];
         $line_tax = $_POST['line_tax'];
         $item_meta_names = isset($_POST['meta_name']) ? $_POST['meta_name'] : '';
         $item_meta_values = isset($_POST['meta_value']) ? $_POST['meta_value'] : '';
         $item_tax_class = $_POST['item_tax_class'];
         $item_id_count = sizeof($item_id);
         for ($i = 0; $i < $item_id_count; $i++) {
             if (!isset($item_id[$i]) || !$item_id[$i]) {
                 continue;
             }
             if (!isset($item_name[$i])) {
                 continue;
             }
             if (!isset($item_quantity[$i]) || $item_quantity[$i] < 1) {
                 continue;
             }
             if (!isset($line_total[$i])) {
                 continue;
             }
             if (!isset($line_tax[$i])) {
                 continue;
             }
             // Meta
             $item_meta = new WC_Order_Item_Meta();
             if (isset($item_meta_names[$i]) && isset($item_meta_values[$i])) {
                 $meta_names = $item_meta_names[$i];
                 $meta_values = $item_meta_values[$i];
                 $meta_names_count = sizeof($meta_names);
                 for ($ii = 0; $ii < $meta_names_count; $ii++) {
                     $meta_name = esc_attr($meta_names[$ii]);
                     $meta_value = esc_attr($meta_values[$ii]);
                     if (isset($meta_name) && isset($meta_value)) {
                         $item_meta->add($meta_name, $meta_value);
                     }
                 }
             }
             // Add to array
             $order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => (int) $item_variation[$i], 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'line_total' => rtrim(rtrim(number_format(woocommerce_clean($line_total[$i]), 4, '.', ''), '0'), '.'), 'line_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_tax[$i]), 4, '.', ''), '0'), '.'), 'line_subtotal' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', ''), '0'), '.'), 'line_subtotal_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', ''), '0'), '.'), 'item_meta' => $item_meta->meta, 'tax_class' => woocommerce_clean($item_tax_class[$i])));
         }
         update_post_meta($post_id, '_order_items', $order_items);
     }
     // WC <> 2.0 compatible posted product IDs
     $product_ids = array();
     if (isset($_POST['order_item_id'])) {
         foreach ($_POST['order_item_id'] as $order_item_id) {
             // WC 2.0+ has unique order item IDs and the product ID is a piece of meta
             $product_ids[$order_item_id] = woocommerce_get_order_item_meta($order_item_id, '_product_id');
         }
     } elseif (isset($_POST['item_id'])) {
         $product_ids = $_POST['item_id'];
     }
     // WC 1.x treated order item IDs as product IDs
     // Now that meta has been updated, we can update the schedules (if there were any changes to schedule related meta)
     if (!empty($product_ids)) {
         $user_id = (int) $_POST['customer_user'];
         foreach ($product_ids as $product_id) {
             $subscription_key = WC_Subscriptions_Manager::get_subscription_key($post_id, $product_id);
             // Order is important here, expiration date takes into account trial expriation date and next payment date takes into account expiration date
             if (in_array($product_id, self::$requires_update['trial_expiration'])) {
                 WC_Subscriptions_Manager::set_trial_expiration_date($subscription_key, $user_id);
             }
             if (in_array($product_id, self::$requires_update['expiration_date'])) {
                 WC_Subscriptions_Manager::set_expiration_date($subscription_key, $user_id);
             }
             if (in_array($product_id, self::$requires_update['next_billing_date'])) {
                 WC_Subscriptions_Manager::set_next_payment_date($subscription_key, $user_id);
             }
         }
     }
 }
开发者ID:bulats,项目名称:chef,代码行数:92,代码来源:class-wc-subscriptions-order.php


注:本文中的WC_Subscriptions_Manager::set_next_payment_date方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。