Esempio n. 1
0
/**
 * Payment Paypal
 * 
 * Handles functionalities about payment
 * all gateways
 * 
 * @package Social Deals Engine
 * @since 1.0.0
 */
function wps_deals_process_testmode($cartdetails, $postdata)
{
    global $wps_deals_paypal, $wps_deals_price, $wps_deals_options, $wps_deals_currency, $wps_deals_model, $wps_deals_message;
    //price class
    $price = $wps_deals_price;
    //model class
    $model = $wps_deals_model;
    //paypal class
    $paypal = $wps_deals_paypal;
    //currency class
    $currency = $wps_deals_currency;
    //message class
    $message = $wps_deals_message;
    $purchasedata = array();
    $purchasedata['user_info'] = array('first_name' => $postdata['wps_deals_cart_user_first_name'], 'last_name' => $postdata['wps_deals_cart_user_last_name'], 'user_name' => $postdata['user_name'], 'user_email' => $postdata['wps_deals_cart_user_email']);
    $purchasedata['post_data'] = $postdata;
    $purchasedata['cartdata'] = $cartdetails;
    $purchasedata['payment_status'] = '1';
    $salesid = wps_deals_insert_payment_data($purchasedata);
    //check sales id id not empty
    if (!empty($salesid)) {
        //empty cart
        wps_deals_empty_cart();
        //send to success page
        $queryurl = array('order_id' => $salesid);
        wps_deals_send_on_success_page($queryurl);
    } else {
        //else show payment is failed
        $errormsg = __('Payment creation failed while processing a manual (free or test) purchase, Please try again after sometime.', 'wpsdeals');
        //error to show on checkout page
        $message->add_session('error', $errormsg, 'error');
        //return to checkout page
        wps_deals_send_on_checkout_page();
    }
}
Esempio n. 2
0
/**
 * Cheuqe Payment
 * 
 * Handles functionalities about payment
 * all gateways
 * 
 * @package Social Deals Engine
 * @since 1.0.1
 */
function wps_deals_process_cheque($cartdetails, $postdata)
{
    global $wps_deals_paypal, $wps_deals_price, $wps_deals_options, $wps_deals_currency, $wps_deals_model, $wps_deals_message;
    //price class
    $price = $wps_deals_price;
    //model class
    $model = $wps_deals_model;
    //paypal class
    $paypal = $wps_deals_paypal;
    //currency class
    $currency = $wps_deals_currency;
    //message class
    $message = $wps_deals_message;
    //payment method
    $method = $postdata['wps_deals_payment_gateways'];
    // Check Mark Order As Completed from payment gateways settings
    if (isset($wps_deals_options['mark_order_complete']) && $wps_deals_options['mark_order_complete'] == '1') {
        $payment_status = '1';
        //completed
    } else {
        $payment_status = '5';
        //on-hold by default
    }
    $purchasedata = array();
    $purchasedata['user_info'] = array('first_name' => $postdata['wps_deals_cart_user_first_name'], 'last_name' => $postdata['wps_deals_cart_user_last_name'], 'user_name' => $postdata['user_name'], 'user_email' => $postdata['wps_deals_cart_user_email']);
    $purchasedata['post_data'] = $postdata;
    $purchasedata['cartdata'] = $cartdetails;
    $purchasedata['payment_status'] = $payment_status;
    $salesid = wps_deals_insert_payment_data($purchasedata);
    if (!empty($salesid)) {
        //empty cart
        wps_deals_empty_cart();
        //send to success page
        $queryurl = array('order_id' => $salesid);
        wps_deals_send_on_success_page($queryurl);
    } else {
        $errormsg = __('Payment creation failed while processing a purchase by cheque, Please try again after sometime.', 'wpsdeals');
        //error to show on checkout page
        $message->add_session('error', $errormsg, 'error');
        //return to checkout page
        wps_deals_send_on_checkout_page();
    }
}
/**
 * Process Order
 *
 * Handle process of order
 * 
 * @package Social Deals Engine
 * @since 1.0.0
 */
function wps_deals_payment_process()
{
    global $wps_deals_cart, $wps_deals_message, $current_user, $wps_deals_options;
    //cart class
    $cart = $wps_deals_cart;
    //message class
    $message = $wps_deals_message;
    //get cart data
    $cartdata = $cart->get();
    if (isset($_POST['wps_deals_submit_payment']) && !empty($_POST['wps_deals_submit_payment']) && $_POST['wps_deals_submit_payment'] == __('Deals Purchase', 'wpsdeals')) {
        //check payment button click for checkout button
        //validate nonce for security purpose
        // $noncevalidate = wps_deals_payment_nonce_valid($_POST['wps_deals_payment_nonce']);
        if (is_user_logged_in() && isset($_POST['wps_deals_cart_login_user_name']) && !empty($_POST['wps_deals_cart_login_user_name']) && isset($_POST['wps_deals_cart_login_user_pass']) && !empty($_POST['wps_deals_cart_login_user_pass'])) {
            //when user will try to purchase with login form then select his email from database
            $_POST['wps_deals_cart_user_email'] = $current_user->user_email;
            $_POST['wps_deals_cart_user_first_name'] = $current_user->first_name;
            $_POST['wps_deals_cart_user_last_name'] = $current_user->last_name;
        } else {
            $_POST['wps_deals_cart_user_email'] = $_POST['wps_deals_cart_user_email'];
        }
        //payment gateway
        $validgateway = wps_deals_valid_gateway();
        //valid order data
        $validatedata = wps_deals_order_data_validate();
        //user details
        $uservalid = wps_deals_valid_user_data();
        //valid billing details
        $userbilling = wps_deals_valid_billing_data();
        //check user can purchase deal
        $user_can_purchase = wps_deals_valid_purchase_limit();
        $agreeterms = true;
        //terms and conditions
        if (!empty($wps_deals_options['enable_terms'])) {
            $terms = isset($_POST['wps_deals_checkout_agree_terms']) ? $_POST['wps_deals_checkout_agree_terms'] : '';
            $agreeterms = wps_deals_payment_agree_to_terms($terms);
        }
        // !$noncevalidate ||
        if (empty($cartdata['products']) || !$validatedata || !$uservalid || !$validgateway || !$agreeterms || !$userbilling || !$user_can_purchase) {
            //check some data valid or not
            //redirect to checkout page
            wps_deals_send_on_checkout_page();
        }
        //get the value of user login name
        if (is_user_logged_in()) {
            //if user is logged in then stored display name
            $_POST['user_name'] = $current_user->display_name;
        } else {
            //do concat first name and last name of from posted data
            $_POST['user_name'] = 'guest';
        }
        $gateway = isset($_POST['wps_deals_payment_gateways']) ? $_POST['wps_deals_payment_gateways'] : '';
        //Pst data
        $post_data = $_POST;
        // Allow themes and plugins to hook before the gateway
        do_action('wps_deals_checkout_before_gateway', $post_data, $cartdata);
        if ($cartdata['total'] <= '0') {
            //if cart total is empty call test mode
            $gateway = 'testmode';
            $post_data['wps_deals_payment_gateways'] = 'testmode';
            //$post_data['wps_deals_payment_gateways']	= 'free';
        }
        // Send info to the gateway for payment processing
        wps_deals_send_to_gateway($gateway, $cartdata, $post_data);
        exit;
    }
}
Esempio n. 4
0
/**
 * Payment Paypal
 * 
 * Handles functionalities about payment
 * all gateways
 * 
 * @package Social Deals Engine
 * @since 1.0.0
 */
function wps_deals_process_payment_paypal($cartdetails, $postdata)
{
    global $wps_deals_paypal, $wps_deals_price, $wps_deals_options, $wps_deals_currency, $wps_deals_model;
    //price class
    $price = $wps_deals_price;
    //model class
    $model = $wps_deals_model;
    //paypal class
    $paypal = $wps_deals_paypal;
    //currency class
    $currency = $wps_deals_currency;
    //get payment gateways
    //$paymentgateways = wps_deals_get_payment_gateways();
    //payment method
    //$method	= isset( $postdata['wps_deals_payment_gateways'] ) ? $postdata['wps_deals_payment_gateways'] : 'paypal';
    $purchasedata = array();
    $purchasedata['user_info'] = array('first_name' => $postdata['wps_deals_cart_user_first_name'], 'last_name' => $postdata['wps_deals_cart_user_last_name'], 'user_name' => $postdata['user_name'], 'user_email' => $postdata['wps_deals_cart_user_email']);
    //$purchasedata['payment_method'] = $method;
    //$purchasedata['admin_label'] 	= $paymentgateways[$method]['admin_label'];
    //$purchasedata['checkout_label'] = $paymentgateways[$method]['checkout_label'];
    $purchasedata['post_data'] = $postdata;
    $purchasedata['cartdata'] = $cartdetails;
    $payment_status['payment_status'] = '0';
    $salesid = wps_deals_insert_payment_data($purchasedata);
    $cancelurl = wps_deals_checkout_cancel_url();
    $thankyouurl = wps_deals_checkout_thank_you_url();
    //$cancelurl = isset($wps_deals_options['payment_cancel_page']) ? get_permalink($wps_deals_options['payment_cancel_page']) : '';
    //$thankyouurl = isset($wps_deals_options['payment_thankyou_page']) ? get_permalink($wps_deals_options['payment_thankyou_page']) : '';
    $cancelurl = add_query_arg(array('wps_deals_cancel_order' => '1', 'order_id' => $salesid), $cancelurl);
    $thankyouargs = array();
    //check user is logged in or not
    if (is_user_logged_in()) {
        $thankyouargs['order_id'] = $salesid;
    }
    $thankyouurl = add_query_arg($thankyouargs, $thankyouurl);
    if (!empty($salesid)) {
        //get order deals
        $orderdetailsall = $model->wps_deals_get_post_meta_ordered($salesid);
        $orderdetails = $orderdetailsall['deals_details'];
        //get the merchant id from settings page
        $merchantid = $wps_deals_options['paypal_merchant_email'];
        //make notify url when payapl ipn is going to validate
        //$notifyurl = add_query_arg(array( 'dealslistner' => 'paypalipn','order_id' => $salesid),home_url());
        $notifyurl = trailingslashit(home_url()) . '?dealslistner=paypalipn';
        $paypal->add_field('business', $merchantid);
        $paypal->add_field('return', $thankyouurl);
        $paypal->add_field('cancel_return', $cancelurl);
        $paypal->add_field('notify_url', $notifyurl);
        $paypal->add_field('first_name', $purchasedata['user_info']['first_name']);
        $paypal->add_field('last_name', $purchasedata['user_info']['last_name']);
        $paypal->add_field('currency_code', $wps_deals_options['currency']);
        $paypal->add_field('cmd', '_ext-enter');
        //
        $paypal->add_field('custom', $salesid);
        //
        $paypal->add_field('rm', '2');
        $paypal->add_field('redirect_cmd', '_cart');
        $paypal->add_field('upload', count($orderdetails));
        $i = 1;
        //made proper data format for sending into paypal
        foreach ($orderdetails as $order) {
            $dealid = $order['deal_id'];
            //get deal title
            $dealtitle = get_the_title($order['deal_id']);
            //append item name to string which will send into paypal
            //$item_name .= $dealtitle.',';
            $item_name = $dealtitle;
            //get deal price
            $dealprice = $order['deal_sale_price'];
            //get deal quantity
            $dealqty = $order['deal_quantity'];
            $paypal->add_field('item_name_' . $i, $item_name);
            $paypal->add_field('amount_' . $i, $dealprice);
            $paypal->add_field('quantity_' . $i, $dealqty);
            $i++;
        }
        //do action to add field to paypal form
        do_action('wps_deals_add_paypal_field', $salesid);
        //add fee amount to paypal
        $discounted_amount = 0.0;
        //check fees is set or not in order meta
        if (isset($orderdetailsall['fees']) && !empty($orderdetailsall['fees'])) {
            $i = empty($i) ? 1 : $i;
            foreach ($orderdetailsall['fees'] as $fee_val) {
                //check fees amount is greated then 0
                if (floatval($fee_val['amount']) > '0') {
                    // this is a positive fee
                    $paypal->add_field('item_name_' . $i, $fee_val['label']);
                    $paypal->add_field('quantity_' . $i, '1');
                    $paypal->add_field('amount_' . $i, $fee_val['amount']);
                    $i++;
                } else {
                    // This is a negative fee (discount)
                    $discounted_amount += abs($fee_val['amount']);
                }
                //end else
            }
            //end foreach loop
        }
        //end if
        $discount_count = '0';
        //check discounted amount should not empty then add discount amount as per fees
        if (!empty($discounted_amount)) {
            $discount_count = '1';
            //initial discount count
            $paypal->add_field('discount_amount_' . $discount_count, $discounted_amount);
        }
        //end if to check discount amount
        //do action to add discount field into paypal fields
        do_action('wps_deals_paypal_disocunt_field', $discount_count, $salesid);
        //empty cart
        wps_deals_empty_cart();
        // submit the fields to paypal
        $paypal->submit_paypal_post();
        exit;
    } else {
        //return to checkout page
        wps_deals_send_on_checkout_page();
    }
}