function wpshop_ajax_validate_payment_method() { check_ajax_referer('wpshop_validate_payment_method', 'wpshop_ajax_nonce'); $order_id = isset($_POST['order_id']) && !empty($_POST['order_id']) ? $_POST['order_id'] : null; $payment_method = isset($_POST['payment_method']) && !empty($_POST['payment_method']) ? $_POST['payment_method'] : null; $transaction_id = isset($_POST['transaction_id']) && !empty($_POST['transaction_id']) ? $_POST['transaction_id'] : null; if (!empty($order_id)) { if (!empty($payment_method) && !empty($transaction_id)) { /* Update he payment method */ $order = get_post_meta($order_id, '_order_postmeta', true); $order['payment_method'] = $payment_method; update_post_meta($order_id, '_order_postmeta', $order); // Update Transaction identifier regarding the payment method if (!empty($transaction_id)) { // $transaction_key = ''; // switch($payment_method) { // case 'check': // $transaction_key = '_order_check_number'; // break; // } // if ( !empty($transaction_key) ) update_post_meta($order_id, $transaction_key, $transaction_id); wpshop_payment::set_payment_transaction_number($order_id, $transaction_id); } $result = json_encode(array(true, '')); } else { $result = json_encode(array(false, __('Choose a payment method and/or type a transaction number', 'wpshop'))); } } else { $result = json_encode(array(false, __('Bad order identifier', 'wpshop'))); } echo json_encode($result); die; }
public function __construct() { add_filter('wps_payment_mode_interface_paypal', array(&$this, 'display_admin_part')); /** Check if SystemPay is registred in Payment Main Option **/ $payment_option = get_option('wps_payment_mode'); if (!empty($payment_option) && !empty($payment_option['mode']) && !array_key_exists('paypal', $payment_option['mode'])) { $payment_option['mode']['paypal']['name'] = __('Paypal', 'wpshop'); $payment_option['mode']['paypal']['logo'] = WPSHOP_TEMPLATES_URL . 'wpshop/medias/paypal.png'; $payment_option['mode']['paypal']['description'] = __('<strong>Tips</strong> : If you have a Paypal account, by choosing this payment method, you will be redirected to the secure payment site Paypal to make your payment. Debit your PayPal account, immediate booking products.', 'wpshop'); update_option('wps_payment_mode', $payment_option); } if (!empty($_GET['paymentListener']) && $_GET['paymentListener'] == 'paypal') { $payment_status = 'denied'; // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } // If testing on Sandbox use: $paypalMode = get_option('wpshop_paypalMode', null); if ($paypalMode == 'sandbox') { $fp = fsockopen('ssl://sandbox.paypal.com', 443, $errno, $errstr, 30); $host = "www.sandbox.paypal.com"; } else { $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30); $host = "www.paypal.com"; } // post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Host: " . $host . "\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; /* Variables */ $customer_id = $_POST['custom']; // id client $shipping = $_POST['mc_shipping']; // frais de livraison $business = $_POST['business']; // compte pro $order_id = (int) $_POST['invoice']; // num de facture $receiver_email = $_POST['receiver_email']; $amount_paid = $_POST['mc_gross']; // total (hors frais livraison) $txn_id = $_POST['txn_id']; // num�ro de transaction $payment_status = $_POST['payment_status']; // status du paiement $payer_email = $_POST['payer_email']; // email du client $txn_type = $_POST['txn_type']; if (!empty($_POST)) { foreach ($_POST as $key => $value) { if (substr($key, 0, 9) == 'item_name') { $_POST[$key] = htmlentities($value); } } } /** Save paypal return data automatically */ wpshop_payment::save_payment_return_data($order_id); $notify_email = get_option('wpshop_paypalEmail', null); // email address to which debug emails are sent to if (!$fp) { echo 'HTTP ERROR!'; } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, "VERIFIED") == 0) { $paypalBusinessEmail = get_option('wpshop_paypalEmail', null); /** Check if payment has been send to good paypal account */ if ($receiver_email == $paypalBusinessEmail) { /** Get the payment transaction identifier */ $paypal_txn_id = wpshop_payment::get_payment_transaction_number($order_id, wpshop_payment::get_order_waiting_payment_array_id($order_id, 'paypal')); /** If no transaction reference has been saved for this order */ if (empty($paypal_txn_id)) { /** Set the payment reference for the order */ wpshop_payment::set_payment_transaction_number($order_id, $txn_id); /** Get order content */ $order = get_post_meta($order_id, '_order_postmeta', true); /** Check the different amount : Order total / Paypal paid amount */ // $amount2pay = floatval($order['order_grand_total']); $amount2pay = number_format(floatval($order['order_amount_to_pay_now']), 2, '.', ''); $amount_paid = number_format(floatval($amount_paid), 2, '.', ''); /* Check if the paid amount is equal to the order amount */ if ($amount_paid == $amount2pay) { $payment_status = 'completed'; } else { $payment_status = 'incorrect_amount'; } } else { @mail($notify_email, 'VERIFIED DUPLICATED TRANSACTION', 'VERIFIED DUPLICATED TRANSACTION'); $payment_status = 'completed'; } } } elseif (strcmp($res, "INVALID") == 0) { @mail($notify_email, "INVALID IPN", "{$res}\n {$req}"); $payment_status = 'payment_refused'; } } fclose($fp); } $params_array = array('method' => 'paypal', 'waited_amount' => number_format((double) $order['order_amount_to_pay_now'], 2, '.', ''), 'status' => number_format((double) $order['order_amount_to_pay_now'], 2, '.', '') == number_format((double) $_POST['mc_gross'], 2, '.', '') ? 'payment_received' : 'incorrect_amount', 'author' => $order['customer_id'], 'payment_reference' => $txn_id, 'date' => current_time('mysql', 0), 'received_amount' => number_format((double) $_POST['mc_gross'], 2, '.', '')); wpshop_payment::check_order_payment_total_amount($order_id, $params_array, $payment_status); } }