/**
  * Init payPal Mass pay api
  */
 public function call_masspay_api($receiver_information)
 {
     global $WCMp;
     require_once $WCMp->plugin_path . 'lib/paypal/CallerService.php';
     session_start();
     $emailSubject = urlencode('You have money!');
     $receiverType = urlencode('EmailAddress');
     $currency = urlencode(get_woocommerce_currency());
     $nvpstr = '';
     if ($receiver_information) {
         foreach ($receiver_information as $receiver) {
             $j = 0;
             $receiverEmail = urlencode($receiver['recipient']);
             $amount = urlencode($receiver['total']);
             $uniqueID = urlencode($receiver['vendor_id']);
             $note = urlencode($receiver['payout_note']);
             $nvpstr .= "&L_EMAIL{$j}={$receiverEmail}&L_Amt{$j}={$amount}&L_UNIQUEID{$j}={$uniqueID}&L_NOTE{$j}={$note}";
             $j++;
         }
         $nvpstr .= "&EMAILSUBJECT={$emailSubject}&RECEIVERTYPE={$receiverType}&CURRENCYCODE={$currency}";
         doProductVendorLOG($nvpstr);
         $resArray = hash_call("MassPay", $nvpstr);
         $ack = strtoupper($resArray["ACK"]);
         if ($ack == "SUCCESS" || $ack == "SuccessWithWarning") {
             doProductVendorLOG(json_encode($resArray));
             return $resArray;
         } else {
             doProductVendorLOG(json_encode($resArray));
             return false;
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Initialize paypal masspay cron
  */
 function do_paypal_mass_payment()
 {
     global $WCMp;
     $payment_admin_settings = get_option('wcmp_payment_settings_name');
     if (array_key_exists('is_mass_pay', $payment_admin_settings)) {
         doProductVendorLOG("Cron Run Start for array creatation @ " . date('d/m/Y g:i:s A', time()));
         update_option('paypal_masspay_cron_running', 1);
         $commissions = $WCMp->paypal_masspay->get_query_commission();
         if (!empty($commissions)) {
             $WCMp->paypal_masspay->do_paypal_masspay();
         }
         doProductVendorLOG("Cron Run Finish @ " . date('d/m/Y g:i:s A', time()));
         doProductVendorLOG("Next Payment import cron @ " . date('d/m/Y g:i:s A', wp_next_scheduled('paypal_masspay_cron_start')) . "::" . date('d/m/Y g:i:s A', time()));
     }
     delete_option('paypal_masspay_cron_running');
 }
 /**
  * Create new commission post
  *
  * @param  int $vendor_id  ID of vendor for commission
  * @param  int $product_id ID of product for commission
  * @param  int $amount     Commission total
  * @return void
  */
 public function create_commission($vendor_id = 0, $product_id = 0, $amount = 0, $order_id = 0, $variation_id = 0, $item_id = 0, $item)
 {
     global $WCMp, $wpdb;
     if ($vendor_id == 0) {
         return;
     }
     if (!isset($amount['total'])) {
         $amount['total'] = 0;
     }
     if (!isset($amount['shipping'])) {
         $amount['shipping'] = 0;
     }
     if (!isset($amount['tax'])) {
         $amount['tax'] = 0;
     }
     if (!isset($amount['commission'])) {
         $amount['commission'] = 0;
     }
     $commission_data = array('post_type' => 'dc_commission', 'post_title' => sprintf(__('Commission - %s', $WCMp->text_domain), strftime(_x('%B %e, %Y @ %I:%M %p', 'Commission date parsed by strftime', $WCMp->text_domain))), 'post_status' => 'private', 'ping_status' => 'closed', 'post_excerpt' => '', 'post_author' => 1);
     $commission_id = wp_insert_post($commission_data);
     // Add meta data
     if ($vendor_id > 0) {
         update_post_meta($commission_id, '_commission_vendor', $vendor_id);
     }
     if ($variation_id > 0) {
         update_post_meta($commission_id, '_commission_product', array($variation_id));
     } else {
         update_post_meta($commission_id, '_commission_product', array($product_id));
     }
     update_post_meta($commission_id, '_commission_amount', $amount['commission']);
     update_post_meta($commission_id, '_shipping', $amount['shipping']);
     update_post_meta($commission_id, '_tax', $amount['tax']);
     if ($order_id > 0) {
         update_post_meta($commission_id, '_commission_order_id', $order_id);
     }
     // Mark commission as unpaid
     update_post_meta($commission_id, '_paid_status', 'unpaid');
     if ($variation_id > 0) {
         $com_pro_id = $variation_id;
     } else {
         $com_pro_id = $product_id;
     }
     $item_commission = $this->get_item_commission($product_id, $product_id, $item, $order_id, $item_id);
     $vendor = get_wcmp_vendor_by_term($vendor_id);
     $vendor_shipping_costs = $vendor->get_wcmp_vendor_shipping_total($order_id, $item);
     $item_shipping = $vendor_shipping_costs['shipping_amount'] + $vendor_shipping_costs['shipping_tax'];
     $item_tax = get_metadata('order_item', $item_id, '_line_tax', true);
     doProductVendorLOG("UPDATE `{$wpdb->prefix}wcmp_vendor_orders` \tSET commission_id = " . $commission_id . ", commission_amount = '" . $item_commission . "', `shipping` = '" . $item_shipping . "', `tax` = '" . $item_tax . "'\tWHERE order_id =" . $order_id . " AND order_item_id = " . $item_id . " AND product_id\t=" . $com_pro_id);
     $update_query = $wpdb->query("UPDATE `{$wpdb->prefix}wcmp_vendor_orders` \tSET commission_id = " . $commission_id . ", commission_amount = '" . $item_commission . "', `shipping` = '" . $item_shipping . "', `tax` = '" . $item_tax . "'\tWHERE order_id =" . $order_id . " AND order_item_id = " . $item_id . " AND product_id\t=" . $com_pro_id);
     do_action('wcmp_vendor_commission_created', $commission_id);
 }