/**
  * Process the captured payment when changing order status to completed
  *
  * @access      public
  * @param       int $order_id
  * @return      mixed
  */
 public function order_status_completed($order_id = null)
 {
     if (!$order_id) {
         $order_id = $_POST['order_id'];
     }
     if (get_post_meta($order_id, 'capture', true)) {
         $params = array();
         if (isset($_POST['amount'])) {
             $params['amount'] = round($_POST['amount']);
         }
         $transaction_id = get_post_meta($order_id, '_transaction_id', true);
         $charge = S4WC_API::capture_charge($transaction_id, $params);
         return $charge;
     }
 }
 /**
  * Process the captured payment when changing order status to completed
  *
  * @access      public
  * @param       int $order_id
  * @return      mixed
  */
 public function order_status_completed($order_id = null)
 {
     if (!$order_id) {
         $order_id = $_POST['order_id'];
     }
     // `_s4wc_capture` added in 1.35, let `capture` last for a few more updates before removing
     if (get_post_meta($order_id, '_s4wc_capture', true) || get_post_meta($order_id, 'capture', true)) {
         $order = new WC_Order($order_id);
         $params = array('amount' => isset($_POST['amount']) ? $_POST['amount'] : $order->order_total * 100, 'expand[]' => 'balance_transaction');
         try {
             $charge = S4WC_API::capture_charge($order->transaction_id, $params);
             if ($charge) {
                 $order->add_order_note(sprintf(__('%s payment captured.', 'stripe-for-woocommerce'), get_class($this)));
                 // Save Stripe fee
                 if (isset($charge->balance_transaction) && isset($charge->balance_transaction->fee)) {
                     $stripe_fee = number_format($charge->balance_transaction->fee / 100, 2, '.', '');
                     update_post_meta($order_id, 'Stripe Fee', $stripe_fee);
                 }
             }
         } catch (Exception $e) {
             $order->add_order_note(sprintf(__('%s payment failed to capture. %s', 'stripe-for-woocommerce'), get_class($this), $this->get_error_message($e)));
         }
     }
 }