/** * Allow Order editing for custom statuses * * @param bool $editable if the order is editable * @param \WC_order $order * @return bool if the order is editable for this status */ function sv_wc_order_status_manager_order_is_editable($editable, $order) { // list the slugs of all order statuses that should be editable. // Note 'pending', 'on-hold', 'auto-draft' are editable by default $editable_custom_statuses = array('packaging', 'awaiting-shipment'); if (in_array($order->get_status(), $editable_custom_statuses)) { $editable = true; } return $editable; }
/** * process_subscription_payment function. * * @param WC_order $order * @param integer $amount (default: 0) * @uses Simplify_BadRequestException * @return bool|WP_Error */ public function process_subscription_payment($order, $amount = 0) { if (0 == $amount) { // Payment complete $order->payment_complete(); return true; } if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce')); } $order_items = $order->get_items(); $order_item = array_shift($order_items); $subscription_name = sprintf(__('%s - Subscription for "%s"', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order_item['name']) . ' ' . sprintf(__('(Order #%s)', 'woocommerce'), $order->get_order_number()); $customer_id = get_post_meta($order->id, '_simplify_customer_id', true); if (!$customer_id) { return new WP_Error('simplify_error', __('Customer not found', 'woocommerce')); } try { // Charge the customer $payment = Simplify_Payment::createPayment(array('amount' => $amount * 100, 'customer' => $customer_id, 'description' => trim(substr($subscription_name, 0, 1024)), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->id, 'card.addressCity' => $order->billing_city, 'card.addressCountry' => $order->billing_country, 'card.addressLine1' => $order->billing_address_1, 'card.addressLine2' => $order->billing_address_2, 'card.addressState' => $order->billing_state, 'card.addressZip' => $order->billing_postcode)); } catch (Exception $e) { $error_message = $e->getMessage(); if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) { $error_message = ''; foreach ($e->getFieldErrors() as $error) { $error_message .= ' ' . $error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')'; } } $order->add_order_note(sprintf(__('Simplify payment error: %s', 'woocommerce'), $error_message)); return new WP_Error('simplify_payment_declined', $e->getMessage(), array('status' => $e->getCode())); } if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %s, Auth Code: %s)', 'woocommerce'), $payment->id, $payment->authCode)); return true; } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); return new WP_Error('simplify_payment_declined', __('Payment was declined - please try another card.', 'woocommerce')); } }
function woocommerce_atos_automatic_response($atts) { $atos = new woocommerce_atos(); if (isset($_POST['DATA'])) { $transauthorised = false; $data = escapeshellcmd(sanitize_text_field($_POST['DATA'])); $message = sprintf('message=%s', $data); $pathfile = sprintf('pathfile=%s', $atos->pathfile); $path_bin_response = $atos->path_bin_response; $result = exec("{$path_bin_response} {$pathfile} {$message}"); $results = explode('!', $result); $response = array('code' => $results[1], 'error' => $results[2], 'merchantid' => $results[3], 'merchantcountry' => $results[4], 'amount' => $results[5], 'transactionid' => $results[6], 'paymentmeans' => $results[7], 'transmissiondate' => $results[8], 'paymenttime' => $results[9], 'paymentdate' => $results[10], 'responsecode' => $results[11], 'paymentcertificate' => $results[12], 'authorisationid' => $results[13], 'currencycode' => $results[14], 'cardnumber' => $results[15], 'cvvflag' => $results[16], 'cvvresponsecode' => $results[17], 'bankresponsecode' => $results[18], 'complementarycode' => $results[19], 'complementaryinfo' => $results[20], 'returncontext' => $results[21], 'caddie' => $results[22], 'receiptcomplement' => $results[23], 'merchantlanguage' => $results[24], 'language' => $results[25], 'customerid' => $results[26], 'orderid' => $results[27], 'customeremail' => $results[28], 'customeripaddress' => $results[29], 'captureday' => $results[30], 'capturemode' => $results[31], 'data' => $results[32]); $order = new WC_order($response['orderid']); if ($response['responsecode'] == '' && $response['error'] == '') { $atos->msg['class'] = 'error'; $atos->msg['message'] = __('Thank you for shopping with us. However, the transaction has been declined.', 'woocommerce-atos'); } elseif ($response['responsecode'] != 0) { $atos->msg['class'] = 'error'; $atos->msg['message'] = __('Thank you for shopping with us. However, the transaction has been declined.', 'woocommerce-atos'); } else { if ($response['responsecode'] == 00) { $transauthorised = true; $order->update_status('processing'); $order->payment_complete($response['transactionid']); $order->add_order_note(__('Payment accepted by the bank', 'woocommerce-atos')); WC()->cart->empty_cart(); } } if ($transauthorised == false) { $order->update_status('failed'); $order->add_order_note('Failed'); $order->add_order_note($atos->msg['message']); } } else { // end of check post echo __('Precondition failed.', 'woocommerce-atos'); } }
/** * do payment function. * * @param WC_order $order * @param int $amount (default: 0) * @uses Simplify_BadRequestException * @return bool|WP_Error */ public function do_payment($order, $amount = 0, $token = array()) { if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce')); } try { // Charge the customer $data = array('amount' => $amount * 100, 'description' => sprintf(__('%1$s - Order #%2$s', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order->get_order_number()), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->get_id()); $data = array_merge($data, $token); $payment = Simplify_Payment::createPayment($data); } catch (Exception $e) { $error_message = $e->getMessage(); if ($e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors()) { $error_message = ''; foreach ($e->getFieldErrors() as $error) { $error_message .= ' ' . $error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')'; } } $order->add_order_note(sprintf(__('Simplify payment error: %s', 'woocommerce'), $error_message)); return new WP_Error('simplify_payment_declined', $e->getMessage(), array('status' => $e->getCode())); } if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %1$s, Auth Code: %2$s)', 'woocommerce'), $payment->id, $payment->authCode)); return true; } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); return new WP_Error('simplify_payment_declined', __('Payment was declined - please try another card.', 'woocommerce')); } }
/** * This function updates the database for the delivery details and adds delivery fields on the Order Received page, * WooCommerce->Orders when an order is placed for WooCommerce version greater than 2.0. */ function prdd_lite_order_item_meta($item_meta, $cart_item) { if (version_compare(WOOCOMMERCE_VERSION, "2.0.0") < 0) { return; } // Add the fields global $wpdb, $woocommerce; foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) { $_product = $values['data']; if (isset($values['prdd_lite_delivery'])) { $delivery = $values['prdd_lite_delivery']; } $quantity = $values['quantity']; $post_id = $this->prdd_lite_get_product_id($values['product_id']); $post_title = $_product->get_title(); $query = "SELECT order_item_id,order_id FROM `" . $wpdb->prefix . "woocommerce_order_items`\n\t\t\t\t\t\tWHERE order_id = %s AND order_item_name = %s"; $results = $wpdb->get_results($wpdb->prepare($query, $item_meta, $post_title)); $order_item_ids[] = $results[0]->order_item_id; $order_id = $results[0]->order_id; $order_obj = new WC_order($order_id); $details = $product_ids = array(); $order_items = $order_obj->get_items(); if (isset($values['prdd_lite_delivery'])) { $prdd_settings = get_post_meta($post_id, '_woo_prdd_lite_enable_delivery_date', true); $details = array(); if (isset($delivery[0]['delivery_date']) && $delivery[0]['delivery_date'] != "") { $name = "Delivery Date"; $date_select = $delivery[0]['delivery_date']; wc_add_order_item_meta($results[0]->order_item_id, $name, sanitize_text_field($date_select, true)); } if (array_key_exists('delivery_hidden_date', $delivery[0]) && $delivery[0]['delivery_hidden_date'] != "") { $date_booking = date('Y-m-d', strtotime($delivery[0]['delivery_hidden_date'])); wc_add_order_item_meta($results[0]->order_item_id, '_prdd_lite_date', sanitize_text_field($date_booking, true)); } } if (version_compare(WOOCOMMERCE_VERSION, "2.5") < 0) { continue; } else { // Code where the Delivery dates are not displayed in the customer new order email from WooCommerce version 2.5 $cache_key = WC_Cache_Helper::get_cache_prefix('orders') . 'item_meta_array_' . $results[0]->order_item_id; $item_meta_array = wp_cache_get($cache_key, 'orders'); if (false !== $item_meta_array) { $metadata = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value, meta_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d AND meta_key IN (%s,%s) ORDER BY meta_id", absint($results[0]->order_item_id), "Delivery Date", '_prdd_lite_date')); foreach ($metadata as $metadata_row) { $item_meta_array[$metadata_row->meta_id] = (object) array('key' => $metadata_row->meta_key, 'value' => $metadata_row->meta_value); } wp_cache_set($cache_key, $item_meta_array, 'orders'); } } } }
/** * process_subscription_payment function. * * @param WC_order $order * @param integer $amount (default: 0) * @return bool|WP_Error */ public function process_subscription_payment($order = '', $amount = 0) { $order_items = $order->get_items(); $order_item = array_shift($order_items); $subscription_name = sprintf(__('%s - Subscription for "%s"', 'woocommerce'), esc_html(get_bloginfo('name')), $order_item['name']) . ' ' . sprintf(__('(Order %s)', 'woocommerce'), $order->get_order_number()); if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce')); } $customer_id = get_post_meta($order->id, '_simplify_customer_id', true); if (!$customer_id) { return new WP_Error('simplify_error', __('Customer not found', 'woocommerce')); } // Charge the customer $payment = Simplify_Payment::createPayment(array('amount' => $amount * 100, 'customer' => $customer_id, 'description' => trim(substr($subscription_name, 0, 1024)), 'currency' => strtoupper(get_woocommerce_currency()), 'reference' => $order->id, 'card.addressCity' => $order->billing_city, 'card.addressCountry' => $order->billing_country, 'card.addressLine1' => $order->billing_address_1, 'card.addressLine2' => $order->billing_address_2, 'card.addressState' => $order->billing_state, 'card.addressZip' => $order->billing_postcode)); if ('APPROVED' == $payment->paymentStatus) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Simplify payment approved (ID: %s, Auth Code: %s)', 'woocommerce'), $payment->id, $payment->authCode)); return true; } else { $order->add_order_note(__('Simplify payment declined', 'woocommerce')); return new WP_Error('simplify_payment_declined', __('Payment was declined - please try another card.', 'woocommerce')); } }
function woocommerce_cancel_order($order_id, $order_item_id) { global $wpdb, $post; $array = array(); $order_obj = new WC_order($order_id); $order_items = $order_obj->get_items(); $select_query = "SELECT booking_id FROM `" . $wpdb->prefix . "booking_order_history`\n\t\t\t\tWHERE order_id='" . $order_id . "'"; $results = $wpdb->get_results($select_query); $post_id = woocommerce_get_order_item_meta($order_item_id, "_product_id", true); $booking_settings = get_post_meta($post_id, 'woocommerce_booking_settings', true); $checkin_date = woocommerce_get_order_item_meta($order_item_id, get_option('book.item-meta-date'), true); //print_r($results); $start_date = date("Y-m-d", strtotime($checkin_date)); if (isset($booking_settings['booking_enable_multiple_day']) && $booking_settings['booking_enable_multiple_day'] == 'on') { $checkout_date = woocommerce_get_order_item_meta($order_item_id, strip_tags(get_option('checkout.item-meta-date')), true); $end_date = date("Y-m-d", strtotime($checkout_date)); //echo "<pre>";print_r($results);echo "</pre>";exit; foreach ($results as $k => $v) { $b[] = $v->booking_id; $select_query_post = "SELECT post_id,id FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\tWHERE id='" . $v->booking_id . "' AND start_date='" . $start_date . "' AND end_date ='" . $end_date . "' AND post_id=" . $post_id; $results_post[] = $wpdb->get_results($select_query_post); } } else { if (isset($booking_settings['booking_enable_time']) && $booking_settings['booking_enable_time'] == 'on') { $timeslot = woocommerce_get_order_item_meta($order_item_id, get_option('book.item-meta-time'), true); $time_slot = explode("-", $timeslot); $from_time = date("G:i", strtotime($time_slot[0])); $to_time = date("G:i", strtotime($time_slot[1])); //echo "<pre>";print_r($results);echo "</pre>";exit; foreach ($results as $k => $v) { $b[] = $v->booking_id; $select_query_post = "SELECT post_id,id FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\tWHERE id='" . $v->booking_id . "' AND start_date='" . $start_date . "' AND from_time ='" . $from_time . "' AND to_time ='" . $to_time . "' AND post_id=" . $post_id; $results_post[] = $wpdb->get_results($select_query_post); } } else { foreach ($results as $k => $v) { $b[] = $v->booking_id; $select_query_post = "SELECT post_id,id FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\tWHERE id='" . $v->booking_id . "' AND start_date='" . $start_date . "' AND post_id=" . $post_id; $results_post[] = $wpdb->get_results($select_query_post); } } } foreach ($results_post as $k => $v) { $a[$v[0]->post_id][] = $v[0]->id; } $i = 0; foreach ($order_items as $item_key => $item_value) { $product_id = get_post_meta($item_value['product_id'], '_icl_lang_duplicate_of', true); if ($product_id == '' && $product_id == null) { $post_time = get_post($item_value['product_id']); $id_query = "SELECT ID FROM `" . $wpdb->prefix . "posts` WHERE post_date = '" . $post_time->post_date . "' ORDER BY ID LIMIT 1"; $results_post_id = $wpdb->get_results($id_query); if (isset($results_post_id)) { $product_id = $results_post_id[0]->ID; } else { $product_id = $item_value['product_id']; } //$duplicate_of = $item_value['product_id']; } //$product_id = $item_value['product_id']; if (in_array($product_id, (array) $array)) { } else { $booking_settings = get_post_meta($product_id, 'woocommerce_booking_settings', true); $qty = $item_value['qty']; $result = $a[$product_id]; $e = 0; foreach ($result as $k => $v) { $booking_id = $result[$e]; if ($booking_settings['booking_enable_multiple_day'] == 'on') { $select_data_query = "SELECT start_date,end_date FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\tWHERE id='" . $booking_id . "'"; $results_data = $wpdb->get_results($select_data_query); $j = 0; foreach ($results_data as $k => $v) { $start_date = $results_data[$j]->start_date; $end_date = $results_data[$j]->end_date; $sql_delete_query = "DELETE FROM `" . $wpdb->prefix . "booking_history` WHERE id = '" . $booking_id . "' AND start_date =\t'" . $start_date . "' AND end_date = '" . $end_date . "' "; $wpdb->query($sql_delete_query); $j++; } } else { if ($booking_settings['booking_enable_time'] == 'on') { $type_of_slot = apply_filters('bkap_slot_type', $product_id); if ($type_of_slot == 'multiple') { do_action('bkap_order_status_cancelled', $order_id, $item_value, $booking_id); } else { $select_data_query = "SELECT * FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\tWHERE id='" . $booking_id . "'"; $results_data = $wpdb->get_results($select_data_query); $j = 0; foreach ($results_data as $k => $v) { $start_date = $results_data[$j]->start_date; $from_time = $results_data[$j]->from_time; $to_time = $results_data[$j]->to_time; if ($from_time != '' && $to_time != '' || $from_time != '') { if ($to_time != '') { $query = "UPDATE `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\tSET available_booking = available_booking + " . $qty . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tid = '" . $booking_id . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\tfrom_time = '" . $from_time . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\tto_time = '" . $to_time . "'"; } else { $query = "UPDATE `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\tSET available_booking = available_booking + " . $qty . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tid = '" . $booking_id . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\tfrom_time = '" . $from_time . "'"; } $wpdb->query($query); } $j++; } } } else { $select_data_query = "SELECT * FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\tWHERE id='" . $booking_id . "'"; $results_data = $wpdb->get_results($select_data_query); $j = 0; foreach ($results_data as $k => $v) { $start_date = $results_data[$j]->start_date; $from_time = $results_data[$j]->from_time; $to_time = $results_data[$j]->to_time; $query = "UPDATE `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\tSET available_booking = available_booking + " . $qty . "\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tid = '" . $booking_id . "' AND\n\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\tfrom_time = '' AND\n\t\t\t\t\t\t\t\t\tto_time = ''"; $wpdb->query($query); } $j++; } } $e++; } } $i++; $array[] = $product_id; } }
/** * process_subscription_payment function. * * @param WC_order $order * @param int $amount (default: 0) * * @return bool|WP_Error */ public function process_subscription_payment($order = '', $amount = 0) { if ('yes' == $this->debug) { $this->log->add($this->id, 'Processing a subscription payment for order ' . $order->get_order_number()); } $charge = $this->api->create_charge($order); if (isset($charge['errors']) && !empty($charge['errors'])) { $error = is_array($charge['errors']) ? current($charge['errors']) : $charge['errors']; return new WP_Error('iugu_subscription_error', $error); } $payment_data = array_map('sanitize_text_field', array('pdf' => $charge['pdf'])); update_post_meta($order->id, '_iugu_wc_transaction_data', $payment_data); update_post_meta($order->id, __('Iugu Bank Slip URL', 'iugu-woocommerce'), $payment_data['pdf']); update_post_meta($order->id, '_transaction_id', sanitize_text_field($charge['invoice_id'])); // Save only in old versions. if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1.12', '<=')) { update_post_meta($order->id, __('Iugu Transaction details', 'iugu-woocommerce'), 'https://iugu.com/a/invoices/' . sanitize_text_field($charge['invoice_id'])); } $order_note = __('Iugu: The customer generated a bank slip, awaiting payment confirmation.', 'iugu-woocommerce'); if ('pending' == $order->get_status()) { $order->update_status('on-hold', $order_note); } else { $order->add_order_note($order_note); } return true; }
/** * process_subscription_payment function. * * @param WC_order $order * @param int $amount (default: 0) * * @return bool|WP_Error */ public function process_subscription_payment($order = '', $amount = 0) { if ('yes' == $this->debug) { $this->log->add($this->id, 'Processing a subscription payment for order ' . $order->get_order_number()); } $payment_method_id = get_post_meta($order->id, '_iugu_customer_payment_method_id', true); if (!$payment_method_id) { if ('yes' == $this->debug) { $this->log->add($this->id, 'Missing customer payment method ID in subscription payment for order ' . $order->get_order_number()); } return new WP_Error('iugu_subscription_error', __('Customer payment method not found!', 'iugu-woocommerce')); } $charge = $this->api->create_charge($order, array('customer_payment_method_id' => $payment_method_id)); if (isset($charge['errors']) && !empty($charge['errors'])) { $error = is_array($charge['errors']) ? current($charge['errors']) : $charge['errors']; return new WP_Error('iugu_subscription_error', $error); } update_post_meta($order->id, '_transaction_id', sanitize_text_field($charge['invoice_id'])); // Save only in old versions. if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1.12', '<=')) { update_post_meta($order->id, __('Iugu Transaction details', 'iugu-woocommerce'), 'https://iugu.com/a/invoices/' . sanitize_text_field($charge['invoice_id'])); } if (true == $charge['success']) { $order->add_order_note(__('Iugu: Subscription paid successfully by credit card.', 'iugu-woocommerce')); $order->payment_complete(); return true; } else { return new WP_Error('iugu_subscription_error', __('Iugu: Subscription payment failed. Credit card declined.', 'iugu-woocommerce')); } }
function child_transaction($type, $uid, $order_id, $amount, $reason = '') { global $woocommerce; $order = new WC_order($order_id); //get the uid from order and compare to md5 in the $_GET $post_uid = get_post_meta($order_id, '_uid', true); $check_uid = md5($post_uid); if ($check_uid != $uid) { exit(__('UID is not correct', 'woocommerce-begateway')); } $messages = array('void' => array('not_possible' => __('Wrong order status. Void is not possible.', 'woocommerce-begateway'), 'status' => __('Void status', 'woocommerce-begateway'), 'failed' => __('Void attempt failed', 'woocommerce-begateway'), 'success' => __('Payment voided', 'woocommerce-begateway')), 'capture' => array('not_possible' => __('Wrong order status. Capture is not possible.', 'woocommerce-begateway'), 'status' => __('Capture status', 'woocommerce-begateway'), 'failed' => __('Capture attempt failed', 'woocommerce-begateway'), 'success' => __('Payment captured', 'woocommerce-begateway')), 'refund' => array('not_possible' => __('Wrong order status. Refund is not possible.', 'woocommerce-begateway'), 'status' => __('Refund status', 'woocommerce-begateway'), 'failed' => __('Refund attempt failed', 'woocommerce-begateway'), 'success' => __('Payment refunded', 'woocommerce-begateway'))); //check order status is on hold exit if not if (in_array($type, array('capture', 'void')) && $order->status != 'on-hold') { exit($messages[$type]['not_possible']); } if (in_array($type, array('refund')) && $order->status != 'processing') { exit($messages[$type]['not_possible']); } // now send data to the server $klass = '\\beGateway\\' . ucfirst($type); $transaction = new $klass(); $transaction->setParentUid($post_uid); $transaction->money->setCurrency(get_woocommerce_currency()); $transaction->money->setAmount($amount); if ($type == 'refund') { if (isset($reason) && !empty($reason)) { $transaction->setReason($reason); } else { $transaction->setReason(__('Refunded from Woocommerce', 'woocommerce-begateway')); } } $response = $transaction->submit(); //determine status if success if ($response->isSuccess()) { if ($type == 'capture') { $order->payment_complete(); $order->add_order_note($messages[$type]['success'] . '. UID: ' . $response->getUid()); update_post_meta($order_id, '_uid', $response->getUid()); } elseif ($type == 'void') { $order->update_status('cancelled', $messages[$type]['success'] . '. UID: ' . $response->getUid()); } elseif ($type == 'refund') { $order->update_status('refunded', $messages[$type]['success'] . '. UID: ' . $response->getUid()); } if ('yes' == $this->debug) { $this->log->add('begateway', $messages[$type]['status'] . ': ' . $response->getMessage()); } update_post_meta($order_id, '_bt_admin_message', $messages[$type]['success']); } else { if ('yes' == $this->debug) { $this->log->add('begateway', $messages[$type]['failed'] . ': ' . $response->getMessage()); } update_post_meta($order_id, '_bt_admin_error', $messages[$type]['failed'] . ': ' . $response->getMessage()); } $location = get_post_meta($order_id, '_return_url', true); delete_post_meta($order_id, '_return_url', true); header('Location:' . $location); exit; }
function bkap_woocommerce_cancel_order($order_id) { global $wpdb, $post; $array = array(); $order_obj = new WC_order($order_id); $order_items = $order_obj->get_items(); $select_query = "SELECT booking_id FROM `" . $wpdb->prefix . "booking_order_history`\n\t\t\t\t\t\t\t\tWHERE order_id='" . $order_id . "'"; $results = $wpdb->get_results($select_query); foreach ($results as $k => $v) { $b[] = $v->booking_id; $select_query_post = "SELECT post_id,id FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\tWHERE id='" . $v->booking_id . "'"; $results_post[] = $wpdb->get_results($select_query_post); } //exit; if (isset($results_post) && count($results_post) > 0 && $results_post != false) { foreach ($results_post as $k => $v) { if (isset($v[0]->id)) { $a[$v[0]->post_id][] = $v[0]->id; } // $a[$v[0]->post_id][] = $v[0]->id; } } $i = 0; foreach ($order_items as $item_key => $item_value) { $product_id = get_post_meta($item_value['product_id'], '_icl_lang_duplicate_of', true); if ($product_id == '' && $product_id == null) { $post_time = get_post($item_value['product_id']); $id_query = "SELECT ID FROM `" . $wpdb->prefix . "posts` WHERE post_date = '" . $post_time->post_date . "' ORDER BY ID LIMIT 1"; $results_post_id = $wpdb->get_results($id_query); if (isset($results_post_id)) { $product_id = $results_post_id[0]->ID; } else { $product_id = $item_value['product_id']; } //$duplicate_of = $item_value['product_id']; } if (array_key_exists("variation_id", $item_value)) { $variation_id = $item_value['variation_id']; } else { $variation_id = ''; } if (in_array($product_id, (array) $array)) { } else { $booking_settings = get_post_meta($product_id, 'woocommerce_booking_settings', true); $qty = $item_value['qty']; if (isset($a[$product_id])) { $result = $a[$product_id]; } $e = 0; $from_time = ''; $to_time = ''; $date_date = ''; $end_date = ''; if (isset($result) && count($result) > 0 && $result != false) { foreach ($result as $k => $v) { $booking_id = $result[$e]; if (isset($booking_settings['booking_enable_multiple_day']) && $booking_settings['booking_enable_multiple_day'] == 'on') { $select_data_query = "SELECT start_date,end_date FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE id='" . $booking_id . "'"; $results_data = $wpdb->get_results($select_data_query); $j = 0; foreach ($results_data as $k => $v) { $start_date = $results_data[$j]->start_date; $end_date = $results_data[$j]->end_date; $sql_delete_query = "DELETE FROM `" . $wpdb->prefix . "booking_history` WHERE id = '" . $booking_id . "' AND start_date =\t'" . $start_date . "' AND end_date = '" . $end_date . "' "; $wpdb->query($sql_delete_query); $j++; } } else { if (isset($booking_settings['booking_enable_time']) && $booking_settings['booking_enable_time'] == 'on') { $type_of_slot = apply_filters('bkap_slot_type', $product_id); if ($type_of_slot == 'multiple') { do_action('bkap_order_status_cancelled', $order_id, $item_value, $booking_id); } else { $select_data_query = "SELECT * FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE id='" . $booking_id . "'"; $results_data = $wpdb->get_results($select_data_query); $j = 0; foreach ($results_data as $k => $v) { $start_date = $results_data[$j]->start_date; $from_time = $results_data[$j]->from_time; $to_time = $results_data[$j]->to_time; if ($from_time != '' && $to_time != '' || $from_time != '') { if ($to_time != '') { $query = "UPDATE `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tSET available_booking = available_booking + " . $qty . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tid = '" . $booking_id . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tfrom_time = '" . $from_time . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tto_time = '" . $to_time . "'"; $select = "SELECT * FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE post_id = '" . $product_id . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tfrom_time = '" . $from_time . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tto_time = '" . $to_time . "'"; $select_results = $wpdb->get_results($select); foreach ($select_results as $k => $v) { $details[$product_id] = $v; } } else { $query = "UPDATE `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tSET available_booking = available_booking + " . $qty . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tid = '" . $booking_id . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfrom_time = '" . $from_time . "'"; $select = "SELECT * FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE post_id = '" . $product_id . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tfrom_time = '" . $from_time . "'"; $select_results = $wpdb->get_results($select); foreach ($select_results as $k => $v) { $details[$product_id] = $v; } } $wpdb->query($query); } $j++; } } } else { $select_data_query = "SELECT * FROM `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\tWHERE id='" . $booking_id . "'"; $results_data = $wpdb->get_results($select_data_query); $j = 0; foreach ($results_data as $k => $v) { $start_date = $results_data[$j]->start_date; $from_time = $results_data[$j]->from_time; $to_time = $results_data[$j]->to_time; $query = "UPDATE `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\tSET available_booking = available_booking + " . $qty . "\n\t\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\tid = '" . $booking_id . "' AND\n\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\tfrom_time = '' AND\n\t\t\t\t\t\t\t\t\t\t\tto_time = ''"; $wpdb->query($query); } $j++; } } $e++; } } } $book_global_settings = json_decode(get_option('woocommerce_booking_global_settings')); $label = get_option("book.item-meta-date"); //print_r($item_value); //$date = str_replace("-","/",$item_value[$label]); $hidden_date = date('d-n-Y', strtotime($start_date)); //print_r($hidden_date); if (isset($booking_settings['booking_time_settings'][$hidden_date])) { $lockout_settings = $booking_settings['booking_time_settings'][$hidden_date]; } else { $lockout_settings = array(); } if (count($lockout_settings) > 0) { $week_day = date('l', strtotime($hidden_date)); //print_r($week_day); $weekdays = book_arrays('weekdays'); //print_r($weekdays); $weekday = array_search($week_day, $weekdays); if (isset($booking_settings['booking_time_settings'][$weekday])) { $lockout_settings = $booking_settings['booking_time_settings'][$weekday]; } else { $lockout_settings = array(); } //print_r($lockout_settings); } $from_lockout_time = explode(":", $from_time); if (isset($from_lockout_time[0])) { $from_hours = $from_lockout_time[0]; } else { $from_hours = ''; } if (isset($from_lockout_time[1])) { $from_minute = $from_lockout_time[1]; } else { $from_minute = ''; } if ($to_time != '') { $to_lockout_time = explode(":", $to_time); $to_hours = $to_lockout_time[0]; $to_minute = $to_lockout_time[1]; } else { $to_hours = ''; $to_minute = ''; } if (count($lockout_settings) > 0) { foreach ($lockout_settings as $l_key => $l_value) { if ($l_value['from_slot_hrs'] == $from_hours && $l_value['from_slot_min'] == $from_minute && $l_value['to_slot_hrs'] == $to_hours && $l_value['to_slot_min'] == $to_minute) { if (isset($l_value['global_time_check'])) { $global_timeslot_lockout = $l_value['global_time_check']; } else { $global_timeslot_lockout = ''; } //print_r($global_timeslot_lockout); } } } //print_r($book_global_settings); //print_r($lockout_settings);exit; if ($book_global_settings->booking_global_timeslot == 'on' || $global_timeslot_lockout == 'on') { $args = array('post_type' => 'product', 'posts_per_page' => -1); $product = query_posts($args); foreach ($product as $k => $v) { $product_ids[] = $v->ID; } //print_r($details); //print_r($product_ids);exit; foreach ($product_ids as $k => $v) { $duplicate_of = get_post_meta($v, '_icl_lang_duplicate_of', true); if ($duplicate_of == '' && $duplicate_of == null) { $post_time = get_post($v); $id_query = "SELECT ID FROM `" . $wpdb->prefix . "posts` WHERE post_date = '" . $post_time->post_date . "' ORDER BY ID LIMIT 1"; $results_post_id = $wpdb->get_results($id_query); if (isset($results_post_id)) { $duplicate_of = $results_post_id[0]->ID; } else { $duplicate_of = $v; } //$duplicate_of = $item_value['product_id']; } $booking_settings = get_post_meta($v, 'woocommerce_booking_settings', true); if (isset($booking_settings['booking_enable_time']) && $booking_settings['booking_enable_time'] == 'on') { //echo "ehere";exit; if (count($details) > 0) { if (!array_key_exists($duplicate_of, $details)) { foreach ($details as $key => $val) { //$booking_settings = get_post_meta($duplicate_of, 'woocommerce_booking_settings', true); //echo"<pre>";print_r($booking_settings);echo"</pre>";exit; $start_date = $val->start_date; $from_time = $val->from_time; $to_time = $val->to_time; if ($to_time != "") { $query = "UPDATE `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\tSET available_booking = available_booking + " . $qty . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE post_id = '" . $duplicate_of . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\tfrom_time = '" . $from_time . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\tto_time = '" . $to_time . "'"; $wpdb->query($query); //echo $query;exit; } else { $query = "UPDATE `" . $wpdb->prefix . "booking_history`\n\t\t\t\t\t\t\t\t\t\t\t\t\tSET available_booking = available_booking + " . $qty . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE post_id = '" . $duplicate_of . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tstart_date = '" . $start_date . "' AND\n\t\t\t\t\t\t\t\t\t\t\t\t\tfrom_time = '" . $from_time . "'"; //$wpdb->query( $query ); $wpdb->query($query); } } } } } } } $i++; $array[] = $product_id; } }
/** * Process the payment and return the result * * @param $order_id * * @return array */ public function process_payment($order_id) { $order = new WC_order($order_id); return array('result' => 'success', 'redirect' => $order->get_checkout_payment_url(true)); }
/** * process_subscription_payment function. * * @param WC_order $order * @param integer $amount (default: 0) * @return bool|WP_Error */ public function process_subscription_payment($order = '', $amount = 0) { $order_items = $order->get_items(); $order_item = array_shift($order_items); $subscription_name = sprintf(__('%s - Subscription for "%s"', 'woocommerce-payment-gateway-boilerplate'), esc_html(get_bloginfo('name')), $order_item['name']) . ' ' . sprintf(__('(Order %s)', 'woocommerce-payment-gateway-boilerplate'), $order->get_order_number()); if ($amount * 100 < 50) { return new WP_Error('simplify_error', __('Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce-payment-gateway-boilerplate')); } if ('APPROVED' == $payment['status']) { // Payment complete $order->payment_complete($payment->id); // Add order note $order->add_order_note(sprintf(__('Gateway name payment approved (ID: %s)', 'woocommerce-payment-gateway-boilerplate'), $payment['id'])); return true; } else { $order->add_order_note(__('Gateway name payment declined', 'woocommerce-payment-gateway-boilerplate')); return new WP_Error('gateway_name_payment_declined', __('Payment was declined - please try again.', 'woocommerce-payment-gateway-boilerplate')); } }
<!-- ******************************************************************** --> <?php wp_head(); ?> </head> <body <?php body_class(); ?> > <?php if (is_wc_endpoint_url('order-received')) { $order_id = wc_get_order_id_by_order_key($_GET['key']); $order1 = new WC_order($order_id); $order_items = array_values($order1->get_items()); $net_amount = $order_items[0]['line_subtotal']; $tax_amount = $order_items[0]['line_subtotal_tax']; $product_name = $order_items[0]['name']; $product_id = $order_items[0]['product_id']; $belboon = $_SESSION['belboon']; $url_home = home_url(); ?> <img src="https://www1.belboon.de/adtracking/sale/000021772.gif/oc=<?php echo $order_id; ?> &sale=<?php echo $net_amount; ?> &belboon=<?php