/**
  * @param int $order_id
  * @return array
  */
 public function process_payment($order_id)
 {
     // get order object
     $order = new WC_Order($order_id);
     // update pos_cash data
     $data = WC_POS_Server::get_raw_data();
     $cashback = isset($data['payment_details']['pos-cashback']) ? wc_format_decimal($data['payment_details']['pos-cashback']) : 0;
     if ($cashback !== 0) {
         // add order meta
         update_post_meta($order_id, '_pos_card_cashback', $cashback);
         // add cashback as fee line item
         // TODO: this should be handled by $order->add_fee after WC 2.2
         $item_id = wc_add_order_item($order_id, array('order_item_name' => __('Cashback', 'woocommerce-pos'), 'order_item_type' => 'fee'));
         if ($item_id) {
             wc_add_order_item_meta($item_id, '_line_total', $cashback);
             wc_add_order_item_meta($item_id, '_line_tax', 0);
             wc_add_order_item_meta($item_id, '_line_subtotal', $cashback);
             wc_add_order_item_meta($item_id, '_line_subtotal_tax', 0);
             wc_add_order_item_meta($item_id, '_tax_class', 'zero-rate');
         }
         // update the order total to include fee
         $order_total = get_post_meta($order_id, '_order_total', true);
         $order_total += $cashback;
         update_post_meta($order_id, '_order_total', $order_total);
     }
     // payment complete
     $order->payment_complete();
     // success
     return array('result' => 'success');
 }
Beispiel #2
0
 public function process_payment($order_id)
 {
     // get order object
     $order = new WC_Order($order_id);
     // update pos_cash data
     $data = WC_POS_Server::get_raw_data();
     $tendered = isset($data['payment_details']['pos-cash-tendered']) ? wc_format_decimal($data['payment_details']['pos-cash-tendered']) : 0;
     $change = isset($data['payment_details']['pos-cash-change']) ? wc_format_decimal($data['payment_details']['pos-cash-change']) : 0;
     update_post_meta($order_id, '_pos_cash_amount_tendered', $tendered);
     update_post_meta($order_id, '_pos_cash_change', $change);
     // payment complete
     $order->payment_complete();
     // Return thankyou redirect
     return array('result' => 'success');
 }
 /**
  * Returns payload for any request for testing
  */
 public function test_http_methods()
 {
     WC_POS_Server::response(array('method' => strtolower($_SERVER['REQUEST_METHOD']), 'payload' => WC_POS_Server::get_raw_data()));
 }
 /**
  * @return array|bool|mixed|void|WP_Error
  */
 private function process_admin_settings()
 {
     // validate
     if (!isset($_GET['id'])) {
         return new WP_Error('woocommerce_pos_settings_error', __('There is no settings id', 'woocommerce-pos'), array('status' => 400));
     }
     $id = $_GET['id'];
     $data = WC_POS_Server::get_raw_data();
     // special case: gateway_
     $gateway_id = preg_replace('/^gateway_/', '', strtolower($id), 1, $count);
     if ($count) {
         $handler = new WC_POS_Admin_Settings_Gateways($gateway_id);
         // else, find handler by id
     } else {
         $handlers = (array) self::handlers();
         if (!isset($handlers[$id])) {
             return new WP_Error('woocommerce_pos_settings_error', sprintf(__('No handler found for %s settings', 'woocommerce-pos'), $_GET['id']), array('status' => 400));
         }
         $handler = new $handlers[$id]();
     }
     // Compatibility for clients that can't use PUT/PATCH/DELETE
     $method = strtoupper($_SERVER['REQUEST_METHOD']);
     if (isset($_GET['_method'])) {
         $method = strtoupper($_GET['_method']);
     } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
         $method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
     }
     // bump IDB version
     if (isset($data['bump_idb_version']) && $data['bump_idb_version']) {
         self::bump_idb_version();
         unset($data['bump_idb_version']);
     }
     // get
     if ($method === 'GET') {
         return $handler->get();
     }
     // set
     if ($method === 'POST' || $method === 'PUT') {
         return $handler->set($data);
     }
     // delete
     if ($method === 'DELETE') {
         return $handler->delete($data);
     }
     return new WP_Error('woocommerce_pos_cannot_' . $method . '_' . $id, __('Settings error', 'woocommerce-pos'), array('status' => 405));
 }