Exemplo n.º 1
0
function eme_paypal_form($event, $payment, $price, $lang, $multi_booking = 0)
{
    global $post;
    $quantity = 1;
    $charge = eme_payment_provider_extra_charge($price, 'paypal');
    $price += $charge;
    $events_page_link = eme_get_events_page(true, false);
    $payment_id = $payment['id'];
    if ($multi_booking) {
        $success_link = get_permalink($post->ID);
        $fail_link = $success_link;
        $name = __("Multiple booking request", "eme");
    } else {
        $success_link = eme_payment_return_url($event, $payment, 1);
        $fail_link = eme_payment_return_url($event, $payment, 2);
        $name = eme_sanitize_html(sprintf(__("Booking for '%s'", "eme"), $event['event_name']));
    }
    $notification_link = add_query_arg(array('eme_eventAction' => 'paypal_notification'), $events_page_link);
    $button_above = eme_replace_payment_provider_placeholders(get_option('eme_paypal_button_above'), $charge, $event['currency'], $lang);
    $button_label = eme_replace_payment_provider_placeholders(get_option('eme_paypal_button_label'), $charge, $event['currency'], $lang);
    $button_below = eme_replace_payment_provider_placeholders(get_option('eme_paypal_button_below'), $charge, $event['currency'], $lang);
    $button_img_url = get_option('eme_paypal_button_img_url');
    require_once "payment_gateways/paypal/Paypal.php";
    $p = new Paypal();
    // the paypal or paypal sandbox url
    $p->paypal_url = get_option('eme_paypal_url');
    // the timeout in seconds before the button form is submitted to paypal
    // this needs the included addevent javascript function
    // 0 = no delay
    // false = disable auto submission
    $p->timeout = false;
    // the button label
    // false to disable button (if you want to rely only on the javascript auto-submission) not recommended
    $button_label = htmlentities($button_label);
    $p->button = $button_label;
    if (!empty($button_img_url)) {
        $p->button_img_url = $button_img_url;
    }
    if (get_option('eme_paypal_s_encrypt')) {
        // use encryption (strongly recommended!)
        $p->encrypt = true;
        $p->private_key = get_option('eme_paypal_s_privkey');
        $p->public_cert = get_option('eme_paypal_s_pubcert');
        $p->paypal_cert = get_option('eme_paypal_s_paypalcert');
        $p->cert_id = get_option('eme_paypal_s_certid');
    } else {
        $p->encrypt = false;
    }
    // the actual button parameters
    // https://www.paypal.com/IntegrationCenter/ic_std-variable-reference.html
    $p->add_field('charset', 'utf-8');
    $p->add_field('business', get_option('eme_paypal_business'));
    $p->add_field('return', $success_link);
    $p->add_field('cancel_return', $fail_link);
    $p->add_field('notify_url', $notification_link);
    $p->add_field('item_name', $name);
    $p->add_field('item_number', $payment_id);
    $p->add_field('currency_code', $event['currency']);
    $p->add_field('amount', $price);
    $p->add_field('quantity', $quantity);
    $p->add_field('no_shipping', 1);
    if (get_option('eme_paypal_no_tax')) {
        $p->add_field('tax', 0);
    }
    $form_html = $button_above;
    $form_html .= $p->get_button();
    $form_html .= $button_below;
    return $form_html;
}
Exemplo n.º 2
0
function eme_replace_booking_placeholders($format, $event, $booking, $is_multibooking = 0, $target = "html", $lang = '')
{
    $deprecated = get_option('eme_deprecated');
    preg_match_all("/#(ESC)?_?[A-Za-z0-9_]+(\\{[A-Za-z0-9_]+\\})?/", $format, $placeholders);
    $person = eme_get_person($booking['person_id']);
    $current_userid = get_current_user_id();
    $answers = eme_get_answers($booking['booking_id']);
    $payment_id = eme_get_booking_payment_id($booking['booking_id']);
    $payment = eme_get_payment($payment_id);
    $booking_ids = array();
    $bookings = array();
    if ($payment_id) {
        $booking_ids = eme_get_payment_booking_ids($payment_id);
        $bookings = eme_get_bookings($booking_ids);
    }
    usort($placeholders[0], 'sort_stringlenth');
    foreach ($placeholders[0] as $result) {
        $replacement = '';
        $found = 1;
        $need_escape = 0;
        $orig_result = $result;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        }
        if (preg_match('/#_RESPID/', $result)) {
            $replacement = $person['person_id'];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_RESP(NAME|LASTNAME|FIRSTNAME|ZIP|CITY|STATE|COUNTRY|ADDRESS1|ADDRESS2|PHONE|EMAIL)/', $result)) {
            $field = preg_replace("/#_RESP/", "", $result);
            $field = strtolower($field);
            if ($field == "name") {
                $field = "lastname";
            }
            $replacement = $person[$field];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_(RESPCOMMENT|COMMENT)/', $result)) {
            $replacement = $booking['booking_comment'];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif ($deprecated && preg_match('/#_RESPSPACES(\\d+)/', $result, $matches) || preg_match('/#_RESPSPACES\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]) - 1;
            if (eme_is_multi($booking['booking_price'])) {
                $seats = eme_convert_multi2array($booking['booking_seats_mp']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif (preg_match('/#_TOTALPRICE$/', $result)) {
            $price = eme_get_total_booking_price($event, $booking);
            $replacement = sprintf("%01.2f", $price);
        } elseif (preg_match('/#_BOOKINGPRICEPERSEAT$/', $result)) {
            $price = eme_get_seat_booking_price($event, $booking);
            $replacement = sprintf("%01.2f", $price);
        } elseif (preg_match('/#_BOOKINGPRICEPERSEAT\\{(\\d+)\\}/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_seat_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_TOTALPRICE\\{(\\d+)\\}/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_total_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif ($deprecated && preg_match('/#_TOTALPRICE(\\d+)/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_total_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_CHARGE\\{(.+)\\}$/', $result, $matches)) {
            $price = eme_get_total_booking_price($event, $booking);
            $replacement = eme_payment_provider_extra_charge($price, $matches[1]);
        } elseif (preg_match('/#_RESPSPACES$/', $result)) {
            $replacement = eme_get_multitotal($booking['booking_seats']);
        } elseif (preg_match('/#_BOOKINGCREATIONDATE/', $result)) {
            $replacement = eme_localised_date($booking['creation_date']);
        } elseif (preg_match('/#_BOOKINGMODIFDATE/', $result)) {
            $replacement = eme_localised_date($booking['modif_date']);
        } elseif (preg_match('/#_BOOKINGCREATIONTIME/', $result)) {
            $replacement = eme_localised_time($booking['creation_date']);
        } elseif (preg_match('/#_BOOKINGMODIFTIME/', $result)) {
            $replacement = eme_localised_time($booking['modif_date']);
        } elseif (preg_match('/#_BOOKINGID/', $result)) {
            $replacement = $booking['booking_id'];
        } elseif (preg_match('/#_TRANSFER_NBR_BE97/', $result)) {
            $replacement = $booking['transfer_nbr_be97'];
        } elseif (preg_match('/#_PAYMENT_URL/', $result)) {
            if ($payment_id && eme_event_can_pay_online($event)) {
                $replacement = eme_payment_url($payment_id);
            }
        } elseif (preg_match('/#_CANCEL_LINK$/', $result)) {
            $url = eme_cancel_url($payment['random_id']);
            $replacement = "<a href='{$url}'>" . __('Cancel booking', 'eme') . "</a>";
        } elseif (preg_match('/#_CANCEL_URL$/', $result)) {
            $replacement = eme_cancel_url($payment['random_id']);
        } elseif (preg_match('/#_CANCEL_CODE$/', $result)) {
            $replacement = $payment['random_id'];
        } elseif (preg_match('/#_FIELDS/', $result)) {
            $field_replace = "";
            foreach ($answers as $answer) {
                $tmp_answer = eme_convert_answer2tag($answer);
                $field_replace .= $answer['field_name'] . ": {$tmp_answer}\n";
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_PAYED/', $result)) {
            $replacement = $booking['booking_payed'] ? __('Yes') : __('No');
        } elseif ($deprecated && preg_match('/#_FIELDNAME(\\d+)/', $result, $matches) || preg_match('/#_FIELDNAME\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            $replacement = eme_trans_sanitize_html($formfield['field_name'], $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif ($deprecated && preg_match('/#_FIELD(\\d+)/', $result, $matches) || preg_match('/#_FIELD\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            $field_replace = "";
            foreach ($answers as $answer) {
                if ($answer['field_name'] == $formfield['field_name']) {
                    $tmp_answer = eme_convert_answer2tag($answer);
                    $field_replace = $tmp_answer;
                }
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_FIELDVALUE\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            foreach ($answers as $answer) {
                if ($answer['field_name'] == $formfield['field_name']) {
                    if (is_array($answer['answer'])) {
                        $tmp_answer = eme_convert_array2multi($answer['answer']);
                    } else {
                        $tmp_answer = $answer['answer'];
                    }
                    $field_replace = $tmp_answer;
                }
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_MULTIBOOKING_SEATS$/', $result)) {
            if ($is_multibooking) {
                // returns the total of all seats for all bookings in the payment id related to this booking
                $replacement = eme_bookings_total_booking_seats($bookings);
            }
        } elseif (preg_match('/#_MULTIBOOKING_TOTALPRICE$/', $result)) {
            if ($is_multibooking) {
                // returns the price for all bookings in the payment id related to this booking
                $price = eme_bookings_total_booking_price($bookings);
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_MULTIBOOKING_DETAILS_TEMPLATE\\{(\\d+)\\}$/', $result, $matches)) {
            $template_id = intval($matches[1]);
            $template = eme_get_template_format($template_id);
            $res = "";
            if ($template && $is_multibooking) {
                // don't let eme_replace_placeholders replace other shortcodes yet, let eme_replace_booking_placeholders finish and that will do it
                foreach ($bookings as $tmp_booking) {
                    $tmp_event = eme_get_event_by_booking_id($tmp_booking['booking_id']);
                    $tmp_res = eme_replace_placeholders($template, $tmp_event, "text", 0);
                    $res .= eme_replace_booking_placeholders($tmp_res, $tmp_event, $tmp_booking, $is_multibooking, "text") . "\n";
                }
            }
            $replacement = $res;
        } elseif (preg_match('/#_IS_MULTIBOOKING/', $result)) {
            $replacement = $is_multibooking;
        } else {
            $found = 0;
        }
        if ($found) {
            if ($need_escape) {
                $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
            }
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    // now, replace any language tags found in the format itself
    $format = eme_translate($format, $lang);
    return do_shortcode($format);
}