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


PHP WC_Subscriptions_Manager::process_subscription_payment_failure_on_order方法代码示例

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


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

示例1: scheduled_subscription_payment

 /**
  * scheduled_subscription_payment
  *
  * Hooked to woocommerce_scheduled_subscription_payment_{gateway_id}
  * Completes recurring payments for a subscription
  */
 public function scheduled_subscription_payment($amount_to_charge, $order)
 {
     $this->log(__FUNCTION__, "Info: Beginning processing of scheduled payment for order {$order->id} for the amount of {$amount_to_charge}");
     $this->log(__FUNCTION__, "Info: Merchant ID = {$this->merchant_id}");
     // token is required
     $payment_method_token = get_post_meta($order->id, '_wc_paypal_braintree_payment_method_token', true);
     if (empty($payment_method_token)) {
         $this->log(__FUNCTION__, "Error: Payment method token is missing on order meta");
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
         return;
     }
     // as is the customer id
     $braintree_customer_id = get_post_meta($order->id, '_wc_paypal_braintree_customer_id', true);
     if (empty($braintree_customer_id)) {
         $this->log(__FUNCTION__, "Error: Braintree customer ID is missing on order meta");
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
         return;
     }
     // Create the gateway instance
     require_once dirname(__FILE__) . '/../braintree_sdk/lib/Braintree.php';
     $gateway = new Braintree_Gateway(array('accessToken' => $this->merchant_access_token));
     // Process the sale with the stored token and customer
     $sale_args = apply_filters('wc_gateway_paypal_braintree_sale_args', array('amount' => $amount_to_charge, 'paymentMethodToken' => $payment_method_token, 'recurring' => true, 'customerId' => $braintree_customer_id, 'channel' => 'WooThemes_BT', 'orderId' => $order->id, 'options' => array('submitForSettlement' => true, 'storeInVaultOnSuccess' => true)));
     try {
         $result = $gateway->transaction()->sale($sale_args);
     } catch (Exception $e) {
         $this->log(__FUNCTION__, 'Error: Unable to process scheduled payment. Reason: ' . $e->getMessage());
         return false;
     }
     if (!$result->success) {
         $this->log(__FUNCTION__, "Error: Unable to process scheduled payment: {$result->message}");
         return false;
     }
     $transaction_id = $result->transaction->id;
     $this->log(__FUNCTION__, "Info: Successfully processed schedule payment, transaction id = {$transaction_id}");
     WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
     $this->log(__FUNCTION__, "Info: Completed processing of scheduled payment for order {$order->id}");
     $order->add_order_note(sprintf(__('PayPal Braintree charge complete (Charge ID: %s)', 'woocommerce-gateway-paypal-braintree'), $transaction_id));
     $order->payment_complete($transaction_id);
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:46,代码来源:class-wc-gateway-paypal-braintree-subscription.php

示例2: process_scheduled_subscription_payment

 /**
  * process_scheduled_subscription_payment function.
  *
  * @param float $amount_to_charge The amount to charge.
  * @param WC_Order $order The WC_Order object of the order which the subscription was purchased in.
  * @param int $product_id The ID of the subscription product for which this payment relates.
  */
 public function process_scheduled_subscription_payment($amount_to_charge, $order, $product_id)
 {
     $result = $this->process_subscription_payment($order, $amount_to_charge);
     if (is_wp_error($result)) {
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
     } else {
         WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
     }
 }
开发者ID:bmcgowan,项目名称:woocommerce-payeezy,代码行数:16,代码来源:class-wc-payeezy-gateway-addons-deprecated.php

示例3: scheduled_subscription_payment

 /**
  * scheduled_subscription_payment function.
  *
  * @param $amount_to_charge float The amount to charge.
  * @param $order WC_Order The WC_Order object of the order which the subscription was purchased in.
  * @param $product_id int The ID of the subscription product for which this payment relates.
  * @access public
  * @return void
  */
 function scheduled_subscription_payment($amount_to_charge, $order, $product_id)
 {
     $result = $this->process_subscription_payment($order, $amount_to_charge);
     if (is_wp_error($result)) {
         $order->add_order_note(sprintf(__('eWAY subscription renewal failed - %s', 'wc-eway'), $this->response_message_lookup($result->get_error_message())));
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
     } else {
         WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
     }
 }
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:19,代码来源:class-wc-gateway-eway-subscriptions.php

示例4: update_subscription_status

 /**
  * Update subscription status.
  *
  * @param int    $order_id
  * @param string $invoice_status
  *
  * @return bool
  */
 protected function update_subscription_status($order_id, $invoice_status)
 {
     $order = new WC_Order($order_id);
     $invoice_status = strtolower($invoice_status);
     $order_updated = false;
     if ('paid' == $invoice_status) {
         $order->add_order_note(__('Iugu: Subscription paid successfully.', 'iugu-woocommerce'));
         // Payment complete
         $order->payment_complete();
         $order_updated = true;
     } elseif (in_array($invoice_status, array('canceled', 'refunded', 'expired'))) {
         $order->add_order_note(__('Iugu: Subscription payment failed.', 'iugu-woocommerce'));
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
         $order_updated = true;
     }
     // Allow custom actions when update the order status.
     do_action('iugu_woocommerce_update_order_status', $order, $invoice_status, $order_updated);
 }
开发者ID:jarsgt,项目名称:iugu-woocommerce,代码行数:26,代码来源:class-wc-iugu-bank-slip-addons-gateway.php

示例5: scheduled_subscription_payment

 /**
  * Process the subscription payment (manually... well via wp_cron)
  *
  * @param $amount the amount for this payment
  * @param $order the order ID
  * @param $product_id the product ID
  */
 function scheduled_subscription_payment($amount_to_charge, $order, $product_id)
 {
     $this->params = array();
     $this->params["amount"] = (int) ($amount_to_charge * 100);
     $this->params["test"] = $test_mode;
     $this->params["reference"] = $order->id . "-" . date("dmY");
     // Reference for order ID 123 will become 123-01022012
     $token = get_post_meta($order->id, "fatzebra_card_token", true);
     $this->params["card_token"] = $token;
     $ip = get_post_meta($post_id, "Customer IP Address", true);
     if (empty($ip)) {
         $ip = "127.0.0.1";
     }
     $this->params["customer_ip"] = $ip;
     $this->params["deferred"] = false;
     $result = $this->do_payment($this->params);
     if (is_wp_error($result)) {
         $error = "";
         $txn_id = "None";
         switch ($result->get_error_code()) {
             case 1:
                 // Non-200 response, so failed... (e.g. 401, 403, 500 etc).
                 $error = $result->get_error_message();
                 break;
             case 2:
                 // Gateway error (data etc)
                 $errors = $result->get_error_data();
                 $error = implode(", ", $errors);
                 error_log("WooCommerce Fat Zebra - Gateway Error: " . print_r($errors, true));
                 break;
             case 3:
                 // Declined - error data is array with keys: message, id
                 $error = $this->response_data->response->message;
                 $txn_id = $this->response_data->response->transaction_id;
                 break;
             case 4:
                 // Exception caught, something bad happened. Data is exception
             // Exception caught, something bad happened. Data is exception
             default:
                 $error = "Unknown - Error - See error log";
                 error_log("WC Fat Zebra (Subscriptions) - Unknown Error (exception): " . print_r($result->get_error_data(), true));
                 break;
         }
         // Add the error details and return
         $order->add_order_note(__("Subscription Payment Failed: " . $error . ". Transaction ID: " . $txn_id));
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
     } else {
         // Success! Returned is an array with the transaction ID etc
         // Update the subscription and return
         // Add a note to the order
         $order->add_order_note(__("Subscription Payment Successful. Transaction ID: " . $result["transaction_id"]));
         WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
     }
 }
开发者ID:atomixdesign,项目名称:FatZebra-WooCommerce,代码行数:61,代码来源:class-wc-fatzebra-masterpass.php

示例6: 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.', WC_Subscriptions::$text_domain));
                 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);
                 } else {
                     // 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);
                     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.', WC_Subscriptions::$text_domain));
                 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':
             if ('true' == get_post_meta($order_id, '_wcs_changing_payment_from_paypal_to_paypal', true)) {
                 // The flag has served its purpose
                 delete_post_meta($order_id, '_wcs_changing_payment_from_paypal_to_paypal');
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription cancellation request ignored as changing PayPal to PayPal, 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.', WC_Subscriptions::$text_domain));
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription cancelled for order ' . $order_id);
                 }
             }
             break;
         case 'subscr_eot':
             // Subscription ended, either due to failed payments or expiration
             $subscription_length = WC_Subscriptions_Order::get_subscription_length($order);
             // PayPal fires the 'subscr_eot' notice immediately if a subscription is only for one billing period, so ignore the request when we only have one billing period
             if (1 != $subscription_length && $subscription_length != WC_Subscriptions_Order::get_subscription_interval($order)) {
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription end-of-term for order ' . $order_id);
                 }
                 // Record subscription ended
                 $order->add_order_note(__('IPN subscription end-of-term for order.', WC_Subscriptions::$text_domain));
                 // Ended due to failed payments so cancel the subscription
                 if (gmdate('U') + 24 * 60 * 60 < strtotime(WC_Subscriptions_Manager::get_subscription_expiration_date(WC_Subscriptions_Manager::get_subscription_key($order->id), $order->customer_user))) {
                     WC_Subscriptions_Manager::cancel_subscriptions_for_order($order);
                 } else {
                     WC_Subscriptions_Manager::expire_subscriptions_for_order($order);
                 }
             }
             break;
         case 'subscr_failed':
             // Subscription sign up failed
             if (self::$debug) {
                 self::$log->add('paypal', 'IPN subscription payment failure for order ' . $order_id);
             }
             // Subscription Payment completed
             $order->add_order_note(__('IPN subscription payment failure.', WC_Subscriptions::$text_domain));
             // 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_id);
             break;
     }
     // Store the transaction ID to avoid handling requests duplicated by PayPal
     if (isset($transaction_details['ipn_track_id'])) {
         $handled_ipn_requests[] = $transaction_id;
         update_post_meta($order_id, '_paypal_ipn_tracking_ids', $handled_ipn_requests);
     }
     // Prevent default IPN handling for subscription txn_types
     exit;
 }
开发者ID:bulats,项目名称:chef,代码行数:101,代码来源:gateway-paypal-standard-subscriptions.php

示例7: process_subscription_payment_on_child_order

 /**
  * If the payment for a renewal order has previously failed and is then paid, we need to make sure the
  * subscription payment function is called.
  *
  * @param int $user_id The id of the user who purchased the subscription
  * @param string $subscription_key A subscription key of the form created by @see WC_Subscriptions_Manager::get_subscription_key()
  * @since 1.2
  */
 public static function process_subscription_payment_on_child_order($order_id, $payment_status = 'completed')
 {
     if (self::is_renewal($order_id, array('order_role' => 'child'))) {
         $child_order = new WC_Order($order_id);
         $parent_order = self::get_parent_order($child_order);
         $subscriptions_in_order = $child_order->get_items();
         // Should only be one subscription in the renewal order, but just in case
         foreach ($subscriptions_in_order as $item) {
             $item_id = WC_Subscriptions_Order::get_items_product_id($item);
             if (WC_Subscriptions_Order::is_item_subscription($parent_order, $item_id)) {
                 if ('failed' == $payment_status) {
                     // Don't duplicate renewal order
                     remove_action('processed_subscription_payment_failure', __CLASS__ . '::generate_failed_payment_renewal_order', 10, 2);
                     WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($parent_order->id, $item_id);
                     // But make sure orders are still generated for other payments in the same request
                     add_action('processed_subscription_payment_failure', __CLASS__ . '::generate_failed_payment_renewal_order', 10, 2);
                 } else {
                     // Don't duplicate renewal order
                     remove_action('processed_subscription_payment', __CLASS__ . '::generate_paid_renewal_order', 10, 2);
                     WC_Subscriptions_Manager::process_subscription_payments_on_order($parent_order->id, $item_id);
                     // But make sure orders are still generated for other payments in the same request
                     add_action('processed_subscription_payment', __CLASS__ . '::generate_paid_renewal_order', 10, 2);
                     // Reactivate the subscription - activate_subscription doesn't operate on child orders
                     $subscription_key = WC_Subscriptions_Manager::get_subscription_key($parent_order->id, $item_id);
                     WC_Subscriptions_Manager::reactivate_subscription($parent_order->customer_user, $subscription_key);
                 }
             }
         }
     }
 }
开发者ID:bulats,项目名称:chef,代码行数:38,代码来源:class-wc-subscriptions-renewal-order.php

示例8: 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);
                 }
             }
             break;
         case 'subscr_eot':
             // Subscription ended, either due to failed payments or expiration
             if (self::$debug) {
                 self::$log->add('paypal', 'IPN EOT request ignored for order ' . $order_id);
             }
             break;
         case 'subscr_failed':
             // Subscription sign up failed
             if (self::$debug) {
                 self::$log->add('paypal', 'IPN subscription payment failure for order ' . $order_id);
             }
             // Subscription Payment completed
             $order->add_order_note(__('IPN subscription payment failure.', 'woocommerce-subscriptions'));
             // 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);
             break;
     }
     // Store the transaction IDs to avoid handling requests duplicated by PayPal
     if (isset($transaction_details['ipn_track_id'])) {
         $handled_ipn_requests[] = $ipn_id;
         update_post_meta($order_id, '_paypal_ipn_tracking_ids', $handled_ipn_requests);
     }
     if (isset($transaction_details['txn_id'])) {
         $handled_transactions[] = $transaction_id;
         update_post_meta($order_id, '_paypal_transaction_ids', $handled_transactions);
     }
     // Prevent default IPN handling for subscription txn_types
     exit;
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:101,代码来源:gateway-paypal-standard-subscriptions.php

示例9: process_renewal_payment_1_5

 /**
  * Process subscription renewal
  *
  * @since 4.1.0
  * @param float $amount_to_charge subscription amount to charge, could include multiple renewals if they've previously failed and the admin has enabled it
  * @param WC_Order $order original order containing the subscription
  * @param int $product_id the subscription product id
  */
 public function process_renewal_payment_1_5($amount_to_charge, $order, $product_id)
 {
     try {
         // set order defaults
         $order = $this->get_gateway()->get_order($order->id);
         // zero-dollar subscription renewal. weird, but apparently it happens
         if (0 == $amount_to_charge) {
             // add order note
             $order->add_order_note(sprintf(_x('%s0 Subscription Renewal Approved', 'Supports direct credit card subscriptions', $this->get_gateway()->get_text_domain()), get_woocommerce_currency_symbol()));
             // update subscription
             WC_Subscriptions_Manager::process_subscription_payments_on_order($order, $product_id);
             return;
         }
         // set the amount to charge, ensuring that we have a decimal point, even if it's 1.00
         $order->payment_total = SV_WC_Helper::number_format($amount_to_charge);
         // required
         if (!$order->payment->token || !$order->get_user_id()) {
             throw new SV_WC_Payment_Gateway_Exception('Subscription Renewal: Payment Token or User ID is missing/invalid.');
         }
         // get the token, we've already verified it's good
         $token = $this->get_gateway()->get_payment_token($order->get_user_id(), $order->payment->token);
         // perform the transaction
         if ($this->get_gateway()->is_credit_card_gateway()) {
             if ($this->get_gateway()->perform_credit_card_charge()) {
                 $response = $this->get_gateway()->get_api()->credit_card_charge($order);
             } else {
                 $response = $this->get_gateway()->get_api()->credit_card_authorization($order);
             }
         } elseif ($this->get_gateway()->is_echeck_gateway()) {
             $response = $this->get_gateway()->get_api()->check_debit($order);
         }
         // check for success
         if ($response->transaction_approved()) {
             // order note based on gateway type
             if ($this->get_gateway()->is_credit_card_gateway()) {
                 $message = sprintf(_x('%s %s Subscription Renewal Payment Approved: %s ending in %s (expires %s)', 'Supports direct credit card subscriptions', $this->get_gateway()->get_text_domain()), $this->get_gateway()->get_method_title(), $this->get_gateway()->perform_credit_card_authorization() ? 'Authorization' : 'Charge', $token->get_card_type() ? $token->get_type_full() : 'card', $token->get_last_four(), $token->get_exp_month() . '/' . $token->get_exp_year());
             } elseif ($this->get_gateway()->is_echeck_gateway()) {
                 // there may or may not be an account type (checking/savings) available, which is fine
                 $message = sprintf(_x('%s Check Subscription Renewal Payment Approved: %s account ending in %s', 'Supports direct cheque subscriptions', $this->get_gateway()->get_text_domain()), $this->get_gateway()->get_method_title(), $token->get_account_type(), $token->get_last_four());
             }
             // add order note
             $order->add_order_note($message);
             // set transaction ID manually, WCS 1.5.x calls WC_Order::payment_complete() internally
             if ($response->get_transaction_id()) {
                 update_post_meta($order->id, '_transaction_id', $response->get_transaction_id());
             }
             // update subscription
             WC_Subscriptions_Manager::process_subscription_payments_on_order($order, $product_id);
         } else {
             // failure
             throw new SV_WC_Payment_Gateway_Exception(sprintf('%s: %s', $response->get_status_code(), $response->get_status_message()));
         }
     } catch (SV_WC_Plugin_Exception $e) {
         // don't mark the order as failed, Subscriptions will handle marking the renewal order as failed
         $order->add_order_note(sprintf(_x('%s Renewal Payment Failed (%s)', $this->get_gateway()->get_text_domain()), $this->get_gateway()->get_method_title(), $e->getMessage()));
         // update subscription
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
     }
 }
开发者ID:shredzjc,项目名称:wc-plugin-framework,代码行数:67,代码来源:class-sv-wc-payment-gateway-integration-subscriptions.php

示例10: 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

示例11: process_paypal_ipn_request

 /**
  * When a PayPal IPN messaged is received for a subscription transaction, 
  * check the transaction details and 
  *
  * @since 1.0
  */
 public static function process_paypal_ipn_request($transaction_details)
 {
     if (!in_array($transaction_details['txn_type'], array('subscr_signup', 'subscr_payment', 'subscr_cancel', 'subscr_eot', 'subscr_failed', 'subscr_modify'))) {
         return;
     }
     if (empty($transaction_details['custom']) || empty($transaction_details['invoice'])) {
         return;
     }
     // Get the $order_id & $order_key with backward compatibility
     extract(self::get_order_id_and_key($transaction_details));
     $transaction_details['txn_type'] = strtolower($transaction_details['txn_type']);
     if (self::$debug) {
         self::$log->add('paypal', 'Subscription Transaction Type: ' . $transaction_details['txn_type']);
     }
     if (self::$debug) {
         self::$log->add('paypal', 'Subscription transaction details: ' . print_r($transaction_details, true));
     }
     $order = new WC_Order($order_id);
     // We have an invalid $order_id, probably because invoice_prefix has changed since the subscription was first created, so get the
     if (!isset($order->id)) {
         $order_id = function_exists('woocommerce_get_order_id_by_order_key') ? woocommerce_get_order_id_by_order_key($order_key) : $wpdb->get_var("SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = '_order_key' AND meta_value = '{$order_key}'");
         $order = new WC_Order($order_id);
     }
     if ($order->order_key !== $order_key) {
         if (self::$debug) {
             self::$log->add('paypal', 'Subscription IPN Error: Order Key does not match invoice.');
         }
         return;
     }
     switch ($transaction_details['txn_type']) {
         case 'subscr_signup':
             // Store PayPal Details
             update_post_meta($order_id, 'Payer PayPal address', $transaction_details['payer_email']);
             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 Subscriber ID', $transaction_details['subscr_id']);
             // Payment completed
             $order->add_order_note(__('IPN subscription sign up completed.', WC_Subscriptions::$text_domain));
             if (self::$debug) {
                 self::$log->add('paypal', 'IPN subscription sign up completed for order ' . $order_id);
             }
             // When there is a free trial & no initial payment amount, we need to mark the order as paid and activate the subscription
             if (0 == WC_Subscriptions_Order::get_total_initial_payment($order) && WC_Subscriptions_Order::get_subscription_trial_length($order) > 0) {
                 $order->payment_complete();
                 WC_Subscriptions_Manager::activate_subscriptions_for_order($order);
             }
             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.', WC_Subscriptions::$text_domain));
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription payment completed for order ' . $order_id);
                 }
                 $subscriptions_in_order = WC_Subscriptions_Order::get_recurring_items($order);
                 $subscription_item = array_pop($subscriptions_in_order);
                 $subscription_key = WC_Subscriptions_Manager::get_subscription_key($order->id, $subscription_item['id']);
                 $subscription = WC_Subscriptions_Manager::get_subscription($subscription_key, $order->customer_user);
                 // First payment on order, process payment & activate subscription
                 if (empty($subscription['completed_payments'])) {
                     $order->payment_complete();
                     WC_Subscriptions_Manager::activate_subscriptions_for_order($order);
                 } else {
                     WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
                 }
             } elseif ('failed' == strtolower($transaction_details['payment_status'])) {
                 // Subscription Payment completed
                 $order->add_order_note(__('IPN subscription payment failed.', WC_Subscriptions::$text_domain));
                 if (self::$debug) {
                     self::$log->add('paypal', 'IPN subscription payment failed for order ' . $order_id);
                 }
                 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':
             if (self::$debug) {
                 self::$log->add('paypal', 'IPN subscription cancelled for order ' . $order_id);
             }
             // Subscription Payment completed
             $order->add_order_note(__('IPN subscription cancelled for order.', WC_Subscriptions::$text_domain));
             WC_Subscriptions_Manager::cancel_subscriptions_for_order($order);
             break;
         case 'subscr_eot':
             // Subscription ended, either due to failed payments or expiration
             // PayPal fires the 'subscr_eot' notice immediately if a subscription is only for one billing period, so ignore the request when we only have one billing period
//.........这里部分代码省略.........
开发者ID:edelkevis,项目名称:git-plus-wordpress,代码行数:101,代码来源:gateway-paypal-standard-subscriptions.php

示例12: process_subscription_renewal_payment

 /**
  * Process subscription renewal
  *
  * @since 2.0
  * @param float $amount_to_charge subscription amount to charge, could include multiple renewals if they've previously failed and the admin has enabled it
  * @param WC_Order $order original order containing the subscription
  * @throws Exception invalid or missing token
  */
 public function process_subscription_renewal_payment($amount_to_charge, WC_Order $order)
 {
     try {
         // set order defaults
         $order = $this->get_order($order->id);
         // set the amount to charge
         $order->amazon_order_total = $amount_to_charge;
         // add a timestamp to the order ID so Amazon doesn't consider it a duplicate of the original payment request
         $order->amazon_caller_reference .= '-' . time();
         // token is required
         if (!isset($order->wc_amazon_fps_token_id)) {
             throw new Exception(__('invalid or missing token', WC_Amazon_FPS::TEXT_DOMAIN));
         }
         parent::process_transaction($order);
     } catch (Exception $e) {
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
         $order->add_order_note(__('Amazon Subscription Renewal Transaction Failed: ' . $e->getMessage()));
     }
 }
开发者ID:Qualitair,项目名称:ecommerce,代码行数:27,代码来源:class-wc-gateway-amazon-fps-addons.php

示例13: process_renewal_payment

 /**
  * Process subscription renewal
  *
  * @since  1.4
  * @param float $amount_to_charge subscription amount to charge, could include
  *              multiple renewals if they've previously failed and the admin
  *              has enabled it
  * @param WC_Order $order original order containing the subscription
  * @param int $product_id the ID of the subscription product
  */
 public function process_renewal_payment($amount_to_charge, $order, $product_id = null)
 {
     require_once 'class-wc-realex-api.php';
     $realex_subscription_count = 0;
     if (is_numeric($order->realex_subscription_count) && $order->realex_subscription_count) {
         $realex_subscription_count = $order->realex_subscription_count;
     }
     // increment the subscription count so we don't get order number clashes
     $realex_subscription_count++;
     update_post_meta($order->id, '_realex_subscription_count', $realex_subscription_count);
     // set custom class member used by the realex gateway
     $order->payment_total = SV_WC_Helper::number_format($amount_to_charge);
     // zero-dollar subscription renewal.  weird, but apparently it happens -- only applicable to Subs 1.5.x
     if (!SV_WC_Plugin_Compatibility::is_wc_subscriptions_version_gte_2_0()) {
         if (0 == $order->payment_total) {
             // add order note
             $order->add_order_note(sprintf(__('%s0 Subscription Renewal Approved', 'woocommerce-gateway-realex'), get_woocommerce_currency_symbol()));
             // update subscription
             WC_Subscriptions_Manager::process_subscription_payments_on_order($order, $product_id);
             return;
         }
     }
     // This order is missing a tokenized card, lets see whether there's one available for the customer
     if (!get_post_meta($order->id, '_realex_cardref', true)) {
         $credit_cards = get_user_meta($order->get_user_id(), 'woocommerce_realex_cc', true);
         if (is_array($credit_cards)) {
             $card_ref = (object) current($credit_cards);
             $card_ref = $card_ref->ref;
             update_post_meta($order->id, '_realex_cardref', $card_ref);
             if (SV_WC_Plugin_Compatibility::is_wc_subscriptions_version_gte_2_0()) {
                 foreach (wcs_get_subscriptions_for_renewal_order($order) as $subscription) {
                     update_post_meta($subscription->id, '_realex_cardref', $card_ref);
                 }
             }
         }
     }
     // create the realex api client
     $realex_client = new Realex_API($this->get_endpoint_url(), $this->get_realvault_endpoint_url(), $this->get_shared_secret());
     // create the customer/cc tokens, and authorize the initial payment amount, if any
     $response = $this->authorize($realex_client, $order);
     if ($response && '00' == $response->result) {
         // add order note
         $order->add_order_note(sprintf(__('Credit Card Subscription Renewal Payment Approved (Payment Reference: %s) ', 'woocommerce-gateway-realex'), $response->pasref));
         // update subscription
         if (SV_WC_Plugin_Compatibility::is_wc_subscriptions_version_gte_2_0()) {
             $order->payment_complete((string) $response->pasref);
         } else {
             WC_Subscriptions_Manager::process_subscription_payments_on_order($order, $product_id);
         }
     } else {
         // generate the result message
         $message = __('Credit Card Subscription Renewal Payment Failed', 'woocommerce-gateway-realex');
         /* translators: Placeholders: %1$s - result, %2$s - result message */
         if ($response) {
             $message .= sprintf(__(' (Result: %1$s - "%2$s").', 'woocommerce-gateway-realex'), $response->result, $response->message);
         }
         $order->add_order_note($message);
         // update subscription
         if (!SV_WC_Plugin_Compatibility::is_wc_subscriptions_version_gte_2_0()) {
             WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
         }
     }
 }
开发者ID:BennyHudson,项目名称:eaton,代码行数:73,代码来源:class-wc-gateway-realex-subscriptions.php

示例14: scheduled_subscription_payment

 /**
  * Scheduled subscription payment.
  *
  * @since  2.0
  **/
 function scheduled_subscription_payment($amount_to_charge, $order)
 {
     // Check if order was created using this method
     if ($this->id == get_post_meta($order->id, '_payment_method', true)) {
         // Prevent hook from firing twice
         if (!get_post_meta($order->id, '_schedule_klarna_subscription_payment', true)) {
             $result = $this->process_subscription_payment($amount_to_charge, $order);
             if (false == $result) {
                 WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order);
             } else {
                 WC_Subscriptions_Manager::process_subscription_payments_on_order($order);
                 $order->payment_complete();
                 // Need to mark new order complete, so Subscription is marked as Active again
             }
             add_post_meta($order->id, '_schedule_klarna_subscription_payment', 'no', true);
         } else {
             delete_post_meta($order->id, '_schedule_klarna_subscription_payment', 'no');
         }
     }
 }
开发者ID:NoviumDesign,项目名称:polefitness,代码行数:25,代码来源:class-klarna-checkout.php

示例15: process_subscription_renewal_payment

 /**
  * Process subscription renewal
  *
  * @since 2.0
  * @param float $amount_to_charge subscription amount to charge, could include multiple renewals if they've previously failed and the admin has enabled it
  * @param \WC_Order $order original order containing the subscription
  * @param int $product_id the ID of the subscription product
  * @throws WC_Gateway_Braintree_Exception
  * @throws Exception
  */
 public function process_subscription_renewal_payment($amount_to_charge, $order, $product_id)
 {
     try {
         // set order defaults
         $order = $this->get_order($order->id);
         // set the amount to charge
         $order->braintree_order['amount'] = $amount_to_charge;
         // set credit card token
         $order->braintree_order['paymentMethodToken'] = get_post_meta($order->id, '_wc_braintree_cc_token', true);
         // required
         if (!$order->braintree_order['customerId'] || !$order->braintree_order['paymentMethodToken']) {
             throw new Exception(__('Subscription Renewal: Customer ID or Credit Card Token is missing.', WC_Braintree::TEXT_DOMAIN));
         }
         $response = Braintree_Transaction::sale($order->braintree_order);
         // check for success
         if ($response->success) {
             // add order note
             $order->add_order_note(sprintf(__('Braintree Subscription Renewal Payment Approved (Transaction ID: %s) ', WC_Braintree::TEXT_DOMAIN), $response->transaction->id));
             // update subscription
             WC_Subscriptions_Manager::process_subscription_payments_on_order($order, $product_id);
         } else {
             // failure
             throw new WC_Gateway_Braintree_Exception('transaction', $response);
         }
     } catch (WC_Gateway_Braintree_Exception $e) {
         // mark order as failed, which adds an order note for the admin and displays a generic "payment error" to the customer
         $this->mark_order_as_failed($order, $e->getMessage());
         // add detailed debugging information
         $this->add_debug_message($e->getErrors());
         // update subscription
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
     } catch (Braintree_Exception_Authorization $e) {
         $this->mark_order_as_failed($order, __('Authorization failed, ensure that your API key is correct and has permissions to create transactions.', WC_Braintree::TEXT_DOMAIN));
         // update subscription
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
     } catch (Exception $e) {
         $this->mark_order_as_failed($order, sprintf(__('%s - Error Type %s', WC_Braintree::TEXT_DOMAIN), $e->getMessage(), get_class($e)));
         // update subscription
         WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($order, $product_id);
     }
 }
开发者ID:keshvenderg,项目名称:cloudshop,代码行数:51,代码来源:class-wc-gateway-braintree-addons.php


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