Ejemplo n.º 1
0
    /**
     * Generate the skrill button link
     **/
    public function generate_skrill_form()
    {
        $order_id = $_GET['orderId'];
        $order = new fflcommerce_order($order_id);
        $skrill_adr = 'https://www.moneybookers.com/app/payment.pl';
        $shipping_name = explode(' ', $order->shipping_method);
        $order_total = trim($order->order_total, 0);
        if (substr($order_total, -1) == '.') {
            $order_total = str_replace('.', '', $order_total);
        }
        // filter redirect page
        $checkout_redirect = apply_filters('fflcommerce_get_checkout_redirect_page_id', fflcommerce_get_page_id('thanks'));
        $skrill_args = array('merchant_fields' => 'partner', 'partner' => 'FFLCommerce', 'pay_to_email' => $this->email, 'recipient_description' => get_bloginfo('name'), 'transaction_id' => $order_id, 'return_url' => get_permalink($checkout_redirect), 'return_url_text' => 'Return to Merchant', 'new_window_redirect' => 0, 'prepare_only' => 0, 'return_url_target' => 1, 'cancel_url' => trailingslashit(get_bloginfo('url')) . '?skrillListener=skrill_cancel', 'cancel_url_target' => 1, 'status_url' => trailingslashit(get_bloginfo('url')) . '?skrillListener=skrill_status', 'language' => $this->getLocale(), 'hide_login' => 1, 'confirmation_note' => __('Thank you for shopping', 'fflcommerce'), 'pay_from_email' => $order->billing_email, 'firstname' => $order->billing_first_name, 'lastname' => $order->billing_last_name, 'address' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'phone_number' => $order->billing_phone, 'postal_code' => $order->billing_postcode, 'city' => $order->billing_city, 'state' => $order->billing_state, 'country' => $this->retrieveIOC($this->getLocale()), 'amount' => $order_total, 'currency' => FFLCommerce_Base::get_options()->get_option('fflcommerce_currency'), 'detail1_description' => 'Order ID', 'detail1_text' => $order_id, 'payment_methods' => $this->payment_methods);
        // Cart Contents
        $item_loop = 0;
        if (sizeof($order->items) > 0) {
            foreach ($order->items as $item) {
                if (!empty($item['variation_id'])) {
                    $_product = new fflcommerce_product_variation($item['variation_id']);
                } else {
                    $_product = new fflcommerce_product($item['id']);
                }
                if ($_product->exists() && $item['qty']) {
                    $item_loop++;
                    $skrill_args['item_name_' . $item_loop] = $_product->get_title();
                    $skrill_args['quantity_' . $item_loop] = $item['qty'];
                    $skrill_args['amount_' . $item_loop] = $_product->get_price_with_tax();
                }
            }
        }
        // Shipping Cost
        $item_loop++;
        $skrill_args['item_name_' . $item_loop] = __('Shipping cost', 'fflcommerce');
        $skrill_args['quantity_' . $item_loop] = '1';
        $skrill_args['amount_' . $item_loop] = number_format($order->order_shipping, 2);
        $skrill_args_array = array();
        foreach ($skrill_args as $key => $value) {
            $skrill_args_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
        }
        // Skirll MD5 concatenation
        $skrill_md = FFLCommerce_Base::get_options()->get_option('fflcommerce_skrill_customer_id') . $skrill_args['transaction_id'] . strtoupper(md5(FFLCommerce_Base::get_options()->get_option('fflcommerce_skrill_secret_word'))) . $order_total . FFLCommerce_Base::get_options()->get_option('fflcommerce_currency') . '2';
        $skrill_md = md5($skrill_md);
        add_post_meta($order_id, '_skrillmd', $skrill_md);
        echo '<form name="moneybookers" id="moneybookers_place_form" action="' . $skrill_adr . '" method="POST">' . implode('', $skrill_args_array) . '</form>';
        echo '<script type="text/javascript">
		//<![CDATA[
    	var paymentform = document.getElementById(\'moneybookers_place_form\');
   		window.onload = paymentform.submit();
		//]]>
		</script>';
        exit;
    }
 /**
  * Calculate total 'product fixed' and 'product percentage' discounts
  *
  * @param  fflcommerce_product $_product the product we are working with
  * @param  array $values the cart values for this product
  * @return float|int|mixed|void $current_product_discount
  */
 private static function calculate_product_discounts_total($_product, $values)
 {
     $current_product_discount = 0;
     if (!empty(self::$applied_coupons)) {
         foreach (self::$applied_coupons as $code) {
             $coupon_discount = 0;
             $coupon = JS_Coupons::get_coupon($code);
             if (!JS_Coupons::is_valid_coupon_for_product($code, $values)) {
                 continue;
             }
             $price = self::get_options()->get('fflcommerce_tax_after_coupon') == 'yes' ? $_product->get_price_excluding_tax() : $_product->get_price_with_tax();
             switch ($coupon['type']) {
                 case 'fixed_product':
                     $coupon_discount = apply_filters('fflcommerce_coupon_product_fixed_amount', $coupon['amount'], $coupon) * $values['quantity'];
                     if ($coupon_discount > $price * $values['quantity']) {
                         $coupon_discount = $price * $values['quantity'];
                     }
                     break;
                 case 'percent_product':
                     $coupon_discount = $price * $values['quantity'] / 100 * $coupon['amount'];
                     break;
             }
             $current_product_discount += $coupon_discount;
         }
     }
     return $current_product_discount;
 }