function display_response() { // Begin Main : Retrieve Variables posted by CMCIC Payment Server $CMCIC_bruteVars = wpshop_tools::getMethode(); // TPE init variables $oTpe = new CMCIC_Tpe(); $oHmac = new CMCIC_Hmac($oTpe); // Message Authentication $cgi2_fields = sprintf(CMCIC_CGI2_FIELDS, $oTpe->sNumero, $CMCIC_bruteVars["date"], $CMCIC_bruteVars['montant'], $CMCIC_bruteVars['reference'], $CMCIC_bruteVars['texte-libre'], $oTpe->sVersion, $CMCIC_bruteVars['code-retour'], $CMCIC_bruteVars['cvx'], $CMCIC_bruteVars['vld'], $CMCIC_bruteVars['brand'], $CMCIC_bruteVars['status3ds'], $CMCIC_bruteVars['numauto'], $CMCIC_bruteVars['motifrefus'], $CMCIC_bruteVars['originecb'], $CMCIC_bruteVars['bincb'], $CMCIC_bruteVars['hpancb'], $CMCIC_bruteVars['ipclient'], $CMCIC_bruteVars['originetr'], $CMCIC_bruteVars['veres'], $CMCIC_bruteVars['pares']); if ($oHmac->computeHmac($cgi2_fields) == strtolower($CMCIC_bruteVars['MAC'])) { wpshop_payment::save_payment_return_data($CMCIC_bruteVars['reference']); $payment_status = 'denied'; switch ($CMCIC_bruteVars['code-retour']) { case "Annulation": // Attention : an autorization may still be delivered for this payment //wpshop_payment::setOrderPaymentStatus($CMCIC_bruteVars['reference'], 'denied'); $payment_status = 'denied'; break; case "payetest": // test //wpshop_payment::setOrderPaymentStatus($CMCIC_bruteVars['reference'], 'completed'); $payment_status = 'completed'; break; case "paiement": // prod // Save cic txn_id // update_post_meta($CMCIC_bruteVars['reference'], '_order_cic_txn_id', $CMCIC_bruteVars['numauto']); //wpshop_payment::set_payment_transaction_number($CMCIC_bruteVars['reference'], $CMCIC_bruteVars['numauto']); //wpshop_payment::setOrderPaymentStatus($CMCIC_bruteVars['reference'], 'completed'); $payment_status = 'completed'; break; /*** ONLY FOR MULTIPART PAYMENT ***/ /*** ONLY FOR MULTIPART PAYMENT ***/ case "paiement_pf2": case "paiement_pf3": case "paiement_pf4": // Payment has been accepted on the productive server for the part #N // return code is like paiement_pf[#N] // put your code here (email sending / Database update) // You have the amount of the payment part in $CMCIC_bruteVars['montantech'] break; case "Annulation_pf2": case "Annulation_pf3": case "Annulation_pf4": // Payment has been refused on the productive server for the part #N // return code is like Annulation_pf[#N] // put your code here (email sending / Database update) // You have the amount of the payment part in $CMCIC_bruteVars['montantech'] break; } $order_meta = get_post_meta($CMCIC_bruteVars['reference'], '_order_postmeta', true); $params_array = array('method' => 'cic', 'waited_amount' => number_format((double) $order_meta['order_amount_to_pay_now'], 2, '.', ''), 'status' => $payment_status == 'completed' ? number_format((double) $order_meta['order_amount_to_pay_now'], 2, '.', '') == number_format((double) substr($CMCIC_bruteVars['montant'], 0, -3), 2, '.', '') ? 'payment_received' : 'incorrect_amount' : $payment_status, 'author' => $order_meta['customer_id'], 'payment_reference' => $CMCIC_bruteVars['numauto'], 'date' => current_time('mysql', 0), 'received_amount' => number_format((double) substr($CMCIC_bruteVars['montant'], 0, -3), 2, '.', '')); wpshop_payment::check_order_payment_total_amount($CMCIC_bruteVars['reference'], $params_array, $payment_status); $receipt = CMCIC_CGI2_MACOK; } else { // your code if the HMAC doesn't match $receipt = CMCIC_CGI2_MACNOTOK . $cgi2_fields; } // Send receipt to CMCIC server printf(CMCIC_CGI2_RECEIPT, $receipt); }
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); } }