function get_request_url($order_id) { $user = learn_press_get_current_user(); $nonce = wp_create_nonce('learn-press-paypal-nonce'); $order = LP_Order::instance($order_id); $custom = array('order_id' => $order_id, 'order_key' => $order->order_key); $query = array('cmd' => '_xclick', 'amount' => learn_press_get_cart_total(), 'quantity' => '1', 'business' => $this->paypal_email, 'item_name' => learn_press_get_cart_description(), 'return' => add_query_arg(array('learn-press-transaction-method' => 'paypal-standard', 'paypal-nonce' => $nonce), learn_press_get_cart_course_url()), 'currency_code' => learn_press_get_currency(), 'notify_url' => get_site_url() . '/?' . learn_press_get_web_hook('paypal-standard') . '=1', 'no_note' => '1', 'shipping' => '0', 'email' => $user->user_email, 'rm' => '2', 'cancel_return' => learn_press_get_cart_course_url(), 'custom' => json_encode($custom), 'no_shipping' => '1'); $query = apply_filters('learn_press_paypal_standard_query', $query); $paypal_payment_url = $this->paypal_url . '?' . http_build_query($query); return $paypal_payment_url; }
function get_paypal_basic_request_url($order) { $settings = get_option('_lpr_settings_payment'); if (empty($settings['paypal'])) { return; } $paypal_settings = $settings['paypal']; $user = learn_press_get_current_user(); $paypal_args = array('cmd' => '_xclick', 'amount' => learn_press_get_cart_total(), 'quantity' => '1'); $transaction = learn_press_generate_transaction_object(); $temp_id = learn_press_uniqid(); $xxx = @file_get_contents(LPR_PLUGIN_PATH . '/temp.txt'); learn_press_set_transient_transaction('lpps', $temp_id, $user->ID, $transaction); file_put_contents(LPR_PLUGIN_PATH . '/temp.txt', $xxx . "=" . $temp_id); /*$order_id = LearnPress()->session->get( 'learn_press_user_order' ); $order_id = learn_press_add_transaction( array( 'method' => $this->method, 'method_id' => '', 'status' => '', 'user_id' => null, 'order_id' => $order_id, 'parent' => 0, 'transaction_object' => $transaction ) ); //LearnPress()->session->set( 'learn_press_user_order', $order_id ); $order = new LPR_Order( $order_id );*/ $nonce = wp_create_nonce('learn-press-paypal-nonce'); $paypal_email = $paypal_settings['sandbox'] ? $paypal_settings['paypal_sandbox_email'] : $paypal_settings['paypal_email']; $query = array('business' => $paypal_email, 'item_name' => learn_press_get_cart_description(), 'return' => add_query_arg(array('learn-press-transaction-method' => 'paypal-standard', 'paypal-nonce' => $nonce), learn_press_get_cart_course_url()), 'currency_code' => learn_press_get_currency(), 'notify_url' => get_site_url() . '/?' . learn_press_get_web_hook('paypal-standard') . '=1', 'no_note' => '1', 'shipping' => '0', 'email' => $user->user_email, 'rm' => '2', 'cancel_return' => learn_press_get_cart_course_url(), 'custom' => $temp_id, 'no_shipping' => '1'); $query = array_merge($paypal_args, $query); $query = apply_filters('it_exchange_paypal_standard_query', $query); $paypal_payment_url = ($paypal_settings['sandbox'] ? $this->paypal_payment_sandbox_url : $this->paypal_payment_live_url) . '?' . http_build_query($query); return $paypal_payment_url; }
function learn_press_update_order_items($order_id) { if (!($order = learn_press_get_order($order_id))) { return; } $subtotal = 0; $total = 0; if ($items = $order->get_items()) { /* [name] => What is LearnPress? [id] => 214 [course_id] => 650 [quantity] => 1 [subtotal] => 1.9 [total] => 1.9 */ foreach ($items as $item) { $subtotal += $item['subtotal']; $total += $item['total']; } } update_post_meta($order_id, '_order_currency', learn_press_get_currency()); update_post_meta($order_id, '_prices_include_tax', 'no'); //update_post_meta( $order_id, '_user_ip_address', learn_press_get_ip() ); //update_post_meta( $order_id, '_user_agent', isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '' ); //update_post_meta( $order_id, '_user_id', learn_press_get_current_user_id() ); update_post_meta($order_id, '_order_subtotal', $subtotal); update_post_meta($order_id, '_order_total', $total); update_post_meta($order_id, '_order_key', apply_filters('learn_press_generate_order_key', uniqid('order'))); update_post_meta($order_id, '_payment_method', ''); update_post_meta($order_id, '_payment_method_title', ''); update_post_meta($order_id, '_order_version', '1.0'); return array('subtotal' => $subtotal, 'total' => $total, 'currency' => learn_press_get_currency()); }
function learn_press_generate_transaction_object() { $cart = learn_press_get_cart(); if ($products = $cart->get_products()) { foreach ($products as $key => $product) { $products[$key]['product_base_price'] = floatval(learn_press_get_course_price($product['id'])); $products[$key]['product_subtotal'] = floatval(learn_press_get_course_price($product['id']) * $product['quantity']); $products[$key]['product_name'] = get_the_title($product['id']); $products = apply_filters('learn_press_generate_transaction_object_products', $products, $key, $product); } } $transaction_object = new stdClass(); $transaction_object->cart_id = $cart->get_cart_id(); $transaction_object->total = round($cart->get_total(), 2); $transaction_object->sub_total = $cart->get_sub_total(); $transaction_object->currency = learn_press_get_currency(); $transaction_object->description = learn_press_get_cart_description(); $transaction_object->products = $products; $transaction_object->coupons = ''; $transaction_object->coupons_total_discount = ''; $transaction_object = apply_filters('learn_press_generate_transaction_object', $transaction_object); return $transaction_object; }
function get_request_url($order_id) { $user = learn_press_get_current_user(); $sandbox = LP()->settings->get('paypal_sandbox') == 'yes'; $payment_form = ''; $paypal_api_url = $sandbox ? $this->paypal_nvp_api_sandbox_url : $this->paypal_nvp_api_live_url; // PAYPAL_NVP_API_SANDBOX_URL : PAYPAL_NVP_API_LIVE_URL; $paypal_payment_url = $sandbox ? $this->paypal_payment_sandbox_url : $this->paypal_payment_sandbox_url; //'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr'; $paypal_email = $sandbox ? LP()->settings->get('paypal_sandbox_email') : LP()->settings->get('paypal_email'); $paypal_api_username = $sandbox ? LP()->settings->get('paypal_sandbox_api_username') : LP()->settings->get('paypal_api_username'); $paypal_api_password = $sandbox ? LP()->settings->get('paypal_sandbox_api_password') : LP()->settings->get('paypal_api_password'); $paypal_api_signature = $sandbox ? LP()->settings->get('paypal_sandbox_api_signature') : LP()->settings->get('paypal_api_signature'); if (!empty($paypal_email) && !empty($paypal_api_username) && !empty($paypal_api_password) && !empty($paypal_api_signature)) { remove_filter('the_title', 'wptexturize'); // remove this because it screws up the product titles in PayPal $temp_id = learn_press_uniqid(); $button_request = array('USER' => trim($paypal_api_username), 'PWD' => trim($paypal_api_password), 'SIGNATURE' => trim($paypal_api_signature), 'VERSION' => '96.0', 'METHOD' => 'BMCreateButton', 'BUTTONCODE' => 'ENCRYPTED', 'BUTTONIMAGE' => 'REG', 'BUYNOWTEXT' => 'PAYNOW'); $button_request['BUTTONTYPE'] = 'BUYNOW'; //$L_BUTTONVARS[] = 'amount=' . learn_press_get_cart_total(); //$L_BUTTONVARS[] = 'quantity=1'; $nonce = wp_create_nonce('learn-press-paypal-nonce'); $L_BUTTONVARS[] = 'business=' . $paypal_email; //$L_BUTTONVARS[] = 'item_name=' . learn_press_get_cart_description(); $L_BUTTONVARS[] = 'return=' . add_query_arg(array('learn-press-transaction-method' => 'paypal-standard-secure', 'paypal-nonce' => $nonce), learn_press_get_cart_course_url()); $L_BUTTONVARS[] = 'currency_code=' . learn_press_get_currency(); //$general_settings['default-currency']; $L_BUTTONVARS[] = 'notify_url=' . learn_press_get_web_hook('paypal-standard-secure'); //http://lessbugs.com/paypal/paypal_ipn.php';// . get_site_url() . '/?paypal-stardard-secure=1' ; $L_BUTTONVARS[] = 'no_note=1'; $L_BUTTONVARS[] = 'shipping=0'; $L_BUTTONVARS[] = 'email=' . $user->user_email; $L_BUTTONVARS[] = 'rm=2'; //Return Method - https://developer.paypal.com/webapps/developer/docs/classic/button-manager/integration-guide/ButtonManagerHTMLVariables/ $L_BUTTONVARS[] = 'cancel_return=' . learn_press_get_cart_course_url(); $L_BUTTONVARS[] = 'custom=' . $temp_id; $L_BUTTONVARS[] = 'no_shipping=1'; foreach ($this->get_item_lines() as $k => $v) { $L_BUTTONVARS[] = "{$k}={$v}"; } $L_BUTTONVARS = apply_filters('learn_press_paypal_standard_secure_button_vars', $L_BUTTONVARS); $count = 0; foreach ($L_BUTTONVARS as $L_BUTTONVAR) { $button_request['L_BUTTONVAR' . $count] = $L_BUTTONVAR; $count++; } //print_r($button_request);die(); $button_request = apply_filters('learn_press_paypal_standard_secure_button_request', $button_request); $response = wp_remote_post($paypal_api_url, array('body' => $button_request)); if (!is_wp_error($response)) { parse_str(wp_remote_retrieve_body($response), $response_array); if (!empty($response_array['ACK']) && 'Success' === $response_array['ACK']) { if (!empty($response_array['WEBSITECODE'])) { $payment_form = str_replace(array("\r\n", "\r", "\n"), '', stripslashes($response_array['WEBSITECODE'])); } } } else { print_r($response); } if (preg_match('/-----BEGIN PKCS7-----.*-----END PKCS7-----/i', $payment_form, $matches)) { $query = array('cmd' => '_s-xclick', 'encrypted' => $matches[0]); $paypal_payment_url = $paypal_payment_url . '?' . http_build_query($query); return $paypal_payment_url; } else { echo $payment_form; } } return false; }
function get_paypal_args($order) { $this->prepare_line_items(); $user = learn_press_get_current_user(); $nonce = wp_create_nonce('learn-press-paypal-nonce'); $custom = array('order_id' => $order->id, 'order_key' => $order->order_key); $args = array_merge(array('cmd' => '_cart', 'business' => $this->paypal_email, 'no_note' => 1, 'currency_code' => learn_press_get_currency(), 'charset' => 'utf-8', 'rm' => is_ssl() ? 2 : 1, 'upload' => 1, 'return' => esc_url($this->get_return_url($order)), 'cancel_return' => esc_url(learn_press_is_enable_cart() ? learn_press_get_page_link('cart') : get_site_url()), 'bn' => 'LearnPress_Cart', 'custom' => json_encode($custom), 'notify_url' => get_site_url() . '/?' . learn_press_get_web_hook('paypal') . '=1', 'email' => $user->user_email), $this->get_item_lines()); //print_r($args);die(); return apply_filters('learn_press_paypal_args', $args); }
function learn_press_get_currency_symbol($currency = '') { if (!$currency) { $currency = learn_press_get_currency(); } switch ($currency) { case 'AED': $currency_symbol = 'د.إ'; break; case 'AUD': case 'CAD': case 'CLP': case 'COP': case 'HKD': case 'MXN': case 'NZD': case 'SGD': case 'USD': $currency_symbol = '$'; break; case 'BDT': $currency_symbol = '৳ '; break; case 'BGN': $currency_symbol = 'лв.'; break; case 'BRL': $currency_symbol = 'R$'; break; case 'CHF': $currency_symbol = 'CHF'; break; case 'CNY': case 'JPY': case 'RMB': $currency_symbol = '¥'; break; case 'CZK': $currency_symbol = 'Kč'; break; case 'DKK': $currency_symbol = 'kr.'; break; case 'DOP': $currency_symbol = 'RD$'; break; case 'EGP': $currency_symbol = 'EGP'; break; case 'EUR': $currency_symbol = '€'; break; case 'GBP': $currency_symbol = '£'; break; case 'HRK': $currency_symbol = 'Kn'; break; case 'HUF': $currency_symbol = 'Ft'; break; case 'IDR': $currency_symbol = 'Rp'; break; case 'ILS': $currency_symbol = '₪'; break; case 'INR': $currency_symbol = 'Rs.'; break; case 'ISK': $currency_symbol = 'Kr.'; break; case 'KIP': $currency_symbol = '₭'; break; case 'KRW': $currency_symbol = '₩'; break; case 'MYR': $currency_symbol = 'RM'; break; case 'NGN': $currency_symbol = '₦'; break; case 'NOK': $currency_symbol = 'kr'; break; case 'NPR': $currency_symbol = 'Rs.'; break; case 'PHP': $currency_symbol = '₱'; break; case 'PLN': $currency_symbol = 'zł'; break; case 'PYG': $currency_symbol = '₲'; break; case 'RON': $currency_symbol = 'lei'; break; case 'RUB': $currency_symbol = 'руб.'; break; case 'SEK': $currency_symbol = 'kr'; break; case 'THB': $currency_symbol = '฿'; break; case 'TRY': $currency_symbol = '₺'; break; case 'TWD': $currency_symbol = 'NT$'; break; case 'UAH': $currency_symbol = '₴'; break; case 'VND': $currency_symbol = '₫'; break; case 'ZAR': $currency_symbol = 'R'; break; default: $currency_symbol = $currency; break; } return apply_filters('learn_press_currency_symbol', $currency_symbol, $currency); }