Esempio n. 1
0
function yab_shop_build_paypal_encrypted_form($cart)
{
    global $tempdir;
    $subdomain = '';
    if (yab_shop_config('paypal_live_or_sandbox') == 'sandbox') {
        $subdomain = '.sandbox';
    }
    $email = '';
    if (ps('email')) {
        $email = yab_shop_return_input('email');
    }
    $state = '';
    if (ps('state|r')) {
        $state = yab_shop_return_input('state|r');
    }
    $tax = '0.00';
    if (yab_shop_config('tax_inclusive') == '0') {
        $tax = number_format(yab_shop_calculate_sum('tax'), 2);
    }
    $action = 'https://www' . $subdomain . '.paypal.com/cgi-bin/webscr';
    $message = yab_shop_lang('checkout_paypal_no_forward');
    $message2 = yab_shop_lang('checkout_paypal_forward');
    $business_email = yab_shop_config('paypal_business_mail');
    $country = yab_shop_config('paypal_prefilled_country');
    $lc = yab_shop_config('paypal_interface_language');
    $section = pagelinkurl(array('s' => yab_shop_config('checkout_section_name')));
    $currency = yab_shop_config('currency');
    $shipping = yab_shop_shipping_costs();
    $myPublicCertificate = yab_shop_config('paypal_certificates_path') . '/' . yab_shop_config('paypal_my_public_certificate_name');
    $myPrivateKey = yab_shop_config('paypal_certificates_path') . '/' . yab_shop_config('paypal_my_private_key_name');
    $CertificateID = yab_shop_config('paypal_certificate_id');
    $PayPalPublicCertificate = yab_shop_config('paypal_certificates_path') . '/' . yab_shop_config('paypal_public_certificate_name');
    $paypal = new PayPalEWP();
    $paypal->setTempDir($tempdir);
    $paypal->setCertificate($myPublicCertificate, $myPrivateKey);
    $paypal->setCertificateID($CertificateID);
    $paypal->setPayPalCertificate($PayPalPublicCertificate);
    $parameters = array('cmd' => '_ext-enter', 'redirect_cmd' => '_cart', 'upload' => '1', 'business' => $business_email, 'cert_id' => $CertificateID, 'return' => $section, 'country' => $country, 'lc' => $lc, 'currency_code' => $currency, 'tax_cart' => $tax, 'shipping_1' => $shipping, 'first_name' => yab_shop_return_input('firstname|r'), 'last_name' => yab_shop_return_input('surname|r'), 'email' => $email, 'address1' => yab_shop_return_input('street|r'), 'city' => yab_shop_return_input('city|r'), 'zip' => yab_shop_return_input('postal|r'), 'state' => $state);
    $i = 0;
    foreach ($cart->get_contents() as $item) {
        $i++;
        $parameters['item_name_' . $i] = $item['name'];
        $parameters['amount_' . $i] = $item['price'];
        $parameters['quantity_' . $i] = $item['qty'];
        if (!empty($item['property_1'])) {
            $parameters['on0_' . $i] = yab_shop_lang('custom_field_property_1');
            $parameters['os0_' . $i] = $item['property_1'];
        }
        if (!empty($item['property_2'])) {
            if (!empty($item['property_3'])) {
                $parameters['on1_' . $i] = yab_shop_lang('custom_field_property_2') . '/' . yab_shop_lang('custom_field_property_3');
                $parameters['os1_' . $i] = $item['property_2'] . '/' . $item['property_3'];
            } else {
                $parameters['on1_' . $i] = yab_shop_lang('custom_field_property_2');
                $parameters['os1_' . $i] = $item['property_2'];
            }
        } else {
            if (!empty($item['property_3'])) {
                $parameters['on1_' . $i] = yab_shop_lang('custom_field_property_3');
                $parameters['os1_' . $i] = $item['property_3'];
            }
        }
    }
    if (ps('email')) {
        $parameters['email'] = yab_shop_return_input('email');
    }
    $encryptedButton = $paypal->encryptButton($parameters);
    $form = '<script type="text/javascript">function doPaypal(){var New="' . $message2 . '";document.getElementById("yabshoppaypalforward").innerHTML=New;document.getElementById("yab-paypal-form").submit();document.getElementById("yabpaypalsubmit").style.display="none"}window.onload=doPaypal;</script>';
    $form .= graf($message, ' class="yab-shop-message" id="yabshoppaypalforward"');
    $form .= tag(hInput('cmd', '_s-xclick') . n . hInput('encrypted', $encryptedButton) . n . fInput('submit', 'paypal', yab_shop_lang('checkout_paypal_button'), 'submit', '', '', '', '', 'yabpaypalsubmit') . n, 'form', ' method="post" action="' . $action . '" id="yab-paypal-form"');
    switch ($paypal->error) {
        case 0:
            $out = $form;
            break;
        case 1:
            $out = 'Paypal certificate id is not set!';
            break;
        case 2:
            $out = 'Your public and/or private certificate is not readable! Please check permissions, names and paths!';
            break;
        case 3:
            $out = 'Paypal public certificate is not readable! Please check permissions, names and paths!';
            break;
        case 4:
            $out = 'Seems to be openssl is not supported!';
            break;
        default:
            $out = 'Unkown error occured!';
    }
    return $out;
}