function invoice_refdate($order_id, $invoice_ref)
 {
     $order = get_post_meta($order_id, '_order_postmeta', true);
     // On r�cup�re la r�f�rence
     //$invoice_ref = 'FA'.date('ym').'-0001';
     // On r�cup�re la date de facturation
     $invoice_add_date = substr($order['order_date'], 0, 10);
     // On r�cup�re la date d'�ch�ance
     //$invoice_max_date = '';
     // Positionnement
     $this->SetY(25);
     $this->SetX(135);
     $this->SetFont('', 'B', 14);
     $this->Cell(50, 5, utf8_decode(__('Ref. : ', 'wpshop')) . $invoice_ref, 0, 1, 'L');
     // Positionnement
     $this->SetX(135);
     $this->SetFont('', '', 9);
     $this->Cell(50, 4, utf8_decode(__('Billing date : ', 'wpshop')) . $invoice_add_date, 0, 1, 'L');
     $this->SetX(135);
     $this->SetFont('', '', 9);
     $this->Cell(50, 4, utf8_decode(__('Payment method : ', 'wpshop')) . utf8_decode(wpshop_payment::get_payment_method($order_id)), 0, 1, 'L');
     $this->SetX(135);
     $this->SetFont('', '', 9);
     $this->Cell(50, 4, utf8_decode(__('Transaction id : ', 'wpshop')) . wpshop_payment::get_payment_transaction_number($order_id), 0, 1, 'L');
     //$this->SetX(135);
     //$this->Cell(50, 4, utf8_decode(__( 'Date d\'�ch�ance : ', 'wpshop' )) . $invoice_max_date,0,1,'L');
     return $invoice_ref . '_' . $invoice_add_date;
 }
예제 #2
0
 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);
     }
 }