/** * Adds seller email to the new order notification email * * @param string $admin_email * @param WC_Order $order * @return array */ function dokan_wc_email_recipient_add_seller($admin_email, $order) { $emails = array($admin_email); $seller_id = dokan_get_seller_id_by_order($order->id); if ($seller_id) { $seller_email = get_user_by('id', $seller_id)->user_email; if ($admin_email != $seller_email) { array_push($emails, $seller_email); } } return $emails; }
/** * 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_status = $order->post_status; $wpdb->insert($wpdb->prefix . 'dokan_orders', array('order_id' => $order_id, 'seller_id' => $seller_id, 'order_total' => $order_total, 'net_amount' => $order_total * $percentage / 100, 'order_status' => $order_status), array('%d', '%d', '%f', '%f', '%s')); }
/** * Insert a order in sync table once a order is created * * @global object $wpdb * @param int $order_id * @since 2.4 */ function dokan_sync_order_table($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); //Total calculation $order_total = $order->get_total(); if ($total_refunded = $order->get_total_refunded()) { $order_total = $order_total - $total_refunded; } //Shipping calculation $order_shipping = $order->get_total_shipping(); foreach ($order->get_items() as $item) { $total_shipping_refunded = 0; if ($shipping_refunded = $order->get_total_refunded_for_item($item['product_id'], 'shipping')) { $total_shipping_refunded += $shipping_refunded; } } $order_shipping = $order_shipping - $total_shipping_refunded; //Tax calculation $order_tax = $order->get_total_tax(); if ($tax_refunded = $order->get_total_tax_refunded()) { $order_tax = $order_tax - $tax_refunded; } $extra_cost = $order_shipping + $order_tax; $order_cost = $order_total - $extra_cost; $order_status = $order->post_status; $net_amount = $order_cost * $percentage / 100 + $extra_cost; $net_amount = apply_filters('dokan_sync_order_net_amount', $net_amount, $order); $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')); }
</time> </td> <td class="order-status" style="text-align:left; white-space:nowrap;"> <?php echo isset($statuses[$order->post_status]) ? $statuses[$order->post_status] : $order->post_status; ?> </td> <td class="order-total"> <?php echo sprintf(_n('%s for %s item', '%s for %s items', $item_count, 'dokan'), $order->get_formatted_order_total(), $item_count); ?> </td> <td class="order-total"> <?php $seller_id = dokan_get_seller_id_by_order($order->id); if ($seller_id && $seller_id != 0) { $sellershop = dokan_get_store_info($seller_id); echo '<a href="' . dokan_get_store_url($seller_id) . '">' . $sellershop['store_name'] . '</a>'; } else { _e('Multiple Seller', 'dokan'); } ?> </td> <td class="order-actions"> <?php $actions = array(); if (in_array($order->status, apply_filters('woocommerce_valid_order_statuses_for_payment', array('pending', 'failed'), $order))) { $actions['pay'] = array('url' => $order->get_checkout_payment_url(), 'name' => __('Pay', 'dokan')); }
/** * 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_shipping = $order->get_total_shipping(); $order_tax = $order->get_total_tax(); $extra_cost = $order_shipping + $order_tax; $order_cost = $order_total - $extra_cost; $order_status = $order->post_status; $net_amount = $order_cost * $percentage / 100 + $extra_cost; $net_amount = apply_filters('dokan_order_net_amount', $net_amount, $order); $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')); }
/** * Process the payment and return the result * * @access public * @param int $order_id * @return array */ function process_payment($order_id) { $receiver = array(); $payRequest = new PayRequest(); $order = new WC_Order($order_id); $sub_orders = get_children(array('post_parent' => $order_id, 'post_type' => 'shop_order')); if ($sub_orders) { $sum = 0; foreach ($sub_orders as $key => $order_post) { $seller_id = dokan_get_seller_id_by_order($order_post->ID); $seller_balance = $this->get_seller_net_balance($order_post->ID, $seller_id); $seller_pay_email = dokan_get_seller_withdraw_mail($seller_id); if (false === $seller_pay_email) { $seller_pay_email = get_user_by('id', $seller_id)->user_email; } $receiver[$key] = new Receiver(); $receiver[$key]->amount = $seller_balance; $receiver[$key]->email = $seller_pay_email; $sum += (double) $seller_balance; } if ($this->payment_process == 'chained') { $admin_amount = (string) $order->get_total(); } else { $admin_amount = (string) ((double) $order->get_total() - $sum); } } else { $seller_id = dokan_get_seller_id_by_order($order_id); $seller_balance = $this->get_seller_net_balance($order_id, $seller_id); $seller_pay_email = dokan_get_seller_withdraw_mail($seller_id); if (false === $seller_pay_email) { $seller_pay_email = get_user_by('id', $seller_id)->user_email; } $receiver[0] = new Receiver(); $receiver[0]->amount = $seller_balance; $receiver[0]->email = $seller_pay_email; if ($this->payment_process == 'chained') { if ($this->single_mode == 'yes') { $admin_amount = (string) ((double) $order->get_total() - (double) $seller_balance); $receiver[0]->amount = (string) $order->get_total(); } else { $admin_amount = (string) $order->get_total(); } } else { $admin_amount = (string) ((double) $order->get_total() - (double) $seller_balance); } } $count = count($receiver); if ($admin_amount > 0) { $receiver[$count] = new Receiver(); $receiver[$count]->amount = $admin_amount; $receiver[$count]->email = $this->pa_admin_email; } if ($this->payment_process == 'chained') { if ($this->single_mode == 'yes') { $receiver[0]->primary = "true"; } else { $receiver[$count]->primary = "true"; } } $this->add_log('Payment Process: ' . $this->payment_process . ' ------ Reciever list' . print_r($receiver, true) . '...'); $receiverList = new ReceiverList($receiver); $payRequest->receiverList = $receiverList; $requestEnvelope = new RequestEnvelope("en_US"); $payRequest->requestEnvelope = $requestEnvelope; $payRequest->actionType = "PAY"; $payRequest->cancelUrl = esc_url($order->get_cancel_order_url()); $payRequest->returnUrl = esc_url($this->get_return_url($order)); $payRequest->currencyCode = get_woocommerce_currency(); $payRequest->ipnNotificationUrl = $this->notify_url; if ('yes' == $this->testmode) { $sdkConfig = array("mode" => "sandbox", "acct1.UserName" => $this->test_appuser, "acct1.Password" => $this->test_apppass, "acct1.Signature" => $this->test_appsig, "acct1.AppId" => "APP-80W284485P519543T"); } else { $sdkConfig = array("mode" => "live", "acct1.UserName" => $this->appuser, "acct1.Password" => $this->apppass, "acct1.Signature" => $this->appsig, "acct1.AppId" => $this->appid); } $adaptivePaymentsService = new AdaptivePaymentsService($sdkConfig); $payResponse = $adaptivePaymentsService->Pay($payRequest); if ($payResponse->payKey) { $shippingAddressInfo = new ShippingAddressInfo(); $shippingAddressInfo->addresseeName = $order->billing_first_name . ' ' . $order->billing_last_name; $shippingAddressInfo->street1 = $order->billing_address_1; $shippingAddressInfo->street2 = $order->billing_address_2; $shippingAddressInfo->city = $order->billing_city; $shippingAddressInfo->zip = $order->billing_postcode; $shippingAddressInfo->state = $this->get_paypal_state($order->billing_country, $order->billing_state); $shippingAddressInfo->country = $order->billing_country; if ('yes' == $this->send_shipping) { $shippingAddressInfo->addresseeName = $order->shipping_first_name . ' ' . $order->shipping_last_name; $shippingAddressInfo->street1 = $order->shipping_address_1; $shippingAddressInfo->street2 = $order->shipping_address_2; $shippingAddressInfo->city = $order->shipping_city; $shippingAddressInfo->zip = $order->shipping_postcode; $shippingAddressInfo->state = $this->get_paypal_state($order->shipping_country, $order->shipping_state); $shippingAddressInfo->country = $order->shipping_country; } $so = new SenderOptions(); $so->shippingAddress = $shippingAddressInfo; $re = new RequestEnvelope('en_US'); $setPaymentOptionsRequest = new SetPaymentOptionsRequest($re, $payResponse->payKey); $setPaymentOptionsRequest->senderOptions = $so; $paymentOptionRequest = $adaptivePaymentsService->SetPaymentOptions($setPaymentOptionsRequest); } $this->add_log('Payment Response: ' . print_r($payResponse, true)); // update paykey reference to find out update_post_meta($order->id, '_dokan_pap_key', $payResponse->payKey); if ('yes' == $this->testmode) { $paypal_url = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" . $payResponse->payKey; } else { $paypal_url = "https://www.paypal.com/webscr?cmd=_ap-payment&paykey=" . $payResponse->payKey; } // Return thankyou redirect return array('result' => 'success', 'redirect' => $paypal_url); }