function fn_paypal_set_express_checkout($payment_id, $order_id = 0, $order_info = array(), $cart = array(), $area = AREA, $is_in_context_order = false)
{
    $processor_data = fn_get_payment_method_data($payment_id);
    $currency = fn_paypal_get_valid_currency($processor_data['processor_params']['currency']);
    if ($is_in_context_order) {
        $return_url = fn_url("paypal_express.in_context_order?payment_id={$payment_id}", $area, 'current');
        $cancel_url = fn_url("checkout.checkout", $area, 'current');
    } elseif (!empty($order_id)) {
        $return_url = fn_url("payment_notification.notify?payment=paypal_express&order_id={$order_id}", $area, 'current');
        $cancel_url = fn_url("payment_notification.cancel?payment=paypal_express&order_id={$order_id}", $area, 'current');
    } else {
        $return_url = fn_url("paypal_express.express_return?payment_id={$payment_id}", $area, 'current');
        $cancel_url = fn_url("checkout.cart", $area, 'current');
    }
    $request = array('PAYMENTREQUEST_0_PAYMENTACTION' => 'SALE', 'PAYMENTREQUEST_0_CURRENCYCODE' => $currency['code'], 'LOCALECODE' => CART_LANGUAGE, 'RETURNURL' => $return_url, 'CANCELURL' => $cancel_url, 'METHOD' => 'SetExpressCheckout', 'SOLUTIONTYPE' => 'Sole');
    if (isset(Tygh::$app['session']['paypal_token'])) {
        $request['IDENTITYACCESSTOKEN'] = Tygh::$app['session']['paypal_token'];
    }
    $paypal_settings = fn_get_paypal_settings();
    if (!empty($paypal_settings) && !empty($paypal_settings['main_pair']['detailed'])) {
        $request['LOGOIMG'] = !empty($paypal_settings['main_pair']['detailed']['http_image_path']) ? $paypal_settings['main_pair']['detailed']['http_image_path'] : $paypal_settings['main_pair']['detailed']['image_path'];
        $exploded_logo = explode('?', $request['LOGOIMG']);
        $request['LOGOIMG'] = $exploded_logo[0];
    }
    fn_paypal_build_request($processor_data, $request, $post_url, $cert_file);
    $order_details = !empty($order_info) ? fn_paypal_build_details($order_info, $processor_data, false) : fn_paypal_build_details($cart, $processor_data);
    $request = array_merge($request, $order_details);
    if ($currency['code'] == CART_PRIMARY_CURRENCY && !empty($order_info)) {
        //We need to minus taxes when it based on unit price because product subtotal already include this tax.
        if (Registry::get('settings.General.tax_calculation') == 'unit_price') {
            $sum_taxes = fn_paypal_sum_taxes($order_info);
            $request['PAYMENTREQUEST_0_ITEMAMT'] -= $sum_taxes['P'];
            $request['PAYMENTREQUEST_0_SHIPPINGAMT'] -= $sum_taxes['S'];
        }
    }
    $result = fn_paypal_request($request, $post_url, $cert_file);
    return $result;
}
Пример #2
0
            Tygh::$app['view']->assign('onload', 'javascript: top.location = ' . "'{$url}'" . ';');
            Tygh::$app['view']->assign('order_action', __('text_paypal_processing_payment'));
            Tygh::$app['view']->display('views/orders/components/placing_order.tpl');
            fn_flush();
        }
    } elseif ($mode == 'cancel') {
        $pp_response['order_status'] = 'N';
        $pp_response['reason_text'] = __('text_transaction_cancelled');
        fn_finish_payment($order_id, $pp_response, false);
        fn_order_placement_routines('route', $order_id);
    } elseif ($mode == 'finish') {
        fn_order_placement_routines('route', $order_id);
    }
    exit;
} else {
    $currency = fn_paypal_get_valid_currency($processor_data['processor_params']['currency']);
    $paypal_total = fn_format_price_by_currency($order_info['total'], CART_PRIMARY_CURRENCY, $currency['code']);
    $cancel_url = fn_url("payment_notification.cancel?payment=paypal_advanced&order_id={$order_id}");
    $post_data = array('VENDOR' => $processor_data['processor_params']['merchant_login'], 'PARTNER' => $processor_data['processor_params']['api_partner'], 'USER' => $processor_data['processor_params']['api_user'], 'PWD' => $processor_data['processor_params']['api_password'], 'TRXTYPE' => 'S', 'BUTTONSOURCE' => 'ST_ShoppingCart_DP_US', 'AMT' => $paypal_total, 'TENDER' => 'C', 'CREATESECURETOKEN' => 'Y', 'SECURETOKENID' => uniqid(rand()), 'DISABLERECEIPT' => 'TRUE', 'RETURNURL' => fn_url("payment_notification.return?payment=paypal_advanced&order_id={$order_id}&security_hash=" . fn_generate_security_hash()), 'CANCELURL' => $cancel_url, 'ERRORURL' => fn_url("payment_notification.return?payment=paypal_advanced&order_id={$order_id}&security_hash=" . fn_generate_security_hash()), 'URLMETHOD' => 'POST', 'TEMPLATE' => $processor_data['processor_params']['layout'], 'PAGECOLLAPSEBGCOLOR' => $processor_data['processor_params']['collapse_bg_color'], 'PAGECOLLAPSETEXTCOLOR' => $processor_data['processor_params']['collapse_text_color'], 'PAGEBUTTONBGCOLOR' => $processor_data['processor_params']['button_bgcolor'], 'PAGEBUTTONTEXTCOLOR' => $processor_data['processor_params']['button_text_color'], 'BUTTONTEXT' => $processor_data['processor_params']['label_text_color'], 'PAYFLOWCOLOR' => $processor_data['processor_params']['payflowcolor'], 'HDRIMG' => $processor_data['processor_params']['header_image'], 'BILLTOFIRSTNAME' => $order_info['b_firstname'], 'BILLTOLASTNAME' => $order_info['b_lastname'], 'BILLTOSTREET' => $order_info['b_address'], 'BILLTOCITY' => $order_info['b_city'], 'BILLTOSTATE' => fn_pp_get_state($order_info, 'b_'), 'BILLTOZIP' => $order_info['b_zipcode'], 'BILLTOCOUNTRY' => $order_info['b_country'], 'SHIPTOFIRSTNAME' => $order_info['s_firstname'], 'SHIPTOLASTNAME' => $order_info['s_firstname'], 'SHIPTOSTREET' => $order_info['s_address'], 'SHIPTOCITY' => $order_info['s_city'], 'SHIPTOSTATE' => fn_pp_get_state($order_info, 's_'), 'SHIPTOZIP' => $order_info['s_zipcode'], 'SHIPTOCOUNTRY' => $order_info['s_country'], 'EMAIL' => $order_info['email'], 'PHONENUM' => $order_info['phone'], 'CURRENCY' => $currency['code']);
    $result = fn_pp_request($post_data, $processor_data['processor_params']['testmode']);
    if ($result['RESULT'] == '0') {
        $query_data = array('SECURETOKEN' => $result['SECURETOKEN'], 'SECURETOKENID' => $result['SECURETOKENID'], 'MODE' => $processor_data['processor_params']['testmode'] == 'Y' ? 'TEST' : '');
        $iframe_url = 'https://payflowlink.paypal.com/?' . http_build_query($query_data);
        Tygh::$app['view']->assign('iframe_url', $iframe_url);
        Tygh::$app['view']->assign('cancel_url', $cancel_url);
        Tygh::$app['view']->display('views/checkout/processors/paypal_advanced.tpl');
        exit;
    } else {
        $pp_response['order_status'] = 'F';
        $pp_response["reason_text"] = 'RESULT:' . $result['RESULT'] . '; RESPMSG:' . $result['RESPMSG'];
    }
Пример #3
0
function fn_pp_standart_prepare_products($order_info, $paypal_currency = '', $max_pp_products = MAX_PAYPAL_PRODUCTS)
{
    if (empty($paypal_currency)) {
        $paypal_currency = !empty($order_info['payment_method']['processor_params']['currency']) ? $order_info['payment_method']['processor_params']['currency'] : CART_PRIMARY_CURRENCY;
    }
    $currency = fn_paypal_get_valid_currency($paypal_currency);
    $post_data = array();
    $product_count = 1;
    $paypal_currency = $currency['code'];
    if ($paypal_currency != CART_PRIMARY_CURRENCY) {
        $post_data['item_name_1'] = __('total_product_cost');
        $post_data['amount_1'] = fn_format_price_by_currency($order_info['total'], CART_PRIMARY_CURRENCY, $paypal_currency);
        $post_data['quantity_1'] = '1';
        return array($post_data, 1);
    }
    $paypal_shipping = fn_order_shipping_cost($order_info);
    $paypal_total = fn_format_price($order_info['total'] - $paypal_shipping, $paypal_currency);
    if (empty($order_info['use_gift_certificates']) && !floatval($order_info['subtotal_discount']) && empty($order_info['points_info']['in_use']) && count($order_info['products']) < MAX_PAYPAL_PRODUCTS) {
        $i = 1;
        if (!empty($order_info['products'])) {
            foreach ($order_info['products'] as $k => $v) {
                $suffix = '_' . $i++;
                $v['product'] = htmlspecialchars(strip_tags($v['product']));
                $v['price'] = fn_format_price(($v['subtotal'] - fn_external_discounts($v)) / $v['amount'], $paypal_currency);
                $post_data["item_name{$suffix}"] = $v['product'];
                $post_data["amount{$suffix}"] = $v['price'];
                $post_data["quantity{$suffix}"] = $v['amount'];
                if (!empty($v['product_options'])) {
                    foreach ($v['product_options'] as $_k => $_v) {
                        $_v['option_name'] = htmlspecialchars(strip_tags($_v['option_name']));
                        $_v['variant_name'] = htmlspecialchars(strip_tags($_v['variant_name']));
                        $post_data["on{$_k}{$suffix}"] = $_v['option_name'];
                        $post_data["os{$_k}{$suffix}"] = $_v['variant_name'];
                    }
                }
            }
        }
        if (!empty($order_info['taxes']) && Registry::get('settings.General.tax_calculation') == 'subtotal') {
            foreach ($order_info['taxes'] as $tax_id => $tax) {
                if ($tax['price_includes_tax'] == 'Y') {
                    continue;
                }
                $suffix = '_' . $i++;
                $item_name = htmlspecialchars(strip_tags($tax['description']));
                $item_price = fn_format_price($tax['tax_subtotal'], $paypal_currency);
                $post_data["item_name{$suffix}"] = $item_name;
                $post_data["amount{$suffix}"] = $item_price;
                $post_data["quantity{$suffix}"] = '1';
            }
        }
        // Gift Certificates
        if (!empty($order_info['gift_certificates'])) {
            foreach ($order_info['gift_certificates'] as $k => $v) {
                $suffix = '_' . $i++;
                $v['gift_cert_code'] = htmlspecialchars($v['gift_cert_code']);
                $v['amount'] = !empty($v['extra']['exclude_from_calculate']) ? 0 : fn_format_price($v['amount'], $paypal_currency);
                $post_data["item_name{$suffix}"] = $v['gift_cert_code'];
                $post_data["amount{$suffix}"] = $v['amount'];
                $post_data["quantity{$suffix}"] = '1';
            }
        }
        if (fn_allowed_for('MULTIVENDOR') && fn_take_payment_surcharge_from_vendor('')) {
            $take_surcharge = false;
        } else {
            $take_surcharge = true;
        }
        // Payment surcharge
        if ($take_surcharge && floatval($order_info['payment_surcharge'])) {
            $suffix = '_' . $i++;
            $name = __('surcharge');
            $payment_surcharge_amount = fn_format_price($order_info['payment_surcharge'], $paypal_currency);
            $post_data["item_name{$suffix}"] = $name;
            $post_data["amount{$suffix}"] = $payment_surcharge_amount;
            $post_data["quantity{$suffix}"] = '1';
        }
        $product_count = $i - 1;
    } elseif ($paypal_total <= 0) {
        $post_data['item_name_1'] = __('total_product_cost');
        $post_data['amount_1'] = fn_format_price($order_info['total'], $paypal_currency);
        $post_data['quantity_1'] = '1';
        $post_data['amount'] = fn_format_price($order_info['total'], $paypal_currency);
        $post_data['shipping_1'] = 0;
    } else {
        $post_data['item_name_1'] = __('total_product_cost');
        $post_data['amount_1'] = $paypal_total;
        $post_data['quantity_1'] = '1';
    }
    return array($post_data, $product_count);
}