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


PHP WC_Subscriptions_Order::get_total_initial_payment方法代码示例

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


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

示例1: process_payment

 /**
  * Process the payment
  */
 function process_payment($order_id)
 {
     global $woocommerce;
     if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
         $order = new WC_Order($order_id);
         $stripe_token = isset($_POST['stripe_token']) ? woocommerce_clean($_POST['stripe_token']) : '';
         // Use Stripe CURL API for payment
         try {
             $post_data = array();
             $customer_id = 0;
             // Check if paying via customer ID
             if (isset($_POST['stripe_customer_id']) && $_POST['stripe_customer_id'] !== 'new' && is_user_logged_in()) {
                 $customer_ids = get_user_meta(get_current_user_id(), '_stripe_customer_id', false);
                 if (isset($customer_ids[$_POST['stripe_customer_id']]['customer_id'])) {
                     $customer_id = $customer_ids[$_POST['stripe_customer_id']]['customer_id'];
                 } else {
                     throw new Exception(__('Invalid card.', 'wc_stripe'));
                 }
             } elseif (empty($stripe_token)) {
                 throw new Exception(__('Please make sure your card details have been entered correctly and that your browser supports JavaScript.', 'wc_stripe'));
             }
             if (method_exists('WC_Subscriptions_Order', 'get_total_initial_payment')) {
                 $initial_payment = WC_Subscriptions_Order::get_total_initial_payment($order);
             } else {
                 $initial_payment = WC_Subscriptions_Order::get_sign_up_fee($order) + WC_Subscriptions_Order::get_price_per_period($order);
             }
             $customer_response = $this->add_customer_to_order($order, $customer_id, $stripe_token);
             if ($initial_payment > 0) {
                 $payment_response = $this->process_subscription_payment($order, $initial_payment);
             }
             if (is_wp_error($customer_response)) {
                 throw new Exception($customer_response->get_error_message());
             } else {
                 if (isset($payment_response) && is_wp_error($payment_response)) {
                     throw new Exception($payment_response->get_error_message());
                 } else {
                     // Payment complete
                     $order->payment_complete();
                     // Remove cart
                     $woocommerce->cart->empty_cart();
                     // Activate subscriptions
                     WC_Subscriptions_Manager::activate_subscriptions_for_order($order);
                     // Store token
                     if ($stripe_token) {
                         update_post_meta($order->id, '_stripe_token', $stripe_token);
                     }
                     // Return thank you page redirect
                     return array('result' => 'success', 'redirect' => $this->get_return_url($order));
                 }
             }
         } catch (Exception $e) {
             $woocommerce->add_error(__('Error:', 'wc_stripe') . ' "' . $e->getMessage() . '"');
             return;
         }
     } else {
         return parent::process_payment($order_id);
     }
 }
开发者ID:orlandomario,项目名称:WooSponsorship,代码行数:61,代码来源:class-wc-gateway-stripe-subscriptions.php

示例2: process_subscription

 /**
  * Process the subscription
  *
  * @param int $order_id
  * @return array
  */
 public function process_subscription($order_id)
 {
     $order = wc_get_order($order_id);
     $token = isset($_POST['simplify_token']) ? wc_clean($_POST['simplify_token']) : '';
     try {
         if (empty($token)) {
             $error_msg = __('Please make sure your card details have been entered correctly and that your browser supports JavaScript.', 'woocommerce');
             if ('yes' == $this->sandbox) {
                 $error_msg .= ' ' . __('Developers: Please make sure that you\'re including jQuery and there are no JavaScript errors on the page.', 'woocommerce');
             }
             throw new Simplify_ApiException($error_msg);
         }
         // Create customer
         $customer = Simplify_Customer::createCustomer(array('token' => $token, 'email' => $order->billing_email, 'name' => trim($order->billing_first_name . ' ' . $order->billing_last_name), 'reference' => $order->id));
         if (is_object($customer) && '' != $customer->id) {
             $customer_id = wc_clean($customer->id);
             // Store the customer ID in the order
             update_post_meta($order_id, '_simplify_customer_id', $customer_id);
         } else {
             $error_msg = __('Error creating user in Simplify Commerce.', 'woocommerce');
             throw new Simplify_ApiException($error_msg);
         }
         $initial_payment = WC_Subscriptions_Order::get_total_initial_payment($order);
         if ($initial_payment > 0) {
             $payment_response = $this->process_subscription_payment($order, $initial_payment);
         }
         if (isset($payment_response) && is_wp_error($payment_response)) {
             throw new Exception($payment_response->get_error_message());
         } else {
             // Remove cart
             WC()->cart->empty_cart();
             // Return thank you page redirect
             return array('result' => 'success', 'redirect' => $this->get_return_url($order));
         }
     } catch (Simplify_ApiException $e) {
         if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) {
             foreach ($e->getFieldErrors() as $error) {
                 wc_add_notice($error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')', 'error');
             }
         } else {
             wc_add_notice($e->getMessage(), 'error');
         }
         return array('result' => 'fail', 'redirect' => '');
     }
 }
开发者ID:vanminh0910,项目名称:shangri-la,代码行数:51,代码来源:class-wc-addons-gateway-simplify-commerce.php

示例3: process_subscription

 /**
  * Process the subscription
  *
  * @param  int $order_id
  * @return array
  */
 public function process_subscription($order_id)
 {
     $order = new WC_Order($order_id);
     if ($this->sandbox == 'yes') {
         $error_msg .= ' ' . __('Developers: Please make sure that you\'re including jQuery and there are no JavaScript errors on the page.', 'woocommerce-payment-gateway-boilerplate');
     }
     $initial_payment = WC_Subscriptions_Order::get_total_initial_payment($order);
     if ($initial_payment > 0) {
         $payment_response = $this->process_subscription_payment($order, $initial_payment);
     }
     if (isset($payment_response) && is_wp_error($payment_response)) {
         throw new Exception($payment_response->get_error_message());
     } else {
         // Remove cart
         WC()->cart->empty_cart();
         // Return thank you page redirect
         return array('result' => 'success', 'redirect' => $this->get_return_url($order));
     }
     return array('result' => 'fail', 'redirect' => '');
 }
开发者ID:prayas-sapkota,项目名称:WooCommerce-Payment-Gateway-Boilerplate,代码行数:26,代码来源:class-wc-gateway-payment-gateway-boilerplate-add-ons.php

示例4: process_subscription

 /**
  * Process the subscription.
  *
  * @param WC_Order $order
  *
  * @return array
  */
 protected function process_subscription($order_id)
 {
     try {
         $order = new WC_Order($order_id);
         if (!isset($_POST['iugu_token'])) {
             if ('yes' == $this->debug) {
                 $this->log->add($this->id, 'Error doing the subscription for order ' . $order->get_order_number() . ': Missing the "iugu_token".');
             }
             $error_msg = __('Please make sure your card details have been entered correctly and that your browser supports JavaScript.', 'iugu-woocommerce');
             throw new Exception($error_msg);
         }
         // Create customer payment method.
         $payment_method_id = $this->api->create_customer_payment_method($order, $_POST['iugu_token']);
         if (!$payment_method_id) {
             if ('yes' == $this->debug) {
                 $this->log->add($this->id, 'Invalid customer method ID for order ' . $order->get_order_number());
             }
             $error_msg = __('An error occurred while trying to save your data. Please contact us for get help.', 'iugu-woocommerce');
             throw new Exception($error_msg);
         }
         // Save the payment method ID in order data.
         update_post_meta($order->id, '_iugu_customer_payment_method_id', $payment_method_id);
         // Try to do an initial payment.
         $initial_payment = WC_Subscriptions_Order::get_total_initial_payment($order);
         if ($initial_payment > 0) {
             $payment_response = $this->process_subscription_payment($order, $initial_payment);
         }
         if (isset($payment_response) && is_wp_error($payment_response)) {
             throw new Exception($payment_response->get_error_message());
         } else {
             // Remove cart
             $this->api->empty_card();
             // Return thank you page redirect
             return array('result' => 'success', 'redirect' => $this->get_return_url($order));
         }
     } catch (Exception $e) {
         $this->api->add_error('<strong>' . esc_attr($this->title) . '</strong>: ' . $e->getMessage());
         return array('result' => 'fail', 'redirect' => '');
     }
 }
开发者ID:jarsgt,项目名称:iugu-woocommerce,代码行数:47,代码来源:class-wc-iugu-credit-card-addons-gateway.php

示例5: process_subscription

 /**
  * Process the subscription.
  *
  * @param WC_Order $order
  *
  * @return array
  */
 protected function process_subscription($order_id)
 {
     try {
         $order = new WC_Order($order_id);
         // Try to do an initial payment.
         $initial_payment = WC_Subscriptions_Order::get_total_initial_payment($order);
         if ($initial_payment > 0) {
             $payment_response = $this->process_subscription_payment($order, $initial_payment);
         }
         if (isset($payment_response) && is_wp_error($payment_response)) {
             throw new Exception($payment_response->get_error_message());
         } else {
             // Remove cart
             $this->api->empty_card();
             // Return thank you page redirect
             return array('result' => 'success', 'redirect' => $this->get_return_url($order));
         }
     } catch (Exception $e) {
         $this->api->add_error('<strong>' . esc_attr($this->title) . '</strong>: ' . $e->getMessage());
         return array('result' => 'fail', 'redirect' => '');
     }
 }
开发者ID:jarsgt,项目名称:iugu-woocommerce,代码行数:29,代码来源:class-wc-iugu-bank-slip-addons-gateway.php

示例6: request_access_code

 public function request_access_code($order, $method = 'ProcessPayment', $trx_type = 'Purchase')
 {
     $customer_ip = get_post_meta($order->id, '_customer_ip_address', true);
     // Check if order is for a subscription, if it is check for fee and charge that
     if (class_exists('WC_Subscriptions_Order') && WC_Subscriptions_Order::order_contains_subscription($order->id)) {
         if (0 == WC_Subscriptions_Order::get_total_initial_payment($order)) {
             $method = 'CreateTokenCustomer';
         } else {
             $method = 'TokenPayment';
         }
         $trx_type = 'Recurring';
         $order_total = WC_Subscriptions_Order::get_total_initial_payment($order) * 100;
     } else {
         $order_total = $order->get_total() * 100.0;
     }
     // set up request object
     $request = array('Method' => $method, 'TransactionType' => $trx_type, 'RedirectUrl' => str_replace('https:', 'http:', add_query_arg(array('wc-api' => 'WC_Gateway_EWAY', 'order_id' => $order->id, 'order_key' => $order->order_key, 'sig_key' => md5($order->order_key . 'WOO' . $order->id)), home_url('/'))), 'IPAddress' => $customer_ip, 'DeviceID' => '0b38ae7c3c5b466f8b234a8955f62bdd', 'PartnerID' => '0b38ae7c3c5b466f8b234a8955f62bdd', 'Payment' => array('TotalAmount' => $order_total, 'CurrencyCode' => get_woocommerce_currency(), 'InvoiceDescription' => apply_filters('woocommerce_eway_description', '', $order), 'InvoiceNumber' => ltrim($order->get_order_number(), _x('#', 'hash before order number', 'woocommerce')), 'InvoiceReference' => $order->id), 'Customer' => array('FirstName' => $order->billing_first_name, 'LastName' => $order->billing_last_name, 'CompanyName' => substr($order->billing_company, 0, 50), 'Street1' => $order->billing_address_1, 'Street2' => $order->billing_address_2, 'City' => $order->billing_city, 'State' => $order->billing_state, 'PostalCode' => $order->billing_postcode, 'Country' => $order->billing_country, 'Email' => $order->billing_email, 'Phone' => $order->billing_phone));
     // Add customer ID if logged in
     if (is_user_logged_in()) {
         $request['Options'][] = array('customerID' => get_current_user_id());
     }
     return $this->perform_request('/CreateAccessCode.json', json_encode($request));
 }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:23,代码来源:class-wc-eway-api.php

示例7: process_subscription_payment

 /**
  * Records a payment on a subscription.
  *
  * @param int $user_id The id of the user who owns the subscription. 
  * @param string $subscription_key A subscription key of the form obtained by @see get_subscription_key( $order_id, $product_id )
  * @since 1.0
  */
 public static function process_subscription_payment($user_id, $subscription_key)
 {
     // Store a record of the subscription payment date
     $subscription = self::get_subscription($subscription_key);
     $subscription['completed_payments'][] = gmdate('Y-m-d H:i:s');
     // Reset failed payment count & suspension count
     $subscription['failed_payments'] = $subscription['suspension_count'] = 0;
     self::update_users_subscriptions($user_id, array($subscription_key => $subscription));
     // Make sure subscriber is marked as a "Paying Customer"
     self::mark_paying_customer($subscription['order_id']);
     // Make sure subscriber has default role
     self::update_users_role($user_id, 'default_subscriber_role');
     // Log payment on order
     $order = new WC_Order($subscription['order_id']);
     $item = WC_Subscriptions_Order::get_item_by_product_id($order, $subscription['product_id']);
     // Free trial & no-signup fee, no payment received
     if (0 == WC_Subscriptions_Order::get_total_initial_payment($order) && 1 == count($subscription['completed_payments'])) {
         if (WC_Subscriptions_Order::requires_manual_renewal($subscription['order_id'])) {
             $order_note = sprintf(__('Free trial commenced for subscription "%s"', 'woocommerce-subscriptions'), $item['name']);
         } else {
             $order_note = sprintf(__('Recurring payment authorized for subscription "%s"', 'woocommerce-subscriptions'), $item['name']);
         }
     } else {
         $order_note = sprintf(__('Payment received for subscription "%s"', 'woocommerce-subscriptions'), $item['name']);
     }
     $order->add_order_note($order_note);
     do_action('processed_subscription_payment', $user_id, $subscription_key);
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:35,代码来源:class-wc-subscriptions-manager.php

示例8: column_default

 /**
  * Outputs the content for each column.
  *
  * @param array $item A singular item (one full row's worth of data)
  * @param array $column_name The name/slug of the column to be processed
  * @return string Text or HTML to be placed inside the column <td>
  * @since 1.0
  */
 public function column_default($item, $column_name)
 {
     global $woocommerce;
     $current_gmt_time = gmdate('U');
     $column_content = '';
     switch ($column_name) {
         case 'status':
             $actions = array();
             $action_url = add_query_arg(array('page' => $_REQUEST['page'], 'user' => $item['user_id'], 'subscription' => $item['subscription_key'], '_wpnonce' => wp_create_nonce($item['subscription_key'])));
             if (isset($_REQUEST['status'])) {
                 $action_url = add_query_arg(array('status' => $_REQUEST['status']), $action_url);
             }
             $order = new WC_Order($item['order_id']);
             $all_statuses = array('active' => __('Reactivate', 'woocommerce-subscriptions'), 'on-hold' => __('Suspend', 'woocommerce-subscriptions'), 'cancelled' => __('Cancel', 'woocommerce-subscriptions'), 'trash' => __('Trash', 'woocommerce-subscriptions'), 'deleted' => __('Delete Permanently', 'woocommerce-subscriptions'));
             foreach ($all_statuses as $status => $label) {
                 if (WC_Subscriptions_Manager::can_subscription_be_changed_to($status, $item['subscription_key'], $item['user_id'])) {
                     $action = 'deleted' == $status ? 'delete' : $status;
                     // For built in CSS
                     $actions[$action] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg('new_status', $status, $action_url)), $label);
                 }
             }
             if ($item['status'] == 'pending') {
                 unset($actions['active']);
                 unset($actions['trash']);
             } elseif (!in_array($item['status'], array('cancelled', 'expired', 'switched', 'suspended'))) {
                 unset($actions['trash']);
             }
             $actions = apply_filters('woocommerce_subscriptions_list_table_actions', $actions, $item);
             $column_content = sprintf('<mark class="%s">%s</mark> %s', sanitize_title($item[$column_name]), WC_Subscriptions_Manager::get_status_to_display($item[$column_name], $item['subscription_key'], $item['user_id']), $this->row_actions($actions));
             $column_content = apply_filters('woocommerce_subscriptions_list_table_column_status_content', $column_content, $item, $actions, $this);
             break;
         case 'title':
             //Return the title contents
             $column_content = sprintf('<a href="%s">%s</a>', get_edit_post_link($item['product_id']), WC_Subscriptions_Order::get_item_name($item['order_id'], $item['product_id']));
             $order = new WC_Order($item['order_id']);
             $order_item = WC_Subscriptions_Order::get_item_by_product_id($order, $item['product_id']);
             $product = $order->get_product_from_item($order_item);
             if (isset($product->variation_data)) {
                 $column_content .= '<br />' . woocommerce_get_formatted_variation($product->variation_data, true);
             }
             break;
         case 'order_id':
             $order = new WC_Order($item[$column_name]);
             $column_content = sprintf('<a href="%1$s">%2$s</a>', get_edit_post_link($item[$column_name]), sprintf(__('Order %s', 'woocommerce-subscriptions'), $order->get_order_number()));
             break;
         case 'user':
             $user = get_user_by('id', $item['user_id']);
             if (is_object($user)) {
                 $column_content = sprintf('<a href="%s">%s</a>', admin_url('user-edit.php?user_id=' . $user->ID), ucfirst($user->display_name));
             }
             break;
         case 'start_date':
         case 'expiry_date':
         case 'end_date':
             if ($column_name == 'expiry_date' && $item[$column_name] == 0) {
                 $column_content = __('Never', 'woocommerce-subscriptions');
             } else {
                 if ($column_name == 'end_date' && $item[$column_name] == 0) {
                     $column_content = __('Not yet ended', 'woocommerce-subscriptions');
                 } else {
                     $gmt_timestamp = strtotime($item[$column_name]);
                     $user_timestamp = $gmt_timestamp + get_option('gmt_offset') * 3600;
                     $column_content = sprintf('<time>%s</time>', date_i18n(woocommerce_date_format(), $user_timestamp));
                 }
             }
             break;
         case 'trial_expiry_date':
             $trial_expiration = WC_Subscriptions_Manager::get_trial_expiration_date($item['subscription_key'], $item['user_id'], 'timestamp');
             if (empty($trial_expiration)) {
                 $column_content = '-';
             } else {
                 $column_content = sprintf('<time title="%s">%s</time>', esc_attr($trial_expiration), date_i18n(woocommerce_date_format(), $trial_expiration + get_option('gmt_offset') * 3600));
             }
             break;
         case 'last_payment_date':
             // Although we record the sign-up date as a payment, if there is a free trial and no sign-up fee, no payment is actually charged
             if (0 == WC_Subscriptions_Order::get_total_initial_payment($item['order_id']) && 1 == count($item['completed_payments'])) {
                 $column_content = '-';
             } else {
                 $last_payment_timestamp = strtotime($item['last_payment_date']);
                 $time_diff = $current_gmt_time - $last_payment_timestamp;
                 if ($time_diff > 0 && $time_diff < 7 * 24 * 60 * 60) {
                     $last_payment = sprintf(__('%s ago', 'woocommerce-subscriptions'), human_time_diff($last_payment_timestamp, $current_gmt_time));
                 } else {
                     $last_payment = date_i18n(woocommerce_date_format(), $last_payment_timestamp + get_option('gmt_offset') * 3600);
                 }
                 $column_content = sprintf('<time title="%s">%s</time>', esc_attr($last_payment_timestamp), $last_payment);
             }
             break;
         case 'next_payment_date':
             $next_payment_timestamp_gmt = WC_Subscriptions_Manager::get_next_payment_date($item['subscription_key'], $item['user_id'], 'timestamp');
             $next_payment_timestamp = $next_payment_timestamp_gmt + get_option('gmt_offset') * 3600;
//.........这里部分代码省略.........
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:101,代码来源:class-wc-subscriptions-list-table.php

示例9: subscriptions_get_order

 /**
  * Adds subscriptions data to the order object
  *
  * @since 1.0
  * @see SV_WC_Payment_Gateway::get_order()
  * @param WC_Order $order the order
  * @return WC_Order the orders
  */
 public function subscriptions_get_order($order)
 {
     // bail if the gateway doesn't support subscriptions or the order doesn't contain a subscription
     if (!$this->supports_subscriptions() || !WC_Subscriptions_Order::order_contains_subscription($order->id)) {
         return $order;
     }
     // subscriptions total, ensuring that we have a decimal point, even if it's 1.00
     $order->payment_total = number_format((double) WC_Subscriptions_Order::get_total_initial_payment($order), 2, '.', '');
     // load any required members that we might not have
     if (!isset($order->payment->token) || !$order->payment->token) {
         $order->payment->token = get_post_meta($order->id, '_wc_' . $this->get_id() . '_payment_token', true);
     }
     if (!isset($order->customer_id) || !$order->customer_id) {
         $order->customer_id = get_post_meta($order->id, '_wc_' . $this->get_id() . '_customer_id', true);
     }
     // ensure the payment token is still valid
     if (!$this->has_payment_token($order->user_id, $order->payment->token)) {
         $order->payment->token = null;
     } else {
         // get the token object
         $token = $this->get_payment_token($order->user_id, $order->payment->token);
         if (!isset($order->payment->account_number) || !$order->payment->account_number) {
             $order->payment->account_number = $token->get_last_four();
         }
         if ($this->is_credit_card_gateway()) {
             // credit card token
             if (!isset($order->payment->card_type) || !$order->payment->card_type) {
                 $order->payment->card_type = $token->get_card_type();
             }
             if (!isset($order->payment->exp_month) || !$order->payment->exp_month) {
                 $order->payment->exp_month = $token->get_exp_month();
             }
             if (!isset($order->payment->exp_year) || !$order->payment->exp_year) {
                 $order->payment->exp_year = $token->get_exp_year();
             }
         } elseif ($this->is_echeck_gateway()) {
             // check token
             if (!isset($order->payment->account_type) || !$order->payment->account_type) {
                 $order->payment->account_type = $token->get_account_type();
             }
         }
     }
     return $order;
 }
开发者ID:nomadicmarc,项目名称:goodbay,代码行数:52,代码来源:class-sv-wc-payment-gateway-direct.php

示例10: get_sign_up_fee

 /**
  * Filters WC_Subscriptions_Order::get_sign_up_fee() to make sure the sign-up fee for a subscription product
  * that is synchronised is returned correctly.
  *
  * @param float The initial sign-up fee charged when the subscription product in the order was first purchased, if any.
  * @param mixed $order A WC_Order object or the ID of the order which the subscription was purchased in.
  * @param int $product_id The post ID of the subscription WC_Product object purchased in the order. Defaults to the ID of the first product purchased in the order.
  * @return float The initial sign-up fee charged when the subscription product in the order was first purchased, if any.
  * @since 1.5.3
  * @deprecated 2.0
  */
 public static function get_sign_up_fee($sign_up_fee, $order, $product_id, $non_subscription_total)
 {
     _deprecated_function(__METHOD__, '2.0', __CLASS__ . '::get_synced_sign_up_fee');
     if ('shop_order' == get_post_type($order) && self::order_contains_synced_subscription($order->id) && WC_Subscriptions_Order::get_subscription_trial_length($order) < 1) {
         $sign_up_fee = max(WC_Subscriptions_Order::get_total_initial_payment($order) - $non_subscription_total, 0);
     }
     return $sign_up_fee;
 }
开发者ID:bself,项目名称:nuimage-wp,代码行数:19,代码来源:class-wc-subscriptions-synchroniser.php

示例11: charge_set_up

 /**
  * Set up the charge that will be sent to Stripe
  *
  * @access      private
  * @return      void
  */
 private function charge_set_up()
 {
     global $s4wc;
     // Add a customer or retrieve an existing one
     $customer = $this->get_customer();
     $customer_info = get_user_meta($this->order->user_id, $s4wc->settings['stripe_db_location'], true);
     // Update default card
     if ($this->form_data['chosen_card'] !== 'new') {
         $default_card = $customer_info['cards'][intval($this->form_data['chosen_card'])]['id'];
         S4WC_DB::update_customer($this->order->user_id, array('default_card' => $default_card));
     }
     $initial_payment = WC_Subscriptions_Order::get_total_initial_payment($this->order);
     $charge = $this->process_subscription_payment($initial_payment);
     $this->charge = $charge;
     $this->transaction_id = $charge->id;
 }
开发者ID:tccyp001,项目名称:onemore-wordpress,代码行数:22,代码来源:class-s4wc_subscriptions_gateway.php

示例12: get_order_1_5

 /**
  * Adds subscriptions data to the order object
  *
  * @since 4.1.0
  * @see SV_WC_Payment_Gateway::get_order()
  * @param WC_Order $order the order
  * @return WC_Order the orders
  */
 public function get_order_1_5($order)
 {
     // bail if the order doesn't contain a subscription
     if (!WC_Subscriptions_Order::order_contains_subscription($order->id)) {
         return $order;
     }
     // subscriptions total, ensuring that we have a decimal point, even if it's 1.00
     $order->payment_total = SV_WC_Helper::number_format(WC_Subscriptions_Order::get_total_initial_payment($order));
     // load any required members that we might not have
     if (!isset($order->payment->token) || !$order->payment->token) {
         $order->payment->token = $this->get_gateway()->get_order_meta($order->id, 'payment_token');
     }
     if (!isset($order->customer_id) || !$order->customer_id) {
         $order->customer_id = $this->get_gateway()->get_order_meta($order->id, 'customer_id');
     }
     // ensure the payment token is still valid
     if (!$this->get_gateway()->has_payment_token($order->get_user_id(), $order->payment->token)) {
         $order->payment->token = null;
     } else {
         // get the token object
         $token = $this->get_gateway()->get_payment_token($order->get_user_id(), $order->payment->token);
         if (!isset($order->payment->account_number) || !$order->payment->account_number) {
             $order->payment->account_number = $token->get_last_four();
         }
         if ($this->get_gateway()->is_credit_card_gateway()) {
             // credit card token
             if (!isset($order->payment->card_type) || !$order->payment->card_type) {
                 $order->payment->card_type = $token->get_card_type();
             }
             if (!isset($order->payment->exp_month) || !$order->payment->exp_month) {
                 $order->payment->exp_month = $token->get_exp_month();
             }
             if (!isset($order->payment->exp_year) || !$order->payment->exp_year) {
                 $order->payment->exp_year = $token->get_exp_year();
             }
         } elseif ($this->get_gateway()->is_echeck_gateway()) {
             // check token
             if (!isset($order->payment->account_type) || !$order->payment->account_type) {
                 $order->payment->account_type = $token->get_account_type();
             }
         }
     }
     return $order;
 }
开发者ID:shredzjc,项目名称:wc-plugin-framework,代码行数:52,代码来源:class-sv-wc-payment-gateway-integration-subscriptions.php

示例13: paypal_standard_subscription_args

 /**
  * Override the default PayPal standard args in WooCommerce for subscription purchases.
  *
  * Based on the HTML Variables documented here: https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HI00JQU
  *
  * @since 1.0
  */
 public static function paypal_standard_subscription_args($paypal_args)
 {
     extract(self::get_order_id_and_key($paypal_args));
     if (WC_Subscriptions_Order::order_contains_subscription($order_id) && 'yes' !== get_option(WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no')) {
         $order = new WC_Order($order_id);
         $order_items = $order->get_items();
         // Only one subscription allowed in the cart when PayPal Standard is active
         $product = $order->get_product_from_item(array_pop($order_items));
         // It's a subscription
         $paypal_args['cmd'] = '_xclick-subscriptions';
         if (count($order->get_items()) > 1) {
             foreach ($order->get_items() as $item) {
                 if ($item['qty'] > 1) {
                     $item_names[] = $item['qty'] . ' x ' . $item['name'];
                 } else {
                     if ($item['qty'] > 0) {
                         $item_names[] = $item['name'];
                     }
                 }
             }
             $paypal_args['item_name'] = sprintf(__('Order %s', WC_Subscriptions::$text_domain), $order->get_order_number());
         } else {
             $paypal_args['item_name'] = $product->get_title();
         }
         $unconverted_periods = array('billing_period' => WC_Subscriptions_Order::get_subscription_period($order), 'trial_period' => WC_Subscriptions_Order::get_subscription_trial_period($order));
         $converted_periods = array();
         // Convert period strings into PayPay's format
         foreach ($unconverted_periods as $key => $period) {
             switch (strtolower($period)) {
                 case 'day':
                     $converted_periods[$key] = 'D';
                     break;
                 case 'week':
                     $converted_periods[$key] = 'W';
                     break;
                 case 'year':
                     $converted_periods[$key] = 'Y';
                     break;
                 case 'month':
                 default:
                     $converted_periods[$key] = 'M';
                     break;
             }
         }
         $price_per_period = WC_Subscriptions_Order::get_recurring_total($order);
         $subscription_interval = WC_Subscriptions_Order::get_subscription_interval($order);
         $subscription_length = WC_Subscriptions_Order::get_subscription_length($order);
         $subscription_installments = $subscription_length / $subscription_interval;
         $is_payment_change = WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment;
         $is_switch_order = WC_Subscriptions_Switcher::order_contains_subscription_switch($order->id);
         $sign_up_fee = $is_payment_change ? 0 : WC_Subscriptions_Order::get_sign_up_fee($order);
         $initial_payment = $is_payment_change ? 0 : WC_Subscriptions_Order::get_total_initial_payment($order);
         if ($is_payment_change) {
             // Add a nonce to the order ID to avoid "This invoice has already been paid" error when changing payment method to PayPal when it was previously PayPal
             $paypal_args['invoice'] = $paypal_args['invoice'] . '-wcscpm-' . wp_create_nonce();
             // Set a flag on the order if changing from PayPal *to* PayPal to prevent incorrectly cancelling the subscription
             if ('paypal' == $order->recurring_payment_method) {
                 add_post_meta($order_id, '_wcs_changing_payment_from_paypal_to_paypal', 'true', true);
             }
         }
         // If we're changing the payment date or switching subs, we need to set the trial period to the next payment date & installments to be the number of installments left
         if ($is_payment_change || $is_switch_order) {
             $subscription_key = WC_Subscriptions_Manager::get_subscription_key($order_id, $product->id);
             // Give a free trial until the next payment date
             $next_payment_timestamp = WC_Subscriptions_Manager::get_next_payment_date($subscription_key, $order->user_id, 'timestamp');
             // When the subscription is on hold
             if ($next_payment_timestamp != false) {
                 $trial_until = self::calculate_trial_periods_until($next_payment_timestamp);
                 $subscription_trial_length = $trial_until['first_trial_length'];
                 $converted_periods['trial_period'] = $trial_until['first_trial_period'];
                 $second_trial_length = $trial_until['second_trial_length'];
                 $second_trial_period = $trial_until['second_trial_period'];
             }
             // If is a payment change, we need to account for completed payments on the number of installments owing
             if ($is_payment_change && $subscription_length > 0) {
                 $subscription_installments -= WC_Subscriptions_Manager::get_subscriptions_completed_payment_count($subscription_key);
             }
         } else {
             $subscription_trial_length = WC_Subscriptions_Order::get_subscription_trial_length($order);
         }
         if ($subscription_trial_length > 0) {
             // Specify a free trial period
             if ($is_switch_order) {
                 $paypal_args['a1'] = $initial_payment > 0 ? $initial_payment : 0;
             } else {
                 $paypal_args['a1'] = $sign_up_fee > 0 ? $sign_up_fee : 0;
             }
             // Maybe add the sign up fee to the free trial period
             // Trial period length
             $paypal_args['p1'] = $subscription_trial_length;
             // Trial period
             $paypal_args['t1'] = $converted_periods['trial_period'];
             // We need to use a second trial period before we have more than 90 days until the next payment
//.........这里部分代码省略.........
开发者ID:bulats,项目名称:chef,代码行数:101,代码来源:gateway-paypal-standard-subscriptions.php

示例14: callback_handler

 /**
  * callback_handler function.
  *
  * Is called after a payment has been submitted in the QuickPay payment window.
  *
  * @access public 
  * @return void
  */
 public function callback_handler()
 {
     $request_body = file_get_contents("php://input");
     $json = json_decode($request_body);
     $payment = new WC_QuickPay_API_Payment($request_body);
     if ($payment->is_authorized_callback($request_body)) {
         // Fetch order number;
         $order_number = WC_QuickPay_Order::get_order_id_from_callback($json);
         // Instantiate order object
         $order = new WC_QuickPay_Order($order_number);
         // Get last transaction in operation history
         $transaction = end($json->operations);
         // Is the transaction accepted?
         if ($json->accepted) {
             // Add order transaction fee
             $order->add_transaction_fee($transaction->amount);
             // Perform action depending on the operation status type
             try {
                 switch ($transaction->type) {
                     //
                     // Cancel callbacks are currently not supported by the QuickPay API
                     //
                     case 'cancel':
                         if (WC_QuickPay_Helper::subscription_is_active()) {
                             if ($order->contains_subscription()) {
                                 WC_Subscriptions_Manager::cancel_subscriptions_for_order($order->id);
                             }
                         }
                         // Write a note to the order history
                         $order->note(__('Payment cancelled.', 'woo-quickpay'));
                         break;
                     case 'capture':
                         // Write a note to the order history
                         $order->note(__('Payment captured.', 'woo-quickpay'));
                         break;
                     case 'refund':
                         $order->note(sprintf(__('Refunded %s %s', 'woo-quickpay'), WC_QuickPay_Helper::price_normalize($transaction->amount), $json->currency));
                         break;
                     case 'authorize':
                         // Set the transaction ID
                         $order->set_transaction_id($json->id);
                         // Set the transaction order ID
                         $order->set_transaction_order_id($json->order_id);
                         // Remove payment link
                         $order->delete_payment_link();
                         // Remove payment ID, now we have the transaction ID
                         $order->delete_payment_id();
                         // Subscription authorization
                         if (isset($json->type) and strtolower($json->type) == 'subscription') {
                             // Create subscription instance
                             $subscription = new WC_QuickPay_API_Subscription($request_body);
                             // Write log
                             $order->note(sprintf(__('Subscription authorized. Transaction ID: %s', 'woo-quickpay'), $json->id));
                             // If 'capture first payment on subscription' is enabled
                             if (WC_QuickPay_Helper::option_is_enabled($this->s('quickpay_autodraw_subscription'))) {
                                 // Check if there is an initial payment on the subscription
                                 $subscription_initial_payment = WC_Subscriptions_Order::get_total_initial_payment($order);
                                 // Only make an instant payment if there is an initial payment
                                 if ($subscription_initial_payment > 0) {
                                     // New subscription instance
                                     $subscription = new WC_QuickPay_API_Subscription();
                                     // Perform API recurring payment request
                                     $recurring = $subscription->recurring($json->id, $order, $subscription_initial_payment);
                                     // Process the recurring response data
                                     WC_QuickPay_API_Subscription::process_recurring_response($recurring, $order);
                                 }
                             }
                         } else {
                             // Write a note to the order history
                             $order->note(sprintf(__('Payment authorized. Transaction ID: %s', 'woo-quickpay'), $json->id));
                         }
                         // Register the payment on the order
                         $order->payment_complete();
                         break;
                 }
             } catch (QuickPay_API_Exception $e) {
                 $e->write_to_logs();
             }
         } else {
             // Write debug information
             $this->log->separator();
             $this->log->add(sprintf(__('Transaction failed for #%s.', 'woo-quickpay'), $order_number));
             $this->log->add(sprintf(__('QuickPay status code: %s.', 'woo-quickpay'), $transaction->qp_status_code));
             $this->log->add(sprintf(__('QuickPay status message: %s.', 'woo-quickpay'), $transaction->qp_status_msg));
             $this->log->add(sprintf(__('Acquirer status code: %s', 'woo-quickpay'), $transaction->aq_status_code));
             $this->log->add(sprintf(__('Acquirer status message: %s', 'woo-quickpay'), $transaction->aq_status_msg));
             $this->log->separator();
             // Update the order statuses
             if ($transaction->type == 'subscribe' or $transaction->type == 'recurring') {
                 WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
             } else {
                 $order->update_status('failed');
//.........这里部分代码省略.........
开发者ID:loevendahl,项目名称:flexbil,代码行数:101,代码来源:woocommerce-quickpay.php

示例15: paypal_standard_subscription_args

 /**
  * Override the default PayPal standard args in WooCommerce for subscription purchases when
  * automatic payments are enabled and when the recurring order totals is over $0.00 (because
  * PayPal doesn't support subscriptions with a $0 recurring total, we need to circumvent it and
  * manage it entirely ourselves.)
  *
  * Based on the HTML Variables documented here: https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HI00JQU
  *
  * @since 1.0
  */
 public static function paypal_standard_subscription_args($paypal_args)
 {
     extract(self::get_order_id_and_key($paypal_args));
     $order = new WC_Order($order_id);
     if ($cart_item = WC_Subscriptions_Cart::cart_contains_failed_renewal_order_payment() || false !== WC_Subscriptions_Renewal_Order::get_failed_order_replaced_by($order_id)) {
         $renewal_order = $order;
         $order = WC_Subscriptions_Renewal_Order::get_parent_order($renewal_order);
         $order_contains_failed_renewal = true;
     } else {
         $order_contains_failed_renewal = false;
     }
     if ($order_contains_failed_renewal || WC_Subscriptions_Order::order_contains_subscription($order) && WC_Subscriptions_Order::get_recurring_total($order) > 0 && 'yes' !== get_option(WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no')) {
         // Only one subscription allowed in the cart when PayPal Standard is active
         $product = $order->get_product_from_item(array_pop(WC_Subscriptions_Order::get_recurring_items($order)));
         // It's a subscription
         $paypal_args['cmd'] = '_xclick-subscriptions';
         if (count($order->get_items()) > 1) {
             foreach ($order->get_items() as $item) {
                 if ($item['qty'] > 1) {
                     $item_names[] = $item['qty'] . ' x ' . self::paypal_item_name($item['name']);
                 } elseif ($item['qty'] > 0) {
                     $item_names[] = self::paypal_item_name($item['name']);
                 }
             }
             $paypal_args['item_name'] = self::paypal_item_name(sprintf(__('Order %s', 'woocommerce-subscriptions'), $order->get_order_number() . " - " . implode(', ', $item_names)));
         } else {
             $paypal_args['item_name'] = self::paypal_item_name($product->get_title());
         }
         $unconverted_periods = array('billing_period' => WC_Subscriptions_Order::get_subscription_period($order), 'trial_period' => WC_Subscriptions_Order::get_subscription_trial_period($order));
         $converted_periods = array();
         // Convert period strings into PayPay's format
         foreach ($unconverted_periods as $key => $period) {
             switch (strtolower($period)) {
                 case 'day':
                     $converted_periods[$key] = 'D';
                     break;
                 case 'week':
                     $converted_periods[$key] = 'W';
                     break;
                 case 'year':
                     $converted_periods[$key] = 'Y';
                     break;
                 case 'month':
                 default:
                     $converted_periods[$key] = 'M';
                     break;
             }
         }
         $price_per_period = WC_Subscriptions_Order::get_recurring_total($order);
         $subscription_interval = WC_Subscriptions_Order::get_subscription_interval($order);
         $subscription_length = WC_Subscriptions_Order::get_subscription_length($order);
         $subscription_installments = $subscription_length / $subscription_interval;
         $is_payment_change = WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment;
         $is_switch_order = WC_Subscriptions_Switcher::order_contains_subscription_switch($order->id);
         $is_synced_subscription = WC_Subscriptions_Synchroniser::order_contains_synced_subscription($order->id);
         $sign_up_fee = $is_payment_change ? 0 : WC_Subscriptions_Order::get_sign_up_fee($order);
         $initial_payment = $is_payment_change ? 0 : WC_Subscriptions_Order::get_total_initial_payment($order);
         if ($is_payment_change) {
             // Add a nonce to the order ID to avoid "This invoice has already been paid" error when changing payment method to PayPal when it was previously PayPal
             $paypal_args['invoice'] = $paypal_args['invoice'] . '-wcscpm-' . wp_create_nonce();
         } elseif ($order_contains_failed_renewal) {
             // Set the invoice details to the original order's invoice but also append a special string and this renewal orders ID so that we can match it up as a failed renewal order payment later
             $paypal_args['invoice'] = self::$invoice_prefix . ltrim($order->get_order_number(), '#') . '-wcsfrp-' . $renewal_order->id;
             $paypal_args['custom'] = serialize(array($order->id, $order->order_key));
         }
         if ($order_contains_failed_renewal) {
             $sign_up_fee = 0;
             $initial_payment = $renewal_order->get_total();
             // Initial payment can be left in case the customer is purchased other products with the payment
             $subscription_trial_length = 0;
             $subscription_installments = max($subscription_installments - WC_Subscriptions_Manager::get_subscriptions_completed_payment_count(WC_Subscriptions_Manager::get_subscription_key($order_id, $product->id)), 0);
             // If we're changing the payment date or switching subs, we need to set the trial period to the next payment date & installments to be the number of installments left
         } elseif ($is_payment_change || $is_switch_order || $is_synced_subscription) {
             $subscription_key = WC_Subscriptions_Manager::get_subscription_key($order_id, $product->id);
             // Give a free trial until the next payment date
             if ($is_switch_order) {
                 $next_payment_timestamp = get_post_meta($order->id, '_switched_subscription_first_payment_timestamp', true);
             } elseif ($is_synced_subscription) {
                 $next_payment_timestamp = WC_Subscriptions_Synchroniser::calculate_first_payment_date($product, 'timestamp');
             } else {
                 $next_payment_timestamp = WC_Subscriptions_Manager::get_next_payment_date($subscription_key, $order->user_id, 'timestamp');
             }
             // When the subscription is on hold
             if ($next_payment_timestamp != false && !empty($next_payment_timestamp)) {
                 $trial_until = self::calculate_trial_periods_until($next_payment_timestamp);
                 $subscription_trial_length = $trial_until['first_trial_length'];
                 $converted_periods['trial_period'] = $trial_until['first_trial_period'];
                 $second_trial_length = $trial_until['second_trial_length'];
                 $second_trial_period = $trial_until['second_trial_period'];
             } else {
//.........这里部分代码省略.........
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:101,代码来源:gateway-paypal-standard-subscriptions.php


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