/** * @action woocommerce_order_details_after_order_table * * @param WC_Order $order */ public static function iamport_order_detail(\WC_Order $order) { $checkout_methods = WSKL_Payment_Gates::get_checkout_methods('iamport'); $pay_method = $order->iamport_paymethod; $receipt_url = $order->iamport_receipt_url; $vbank_name = $order->iamport_vbank_name; $vbank_num = $order->iamport_vbank_num; $vbank_date = $order->iamport_vbank_date; $transction_id = $order->get_transaction_id(); ob_start(); switch ($pay_method) { case 'card': $pay_method_text = $checkout_methods['credit']; include_once WSKL_PATH . '/includes/lib/iamport/template-simple.php'; break; case 'trans': $pay_method_text = $checkout_methods['remit']; include_once WSKL_PATH . '/includes/lib/iamport/template-simple.php'; break; case 'phone': $pay_method_text = $checkout_methods['mobile']; include_once WSKL_PATH . '/includes/lib/iamport/template-simple.php'; break; case 'vbank': $pay_method_text = $checkout_methods['virtual']; include_once WSKL_PATH . '/includes/lib/iamport/template-vbank.php'; break; case 'kakao': $pay_method_text = $checkout_methods['kakao_pay']; include_once WSKL_PATH . '/includes/lib/iamport/template-simple.php'; break; } ob_end_flush(); }
/** * Get a link to the transaction on the 3rd party gateway size (if applicable) * * @param WC_Order $order the order object * @return string transaction URL, or empty string */ public function get_transaction_url($order) { $return_url = ''; $transaction_id = $order->get_transaction_id(); if (!empty($this->view_transaction_url) && !empty($transaction_id)) { $return_url = sprintf($this->view_transaction_url, $transaction_id); } return apply_filters('woocommerce_get_transaction_url', $return_url, $order, $this); }
/** * Get refund request args * @param WC_Order $order * @param float $amount * @param string $reason * @return array */ public static function get_request($order, $amount = null, $reason = '') { $request = array('VERSION' => '84.0', 'SIGNATURE' => self::$api_signature, 'USER' => self::$api_username, 'PWD' => self::$api_password, 'METHOD' => 'RefundTransaction', 'TRANSACTIONID' => $order->get_transaction_id(), 'NOTE' => html_entity_decode(wc_trim_string($reason, 255), ENT_NOQUOTES, 'UTF-8'), 'REFUNDTYPE' => 'Full'); if (!is_null($amount)) { $request['AMT'] = number_format($amount, 2, '.', ''); $request['CURRENCYCODE'] = $order->get_order_currency(); $request['REFUNDTYPE'] = 'Partial'; } return apply_filters('woocommerce_paypal_refund_request', $request, $order, $amount, $reason); }
/** * Refund an order. * * @throws \PayPal_API_Exception * * @param WC_Order $order Order to refund * @param float $amount Amount to refund * @param string $refundType Type of refund (Partial or Full) * @param string $reason Reason to refund * @param string $current Currency of refund * * @return null|string If exception is thrown, null is returned. Otherwise * ID of refund transaction is returned. */ public static function refund_order($order, $amount, $refundType, $reason, $currency) { // add refund params $params['TRANSACTIONID'] = $order->get_transaction_id(); $params['REFUNDTYPE'] = $refundType; $params['AMT'] = $amount; $params['CURRENCYCODE'] = $currency; $params['NOTE'] = $reason; // do API call $response = wc_gateway_ppec()->client->refund_transaction($params); // look at ACK to see if success or failure // if success return the transaction ID of the refund // if failure then do 'throw new PayPal_API_Exception( $response );' if ('Success' == $response['ACK'] || 'SuccessWithWarning' == $response['ACK']) { return $response['REFUNDTRANSACTIONID']; } else { throw new PayPal_API_Exception($response); } }
/** * Can the order be refunded via PayPal? * @param WC_Order $order * @return bool */ public function can_refund_order($order) { return $order && $order->get_transaction_id(); }
/** * Test: get_transaction_id */ function test_get_transaction_id() { $object = new WC_Order(); $set_to = '12345'; $object->set_transaction_id($set_to); $this->assertEquals($set_to, $object->get_transaction_id()); }
function orderpost($orderId) { global $wpdb; $testMode = get_option('linksync_test'); $LAIDKey = get_option('linksync_laid'); $apicall = new linksync_class($LAIDKey, $testMode); //Checking for already sent Order $sentOrderIds = get_option('linksync_sent_order_id'); if (isset($sentOrderIds)) { if (!empty($sentOrderIds)) { $order_id_array = unserialize($sentOrderIds); } else { $order_id_array = array(); } if (!in_array($orderId, $order_id_array)) { $order = new WC_Order($orderId); if ($order->post_status == get_option('order_status_wc_to_vend')) { update_option('linksync_sent_order_id', serialize(array_merge($order_id_array, array($orderId)))); $order_no = $order->get_order_number(); if (strpos($order_no, '#') !== false) { $order_no = str_replace('#', '', $order_no); } $get_total = $order->get_total(); $get_user = $order->get_user(); $comments = $order->post->post_excerpt; $primary_email_address = $get_user->data->user_email; $currency = $order->get_order_currency(); $shipping_method = $order->get_shipping_method(); $order_total = $order->get_order_item_totals(); $transaction_id = $order->get_transaction_id(); $taxes_included = false; $total_discount = $order->get_total_discount(); $total_quantity = 0; $registerDb = get_option('wc_to_vend_register'); $vend_uid = get_option('wc_to_vend_user'); $total_tax = $order->get_total_tax(); // Geting Payment object details if (isset($order_total['payment_method']['value']) && !empty($order_total['payment_method']['value'])) { $wc_payment = get_option('wc_to_vend_payment'); if (isset($wc_payment) && !empty($wc_payment)) { $total_payments = explode(",", $wc_payment); foreach ($total_payments as $mapped_payment) { $exploded_mapped_payment = explode("|", $mapped_payment); if (isset($exploded_mapped_payment[1]) && !empty($exploded_mapped_payment[1]) && isset($exploded_mapped_payment[0]) && !empty($exploded_mapped_payment[0])) { if ($exploded_mapped_payment[1] == $order_total['payment_method']['value']) { $vend_payment_data = explode("%%", $exploded_mapped_payment[0]); if (isset($vend_payment_data[0])) { $payment_method = $vend_payment_data[0]; } if (isset($vend_payment_data[1])) { $payment_method_id = $vend_payment_data[1]; } break; } } } } $payment = array("retailer_payment_type_id" => isset($payment_method_id) ? $payment_method_id : null, "amount" => isset($get_total) ? $get_total : 0, "method" => isset($payment_method) ? $payment_method : null, "transactionNumber" => isset($transaction_id) ? $transaction_id : null); } $export_user_details = get_option('wc_to_vend_export'); if (isset($export_user_details) && !empty($export_user_details)) { if ($export_user_details == 'customer') { //woocommerce filter $billingAddress_filter = apply_filters('woocommerce_order_formatted_billing_address', array('firstName' => $order->billing_first_name, 'lastName' => $order->billing_last_name, 'phone' => $order->billing_phone, 'street1' => $order->billing_address_1, 'street2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postalCode' => $order->billing_postcode, 'country' => $order->billing_country, 'company' => $order->billing_company, 'email_address' => $order->billing_email), $order); $billingAddress = array('firstName' => $billingAddress_filter['firstName'], 'lastName' => $billingAddress_filter['lastName'], 'phone' => $billingAddress_filter['phone'], 'street1' => $billingAddress_filter['street1'], 'street2' => $billingAddress_filter['street2'], 'city' => $billingAddress_filter['city'], 'state' => $billingAddress_filter['state'], 'postalCode' => $billingAddress_filter['postalCode'], 'country' => $billingAddress_filter['country'], 'company' => $billingAddress_filter['company'], 'email_address' => $billingAddress_filter['email_address']); $deliveryAddress_filter = apply_filters('woocommerce_order_formatted_shipping_address', array('firstName' => $order->shipping_first_name, 'lastName' => $order->shipping_last_name, 'phone' => $order->shipping_phone, 'street1' => $order->shipping_address_1, 'street2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postalCode' => $order->shipping_postcode, 'country' => $order->shipping_country, 'company' => $order->shipping_company), $order); $deliveryAddress = array('firstName' => $deliveryAddress_filter['firstName'], 'lastName' => $deliveryAddress_filter['lastName'], 'phone' => $deliveryAddress_filter['phone'], 'street1' => $deliveryAddress_filter['street1'], 'street2' => $deliveryAddress_filter['street2'], 'city' => $deliveryAddress_filter['city'], 'state' => $deliveryAddress_filter['state'], 'postalCode' => $deliveryAddress_filter['postalCode'], 'country' => $deliveryAddress_filter['country'], 'company' => $deliveryAddress_filter['company']); $primary_email = isset($primary_email_address) ? $primary_email_address : $billingAddress['email_address']; unset($billingAddress['email_address']); } } $vend_user_detail = get_option('wc_to_vend_user'); if (isset($vend_user_detail) && !empty($vend_user_detail)) { $user = explode('|', $vend_user_detail); $vend_uid = isset($user[0]) ? $user[0] : null; $vend_username = isset($user[1]) ? $user[1] : null; } //Ordered product(s) $items = $order->get_items(); $taxes = $order->get_taxes(); foreach ($items as $item) { foreach ($taxes as $tax_label) { $sql = mysql_query("SELECT tax_rate_id FROM `" . $wpdb->prefix . "woocommerce_tax_rates` WHERE tax_rate_name='" . $tax_label['label'] . "' AND tax_rate_class='" . $item['item_meta']['_tax_class'][0] . "'"); if (mysql_num_rows($sql) != 0) { $tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]); if ($tax_classes['result'] == 'success') { $vend_taxes = explode('/', $tax_classes['tax_classes']); } } } $taxId = isset($vend_taxes[0]) ? $vend_taxes[0] : null; $taxName = isset($vend_taxes[1]) ? $vend_taxes[1] : null; $taxRate = isset($vend_taxes[2]) ? $vend_taxes[2] : null; if (isset($item['variation_id']) && !empty($item['variation_id'])) { $product_id = $item['variation_id']; } else { $product_id = $item['product_id']; } $pro_object = new WC_Product($product_id); $itemtotal = (double) $item['item_meta']['_line_subtotal'][0]; if (isset($item['line_subtotal']) && !empty($item['line_subtotal'])) { $product_amount = (double) ($item['line_subtotal'] / $item['qty']); } $discount = (double) $item['item_meta']['_line_subtotal'][0] - (double) $item['item_meta']['_line_total'][0]; if (isset($discount) && !empty($discount)) { $discount = (double) ($discount / $item['qty']); } #---------Changes--------# //Product Amount = product org amount - discount amount $product_total_amount = (double) $product_amount - (double) $discount; $product_sku = $pro_object->get_sku(); if (isset($product_total_amount) && isset($taxRate) && !empty($product_total_amount) && !empty($taxRate)) { $taxValue = $product_total_amount * $taxRate; } $products[] = array('sku' => $product_sku, 'title' => $item['name'], 'price' => $product_total_amount, 'quantity' => $item['qty'], 'discountAmount' => isset($discount) ? $discount : 0, 'taxName' => isset($taxName) ? $taxName : null, 'taxId' => isset($taxId) ? $taxId : null, 'taxRate' => isset($taxRate) ? $taxRate : null, 'taxValue' => isset($taxValue) ? $taxValue : null, 'discountTitle' => isset($discountTitle) ? $discountTitle : 'sale'); $total_quantity += $item['qty']; unset($taxId); unset($taxName); unset($taxRate); unset($taxValue); } #---------Discount-----# // if (isset($total_discount) && !empty($total_discount)) { // $taxes_Discount = $apicall->linksync_getTaxes(); // if (isset($taxes_Discount) && !empty($taxes_Discount)) { // if (!isset($taxes_Discount['errorCode'])) { // if (isset($taxes_Discount['taxes'])) { // foreach ($taxes_Discount['taxes'] as $select_tax) { // if ($select_tax['name'] == 'GST') { // $discountTaxName = $select_tax['name']; // $discountTaxId = $select_tax['id']; // $discountTaxRate = $select_tax['rate']; // } // } // } // } // } // if (isset($total_discount)) { // if (isset($discountTaxRate) && !empty($discountTaxRate)) { // $taxValue_discount = $discountTaxRate * $total_discount; // } // } // $products[] = array( // "price" => isset($total_discount) ? $total_discount : null, // "quantity" => 1, // "sku" => "vend-discount", // 'taxName' => isset($discountTaxName) ? $discountTaxName : null, // 'taxId' => isset($discountTaxId) ? $discountTaxId : null, // 'taxRate' => isset($discountTaxRate) ? $discountTaxRate : null, // 'taxValue' => isset($taxValue_discount) ? $taxValue_discount : null // ); // $products[] = array( // "price" => isset($total_discount) ? $total_discount : null, // "quantity" => 1, // "sku" => "vend-discount", // 'taxName' => null, // 'taxId' => null, // 'taxRate' => null, // 'taxValue' => null // ); // } #----------Shipping------------# foreach ($taxes as $tax_label) { if (isset($tax_label['shipping_tax_amount']) && !empty($tax_label['shipping_tax_amount'])) { $tax_classes = linksync_tax_classes($tax_label['label'], $item['item_meta']['_tax_class'][0]); if ($tax_classes['result'] == 'success') { $vend_taxes = explode('/', $tax_classes['tax_classes']); $taxId_shipping = isset($vend_taxes[0]) ? $vend_taxes[0] : null; $taxName_shipping = isset($vend_taxes[1]) ? $vend_taxes[1] : null; $taxRate_shipping = isset($vend_taxes[2]) ? $vend_taxes[2] : null; } } } if (isset($shipping_method) && !empty($shipping_method)) { $shipping_cost = $order->get_total_shipping(); $shipping_with_tax = $order->get_shipping_tax(); if ($shipping_with_tax > 0) { if (isset($shipping_cost) && isset($taxRate_shipping) && !empty($shipping_cost) && !empty($taxRate_shipping)) { $taxValue_shipping = $shipping_cost * $taxRate_shipping; } } $products[] = array("price" => isset($shipping_cost) ? $shipping_cost : null, "quantity" => 1, "sku" => "shipping", 'taxName' => isset($taxName_shipping) ? $taxName_shipping : null, 'taxId' => isset($taxId_shipping) ? $taxId_shipping : null, 'taxRate' => isset($taxRate_shipping) ? $taxRate_shipping : null, 'taxValue' => isset($taxValue_shipping) ? $taxValue_shipping : null); } //UTC Time date_default_timezone_set("UTC"); $order_created = date("Y-m-d H:i:s", time()); $OrderArray = array('uid' => isset($vend_uid) ? $vend_uid : null, 'created' => isset($order_created) ? $order_created : null, "orderId" => isset($order_no) ? $order_no : null, "source" => "WooCommerce", 'register_id' => isset($registerDb) ? $registerDb : null, 'user_name' => isset($vend_username) ? $vend_username : null, 'primary_email' => isset($primary_email) && !empty($primary_email) ? $primary_email : null, 'total' => isset($get_total) ? $get_total : 0, 'total_tax' => isset($total_tax) ? $total_tax : 0, 'comments' => isset($comments) ? $comments : null, 'taxes_included' => $taxes_included, 'currency' => isset($currency) ? $currency : 'USD', 'shipping_method' => isset($shipping_method) ? $shipping_method : null, 'payment' => isset($payment) && !empty($payment) ? $payment : null, 'products' => isset($products) && !empty($products) ? $products : null, 'payment_type_id' => isset($payment_method_id) ? $payment_method_id : null, 'billingAddress' => isset($billingAddress) && !empty($billingAddress) ? $billingAddress : null, 'deliveryAddress' => isset($deliveryAddress) && !empty($deliveryAddress) ? $deliveryAddress : null); $json = json_encode($OrderArray); $apicall->linksync_postOrder($json); linksync_class::add('Order Sync Woo to Vend', 'success', 'Woo Order no:' . $order_no, $LAIDKey); } } else { linksync_class::add('Order Sync Woo to Vend', 'Error', 'Already Sent Order', $LAIDKey); } } }
/** * Can the order be refunded via PayTPV? * @param WC_Order $order * @return bool */ public function can_refund_order($order) { return $order && $order->get_transaction_id() && get_post_meta((int) $order->id, 'PayTPV_IdUser', true); }
/** * Can the order be refunded? * * @param WC_Order $order * * @return bool */ public function can_refund_order($order) { return $order && $order->payment_method == 'fac' && $order->get_transaction_id(); }
/** * Process a refund in WooCommerce 2.2 or later. * * @param int $order_id * @param float $amount * @param string $reason * * @return bool|WP_Error True or false based on success, or a WP_Error object. */ public function process_refund($order_id, $amount = null, $reason = '') { $order = new WC_Order($order_id); if (!$order || !$order->get_transaction_id()) { return false; } $diff = strtotime($order->order_date) - strtotime(current_time('mysql')); $days = absint($diff / (60 * 60 * 24)); $limit = 120; if ($limit > $days) { $tid = $order->get_transaction_id(); $amount = wc_format_decimal($amount); $response = $this->api->do_transaction_cancellation($order, $tid, $order->id . '-' . time(), $amount); // Already canceled. if (isset($response->mensagem) && !empty($response->mensagem)) { $order->add_order_note(__('Cielo', 'cielo-woocommerce') . ': ' . sanitize_text_field($response->mensagem)); return new WP_Error('cielo_refund_error', sanitize_text_field($response->mensagem)); } else { if (isset($response->cancelamentos->cancelamento)) { $order->add_order_note(sprintf(__('Cielo: %s - Refunded amount: %s.', 'cielo-woocommerce'), sanitize_text_field($response->cancelamentos->cancelamento->mensagem), wc_price($response->cancelamentos->cancelamento->valor / 100))); } return true; } } else { return new WP_Error('cielo_refund_error', sprintf(__('This transaction has been made more than %s days and therefore it can not be canceled', 'cielo-woocommerce'), $limit)); } return false; }
/** * Get a link to the transaction on the 3rd party gateway size (if applicable) * * @param WC_Order $order the order object * * @return string transaction URL, or empty string */ public function get_transaction_url($order) { $return_url = ''; $transaction_id = $order->get_transaction_id(); if (!$transaction_id) { $transaction_id = get_post_meta($order->id, 'oplatamd_transaction_id', true); } if (!empty($this->view_transaction_url) && !empty($transaction_id)) { $return_url = sprintf($this->view_transaction_url, $transaction_id); } return apply_filters('woocommerce_get_transaction_url', $return_url, $order, $this); }
/** * Process a Credit Capture transaction. * * @access public * @param WC_Order $order * @return bool|WP_Error */ public function process_creditcapture($order) { // Bail if no GUID. if (!$order || !$order->get_transaction_id()) { $this->log('TrxServices failed to capture an authorized credit transaction: No GUID'); return false; } $guid = $order->get_transaction_id(); $data = array('Detail' => array('TranType' => 'Credit', 'TranAction' => 'Capture', 'CurrencyCode' => 840, 'Amount' => $order->order_total), 'Reference' => array('Guid' => $guid)); $data = apply_filters('woocommerce_trxservices_creditcapture_data', $data, $order, $amount, $reason); $result = $this->do_request($data); // Bail if capture failed. if (!$result) { return false; } // Extract guid, responseCode and responseText. extract($result); if ($responseCode != '00') { $message = sprintf(__('Unable to capture payment for order %s via TrxServices (GUID: %s ResponseCode: %s ResponseText: %s)', 'woocommerce-trxservices'), $order_id, $guid, $responseCode, $responseText); $order->add_order_note($message); $this->log($message); return false; } // Change order status. $order->update_status('processing', __('Payment captured via TrxServices.', 'woocommerce-trxservices')); $order->add_order_note(sprintf(__('TrxServices Credit Capture %s (GUID: %s)', 'woocommerce-trxservices'), $amount, $guid)); // Store transaction type. update_post_meta($order->id, '_trxservices_transaction_type', 'Credit Capture'); $message = 'TrxServices captured payment for an authorized credit transaction for order #' . $order->id; $this->log($message); return true; }