/**
  * Get Komoju Args for passing to Komoju hosted page
  *
  * @param WC_Order $order
  * @return array
  */
 protected function get_komoju_args($order, $method)
 {
     WC_Gateway_Komoju::log('Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url);
     $params = array("transaction[amount]" => $order->get_subtotal() + $order->get_total_shipping(), "transaction[currency]" => get_woocommerce_currency(), "transaction[customer][email]" => $order->billing_email, "transaction[customer][phone]" => $order->billing_phone, "transaction[customer][given_name]" => $order->billing_first_name, "transaction[customer][family_name]" => $order->billing_last_name, "transaction[external_order_num]" => $this->gateway->get_option('invoice_prefix') . $order->get_order_number() . '-' . $this->request_id, "transaction[return_url]" => $this->gateway->get_return_url($order), "transaction[cancel_url]" => $order->get_cancel_order_url_raw(), "transaction[callback_url]" => $this->notify_url, "transaction[tax]" => strlen($order->get_total_tax()) == 0 ? 0 : $order->get_total_tax(), "timestamp" => time());
     WC_Gateway_Komoju::log('Raw parametres: ' . print_r($params, true));
     $qs_params = array();
     foreach ($params as $key => $val) {
         $qs_params[] = urlencode($key) . '=' . urlencode($val);
     }
     sort($qs_params);
     $query_string = implode('&', $qs_params);
     $url = $this->Komoju_endpoint . $method . '/new' . '?' . $query_string;
     $hmac = hash_hmac('sha256', $url, $this->gateway->secretKey);
     $query_string .= '&hmac=' . $hmac;
     return $query_string;
 }
 /**
  * Get the order data for the given ID.
  *
  * @since  2.5.0
  * @param  WC_Order $order The order instance
  * @return array
  */
 protected function get_order_data($order)
 {
     $order_post = get_post($order->id);
     $dp = wc_get_price_decimals();
     $order_data = array('id' => $order->id, 'order_number' => $order->get_order_number(), 'created_at' => $this->format_datetime($order_post->post_date_gmt), 'updated_at' => $this->format_datetime($order_post->post_modified_gmt), 'completed_at' => $this->format_datetime($order->completed_date, true), 'status' => $order->get_status(), 'currency' => $order->get_order_currency(), 'total' => wc_format_decimal($order->get_total(), $dp), 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp), 'total_line_items_quantity' => $order->get_item_count(), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'total_shipping' => wc_format_decimal($order->get_total_shipping(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'total_discount' => wc_format_decimal($order->get_total_discount(), $dp), 'shipping_methods' => $order->get_shipping_method(), 'payment_details' => array('method_id' => $order->payment_method, 'method_title' => $order->payment_method_title, 'paid' => isset($order->paid_date)), 'billing_address' => array('first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_1' => $order->billing_address_1, 'address_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postcode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phone' => $order->billing_phone), 'shipping_address' => array('first_name' => $order->shipping_first_name, 'last_name' => $order->shipping_last_name, 'company' => $order->shipping_company, 'address_1' => $order->shipping_address_1, 'address_2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postcode' => $order->shipping_postcode, 'country' => $order->shipping_country), 'note' => $order->customer_note, 'customer_ip' => $order->customer_ip_address, 'customer_user_agent' => $order->customer_user_agent, 'customer_id' => $order->get_user_id(), 'view_order_url' => $order->get_view_order_url(), 'line_items' => array(), 'shipping_lines' => array(), 'tax_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array());
     // add line items
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         $product_id = null;
         $product_sku = null;
         // Check if the product exists.
         if (is_object($product)) {
             $product_id = isset($product->variation_id) ? $product->variation_id : $product->id;
             $product_sku = $product->get_sku();
         }
         $meta = new WC_Order_Item_Meta($item, $product);
         $item_meta = array();
         foreach ($meta->get_formatted(null) as $meta_key => $formatted_meta) {
             $item_meta[] = array('key' => $meta_key, 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
         }
         $order_data['line_items'][] = array('id' => $item_id, 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : null, 'name' => $item['name'], 'product_id' => $product_id, 'sku' => $product_sku, 'meta' => $item_meta);
     }
     // Add shipping.
     foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
         $order_data['shipping_lines'][] = array('id' => $shipping_item_id, 'method_id' => $shipping_item['method_id'], 'method_title' => $shipping_item['name'], 'total' => wc_format_decimal($shipping_item['cost'], $dp));
     }
     // Add taxes.
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $order_data['tax_lines'][] = array('id' => $tax->id, 'rate_id' => $tax->rate_id, 'code' => $tax_code, 'title' => $tax->label, 'total' => wc_format_decimal($tax->amount, $dp), 'compound' => (bool) $tax->is_compound);
     }
     // Add fees.
     foreach ($order->get_fees() as $fee_item_id => $fee_item) {
         $order_data['fee_lines'][] = array('id' => $fee_item_id, 'title' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : null, 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp));
     }
     // Add coupons.
     foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
         $order_data['coupon_lines'][] = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'amount' => wc_format_decimal($coupon_item['discount_amount'], $dp));
     }
     $order_data = apply_filters('woocommerce_cli_order_data', $order_data);
     return $this->flatten_array($order_data);
 }
Example #3
0
/**
 * Insert a order in sync table once a order is created
 *
 * @global object $wpdb
 * @param int $order_id
 */
function dokan_sync_insert_order($order_id)
{
    global $wpdb;
    $order = new WC_Order($order_id);
    $seller_id = dokan_get_seller_id_by_order($order_id);
    $percentage = dokan_get_seller_percentage($seller_id);
    $order_total = $order->get_total();
    $order_subtotal = $order->get_subtotal();
    $other_cost = $order_total - $order_subtotal;
    $order_status = $order->post_status;
    $net_amount = $order_subtotal * $percentage / 100 + $other_cost;
    $net_amount = apply_filters('dokan_order_net_amount', $net_amount, $order, $seller_id, $percentage);
    $wpdb->insert($wpdb->prefix . 'dokan_orders', array('order_id' => $order_id, 'seller_id' => $seller_id, 'order_total' => $order_total, 'net_amount' => $net_amount, 'order_status' => $order_status), array('%d', '%d', '%f', '%f', '%s'));
}
 function get_payment_xml($order_id)
 {
     global $woocommerce;
     global $product;
     $order = new WC_Order($order_id);
     $Secuitems = '';
     foreach ($order->get_items() as $item) {
         $Options = array();
         foreach ($item as $Attribute => $Value) {
             if (!in_array($Attribute, $this->GetStandardProductFields())) {
                 $Options[$Attribute] = $Value;
             }
         }
         $product = new WC_Product($item['product_id']);
         $Secuitems .= '[' . $item['product_id'] . '|' . $product->get_sku() . '|' . $item['name'];
         if (!empty($Options)) {
             foreach ($Options as $Key => $Value) {
                 if ((string) $Key === 'pa_quantity') {
                     $Key = 'Quantity';
                 }
                 $Secuitems .= ', ' . $Key . ': ' . $Value;
             }
         }
         $Secuitems .= '|' . $this->currency_format($item['line_total'] / $item['qty']) . '|' . $item['qty'] . '|' . $this->currency_format($item['line_total']) . ']';
     }
     $TransactionSubTotal = $this->currency_format($order->get_subtotal());
     $TransactionAmount = $this->currency_format($order->get_total());
     $expirydate = str_replace(array('/', ' '), '', $_POST['UPG_api-card-expiry']);
     $cardnumber = str_replace(array(' ', '-'), '', $_POST['UPG_api-card-number']);
     $cardcv2 = str_replace(array(' ', '-'), '', $_POST['UPG_api-card-cvc']);
     $xmlContrsuct = '<?xml version ="1.0"?>';
     $xmlContrsuct .= '<request>';
     $xmlContrsuct .= '<type>transaction</type>';
     $xmlContrsuct .= '<authtype>authorise</authtype>';
     $xmlContrsuct .= '<authentication>';
     $xmlContrsuct .= '<shreference>' . $this->reference . '</shreference>';
     $xmlContrsuct .= '<checkcode>' . $this->checkcode . '</checkcode>';
     $xmlContrsuct .= '</authentication>';
     $xmlContrsuct .= '<transaction>';
     //Card details
     $xmlContrsuct .= '<cardnumber>' . $cardnumber . '</cardnumber>';
     $xmlContrsuct .= '<cv2>' . $cardcv2 . '</cv2>';
     $xmlContrsuct .= '<cardexpiremonth>' . substr($expirydate, 0, 2) . '</cardexpiremonth>';
     $xmlContrsuct .= '<cardexpireyear>' . substr($expirydate, -2) . '</cardexpireyear>';
     //Cardholder details
     $xmlContrsuct .= '<cardholdersname>' . $order->billing_first_name . ' ' . $order->billing_last_name . '</cardholdersname>';
     $xmlContrsuct .= '<cardholdersemail>' . $order->billing_email . '</cardholdersemail>';
     $xmlContrsuct .= '<cardholderaddr1>' . $order->billing_address_1 . '</cardholderaddr1>';
     $xmlContrsuct .= '<cardholderaddr2>' . $order->billing_address_2 . '</cardholderaddr2>';
     $xmlContrsuct .= '<cardholdercity>' . $order->billing_city . '</cardholdercity>';
     $xmlContrsuct .= '<cardholderstate>' . $order->billing_state . '</cardholderstate>';
     $xmlContrsuct .= '<cardholderpostcode>' . $order->billing_postcode . '</cardholderpostcode>';
     $xmlContrsuct .= '<cardholdercountry>' . $order->billing_country . '</cardholdercountry>';
     $xmlContrsuct .= '<cardholdertelephonenumber>' . $order->billing_phone . '</cardholdertelephonenumber>';
     // Order details
     $xmlContrsuct .= '<orderid>' . $order->id . '</orderid>';
     $xmlContrsuct .= '<subtotal>' . $TransactionSubTotal . '</subtotal>';
     $xmlContrsuct .= '<transactionamount>' . $TransactionAmount . '</transactionamount>';
     $xmlContrsuct .= '<transactioncurrency>' . get_woocommerce_currency() . '</transactioncurrency>';
     $xmlContrsuct .= '<transactiondiscount>' . $this->currency_format($order->get_total_discount()) . '</transactiondiscount>';
     $xmlContrsuct .= '<transactiontax>' . $this->currency_format($order->get_total_tax()) . '</transactiontax>';
     $xmlContrsuct .= '<shippingcharge>' . $this->currency_format($order->get_total_shipping()) . '</shippingcharge>';
     $xmlContrsuct .= '<secuitems><![CDATA[' . $Secuitems . ']]></secuitems>';
     $xmlContrsuct .= '</transaction>';
     $xmlContrsuct .= '</request>';
     return $xmlContrsuct;
 }
 /**
  * Get the subtotal without discount and shipping, but including tax.
  * @return mixed|void
  */
 public function get_subtotal_incl_tax()
 {
     return $this->order->get_subtotal() + $this->order->get_total_tax();
 }
Example #6
0
function addRoyaltyPoint($order_id)
{
    if (!get_current_user_id()) {
        return false;
    }
    $order = new WC_Order($order_id);
    $subtotal = $order->get_subtotal();
    $pointsAdjustment = $subtotal - $order->cart_discount;
    $cardNo = get_cimyFieldValue(get_current_user_id(), 'CARD_NO');
    $userInfo = array("CARD_NO" => $cardNo, "PLUS_POINT" => number_format($pointsAdjustment, 2));
    $royaltyCardAPI = new royaltyCardAPI();
    $rtnIncrementPoints = $royaltyCardAPI->incrementPoints($userInfo);
    if ($rtnIncrementPoints == 'SUCCESS') {
        //echo 'aaaa';
    } else {
        return new WP_Error(444, $rtnIncrementPoints);
    }
}
function sendCustomerInvoice($order_id)
{
    PlexLog::addLog(' Info =>@sendCustomerInvoice order_id=' . $order_id);
    $wooCommerceOrderObject = new WC_Order($order_id);
    $user_id = $wooCommerceOrderObject->get_user_id();
    $customerMailId = $wooCommerceOrderObject->billing_email;
    $invoice_mail_content = '';
    $invoice_mail_content .= '
	<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_container">
		<tbody>
			<tr>
				<td align="center" valign="top">
					<font face="Arial" style="font-weight:bold;background-color:#8fd1c8;color:#202020;"></font>
					<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_header" bgcolor="#8fd1c8">
						<tbody>
							<tr >
					            <td width="20" height="20"  bgcolor="#8fd1c8">&nbsp;</td>
					            <td bgcolor="#8fd1c8">&nbsp;</td>
					            <td width="20" bgcolor="#8fd1c8">&nbsp;</td>
					        </tr>
					        <tr >
					            <td width="20"  bgcolor="#8fd1c8">&nbsp;</td>
					            <td bgcolor="#8fd1c8" style="font-weight:bold;font-size:24px;color:#ffffff;" ><h2 style="margin:0;">Welcome to ' . get_option('blogname') . '! <br>Thank you for your order. We\'ll be in touch shortly with additional order and shipping information.</h2></td>
					            <td width="20" bgcolor="#8fd1c8">&nbsp;</td>
					        </tr>
					        <tr >
					            <td width="20" height="20"  bgcolor="#8fd1c8">&nbsp;</td>
					            <td bgcolor="#8fd1c8">&nbsp;</td>
					            <td width="20" bgcolor="#8fd1c8">&nbsp;</td>
					        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr>
            	<td align="center" valign="top">
            		<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_body">
            			<tbody>
            				<tr>
            					<td valign="top">
            						<font style="background-color:#f9f9f9">
            							<table border="0" cellpadding="20" cellspacing="0" width="100%">
            								<tbody>
            									<tr>
	            									<td valign="top">
	            										<div>
	            											<font face="Arial" align="left" style="font-size:18px;color:#8a8a8a">
	            												<p>Your order #' . get_post_meta($order_id, "plexOrderId", true) . ' has been received and is now being processed. Your order details are shown below for your reference:</p>
																<table cellspacing="0" cellpadding="6" border="1" style="width:100%;">
																	<thead>
																		<tr>
																			<th scope="col">
																				<font align="left">Product</font>
																			</th>
																			<th scope="col">
																				<font align="left">Quantity</font>
																			</th>
																			<th scope="col">
																				<font align="left">Price</font>
																			</th>
																		</tr>
																	</thead>
																	<tbody>';
    $allItems = $wooCommerceOrderObject->get_items();
    foreach ($allItems as $key => $value) {
        $invoice_mail_content .= '
																				<tr>
																					<td>
																						<font align="left">' . $value["name"] . '<br><small></small></font>
																					</td>
																					<td>
																						<font align="left">' . $value["qty"] . '</font>
																					</td>
																					<td>
																						<font align="left">
																							<span class="amount">$' . $value["line_subtotal"] . '</span>
																						</font>
																					</td>
																				</tr>';
    }
    $invoice_mail_content .= '																		
																	</tbody>
																	<tfoot style="text-align: left;">
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Cart Subtotal:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_subtotal()) . '</span>
																				</font>
																			</td>
																		</tr>';
    if ($wooCommerceOrderObject->get_total_discount() > 0.0) {
        $invoice_mail_content .= '<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Discount:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_total_discount()) . '</span>
																				</font>
																			</td>
																		</tr>';
    }
    $invoice_mail_content .= '<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Tax:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_cart_tax() + $wooCommerceOrderObject->get_shipping_tax()) . '</span>
																				</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Shipping:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . $wooCommerceOrderObject->get_total_shipping() . '</span>&nbsp;<small>via ' . $wooCommerceOrderObject->get_shipping_method() . '</small>
																				</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Payment Method:</font>
																			</th>
																			<td>
																				<font align="left">' . $wooCommerceOrderObject->payment_method_title . '</font>
																			</td>
																		</tr>
																		<tr>
																			<th scope="row" colspan="2">
																				<font align="left">Order Total:</font>
																			</th>
																			<td>
																				<font align="left">
																					<span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_total()) . '</span>
																				</font>
																			</td>
																		</tr>
																	</tfoot>
																</table>
																<h2>
																	<font face="Arial" align="left" style="font-weight:bold;font-size:30px;color:#6d6d6d">Customer details</font>
																</h2>
																<p><strong>Email:</strong> ' . $customerMailId . '</p>
																<p><strong>Tel:</strong> ' . $wooCommerceOrderObject->billing_phone . '</p>
																<table cellspacing="0" cellpadding="0" border="0">
																	<tbody>
																		<tr>
																			<td valign="top" width="50%">
																				<h3>
																					<font face="Arial" align="left" style="font-weight:bold;font-size:26px;color:#6d6d6d">Billing address</font>
																				</h3>
																				<p>' . $wooCommerceOrderObject->get_formatted_billing_address() . '</p>

																			</td>
																			<td valign="top" width="50%">
																				<h3>
																					<font face="Arial" align="left" style="font-weight:bold;font-size:26px;color:#6d6d6d">Shipping address</font>
																				</h3>
																				<p>' . $wooCommerceOrderObject->get_formatted_shipping_address() . '</p>
																			</td>
																		</tr>
																	</tbody>
																</table>
															</font>
														</div>
													</td>
												</tr>
											</tbody>
										</table>
									</font>
								</td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td align="center" valign="top">
					<table border="0" cellpadding="10" cellspacing="0" width="600" id="template_footer">
						<tbody>
							<tr>
								<td valign="top">
	                                <table border="0" cellpadding="4" cellspacing="0" width="100%">
	                                	<tbody>
	                                		<tr>
	                                			<td colspan="2" valign="middle" id="credit" style="background-color: #777;">
	                                				<font face="Arial" align="center" style="font-size:12px;color:#bce3de">
	                                					<p>' . site_url() . '</p>
	                                                </font>
	                                            </td>
	                                        </tr>
	                                    </tbody>
	                                </table>
	                            </td>
	                        </tr>
	                    </tbody>
	                </table>
	            </td>
	        </tr>
	    </tbody>
	</table>';
    $emailHeader = "Content-type: text/html";
    // To send HTML mail, the Content-type header must be set
    $emailHeader = 'MIME-Version: 1.0' . "\r\n";
    $emailHeader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    // Additional emailHeader
    $emailHeader .= 'From: ' . get_bloginfo('name') . ' <*****@*****.**>' . "\r\n";
    $emailSubject = "Your plexuser order receipt from " . date_i18n(wc_date_format(), strtotime($wooCommerceOrderObject->order_date));
    wp_mail($customerMailId, $emailSubject, $invoice_mail_content, $emailHeader);
}