示例#1
0
 public function processRequest($ip)
 {
     $this->ip = $ip;
     $parts = preg_split('/&/', $this->response);
     foreach ($parts as $part) {
         $p = preg_split('/=/', $part, 2);
         $this->results[$p[0]] = $p[1];
     }
     $this->invoice = new Web_Invoice_GetInfo(web_invoice_get_invoice_id_by_payment($this->results['VendorTxCode']));
     if (!$this->invoice) {
         return;
     }
     if ($this->results['Status'] == 'OK' && intval($this->results['Amount']) == intval($this->invoice->display('amount'))) {
         $this->approved = true;
         web_invoice_mark_as_paid($this->invoice->id);
         $this->_logSuccess($this->results['VPSTxId']);
         web_invoice_update_invoice_meta($this->invoice->id, 'transaction_id', $this->results['VPSTxId']);
         web_invoice_update_invoice_meta($this->invoice->id, 'auth_code', $this->results['TxAuthNo']);
     } else {
         if ($this->results['Status'] == 'NOTAUTHED') {
             $this->declined = true;
             $this->_logFailure($this->results['VPSTxId']);
             web_invoice_update_invoice_meta($this->invoice->id, 'transaction_id', $this->results['VPSTxId']);
         } else {
             $this->error = true;
             $this->_logFailure($this->results['VPSTxId']);
             web_invoice_update_invoice_meta($this->invoice->id, 'transaction_id', $this->results['VPSTxId']);
         }
     }
     wp_redirect(web_invoice_build_invoice_link($this->invoice->id));
 }
 function _processCharge($ip, $request)
 {
     $this->gc_status = $request['new-financial-order-state'];
     if (strtolower($this->gc_status) != "charged") {
         $this->_logSuccess('Payment in progress (' . $this->gc_status . ')');
         header('HTTP/1.0 200 OK');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Thank you very much for letting us know. REF: Not success';
         exit(0);
     }
     web_invoice_mark_as_paid($this->invoice->id);
 }
示例#3
0
 function processRequest($ip, $request)
 {
     $req = 'cmd=_notify-validate';
     $post_values = "";
     $cart = array();
     foreach ($request as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
         $post_values .= " {$key} : {$value}\n";
     }
     $header = "";
     // post back to PayPal system to validate
     $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     if (get_option('web_invoice_paypal_sandbox') == 'True') {
         $fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
     } else {
         $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
     }
     $this->ip = $ip;
     $this->pay_to_email = $request['receiver_email'];
     $this->pay_from_email = $request['payer_email'];
     $this->transaction_id = $request['txn_id'];
     $this->status = $request['payment_status'];
     $this->amount = $request['mc_gross'];
     $this->currency = $request['mc_currency'];
     $this->test_ipn = $request['test_ipn'];
     if (isset($request['subscr_id'])) {
         $this->recurring_payment_id = $request['subscr_id'];
     }
     if (!$this->invoice->id) {
         $this->_logFailure('Invoice not found');
         header('HTTP/1.0 404 Not Found');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Invoice not found';
         exit(0);
     }
     if ($this->currency != $this->invoice->display('currency')) {
         $this->_logFailure('Invalid currency');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: PP0';
         exit(0);
     }
     if ($this->amount != $this->invoice->display('amount')) {
         $this->_logFailure('Invalid amount');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: PP1';
         exit(0);
     }
     if ($this->pay_to_email != get_option('web_invoice_paypal_address')) {
         $this->_logFailure('Invalid pay_to_email');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: PP2';
         exit(0);
     }
     if (!$fp) {
         $this->_logFailure('Unable to verify');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: PP2';
         exit(0);
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res = fgets($fp, 1024);
             if (strcmp($res, "VERIFIED") == 0) {
                 if ($this->status == "Completed") {
                     if ($this->test_ipn == 1) {
                         if (get_option('web_invoice_paypal_sandbox') == 'True') {
                             $this->_logFailure('Test payment');
                         }
                     } else {
                         $this->_logSuccess('Paid');
                         web_invoice_mark_as_paid($this->invoice->id);
                     }
                     header('HTTP/1.0 200 OK');
                     header('Content-type: text/plain; charset=UTF-8');
                     print 'Success';
                     exit(0);
                 } else {
                     $message = "Corrupted PayPal IPN {$txn_id}, {$count}, {$receiver_email}";
                 }
             } else {
                 if (strcmp($res, "INVALID") == 0) {
                     $message = "Invalid PayPal IPN {$txn_id}";
                 }
             }
         }
         fclose($fp);
     }
     $this->_logFailure($message);
     header('HTTP/1.0 200 OK');
     header('Content-type: text/plain; charset=UTF-8');
     print 'Thank you very much for letting us know. REF: ' . $message;
     exit(0);
 }
示例#4
0
 function _processPayment($ip, $request)
 {
     $this->_logSuccess('Payment in progress (' . $this->respmsg . ')');
     web_invoice_mark_as_paid($this->invoice->id);
     header('HTTP/1.0 200 OK');
     header('Content-type: text/plain; charset=UTF-8');
     print 'Thank you very much for letting us know. REF: Paid';
 }
示例#5
0
function web_invoice_process_cc_transaction($cc_data)
{
    $errors = array();
    $errors_msg = null;
    $_POST['processing_problem'] = '';
    $stop_transaction = false;
    $invoice_id = preg_replace("/[^0-9]/", "", $_POST['invoice_num']);
    /* this is the real invoice id */
    if (web_invoice_recurring($invoice_id)) {
        $recurring = true;
    }
    $invoice = new Web_Invoice_GetInfo($invoice_id);
    // Accomodate Custom Invoice IDs by changing the post value, this is passed to Authorize.net account
    $web_invoice_custom_invoice_id = web_invoice_meta($invoice_id, 'web_invoice_custom_invoice_id');
    // If there is a custom invoice id, we're setting the $_POST['invoice_num'] to the custom id, because that is what's getting passed to authorize.net
    if ($web_invoice_custom_invoice_id) {
        $_POST['invoice_num'] = $web_invoice_custom_invoice_id;
    }
    $wp_users_id = get_web_invoice_user_id($invoice_id);
    if (empty($_POST['first_name'])) {
        $errors['first_name'][] = "Please enter your first name under billing details.";
        $stop_transaction = true;
    }
    if (empty($_POST['last_name'])) {
        $errors['last_name'][] = "Please enter your last name under billing details.";
        $stop_transaction = true;
    }
    if (empty($_POST['email_address'])) {
        $errors['email_address'][] = "Please provide an email address under billing details.";
        $stop_transaction = true;
    }
    if (empty($_POST['phonenumber'])) {
        $errors['phonenumber'][] = "Please enter your phone number under billing details.";
        $stop_transaction = true;
    }
    if (empty($_POST['address'])) {
        $errors['address'][] = "Please enter your address under billing details.";
        $stop_transaction = true;
    }
    if (empty($_POST['city'])) {
        $errors['city'][] = "Please enter your city under billing details.";
        $stop_transaction = true;
    }
    if (empty($_POST['zip'])) {
        $errors['zip'][] = "Please enter your ZIP code under billing details.";
        $stop_transaction = true;
    }
    if (empty($_POST['country'])) {
        $errors['country'][] = "Please enter your country under billing details.";
        $stop_transaction = true;
    }
    if (empty($_POST['state']) && $_POST['country'] == 'US') {
        $errors['state'][] = "Please select your state under billing details.";
        $stop_transaction = true;
    }
    if (!isset($_POST['processor']) || $_POST['processor'] != 'sagepay') {
        if (empty($_POST['card_num'])) {
            $errors['card_num'][] = "Please enter your credit card number under billing details.";
            $stop_transaction = true;
        } else {
            if (!web_invoice_validate_cc_number($_POST['card_num'])) {
                $errors['card_num'][] = "Please enter a valid credit card number.";
                $stop_transaction = true;
            }
        }
        if (empty($_POST['exp_month'])) {
            $errors['exp_month'][] = "Please enter your credit card's expiration month under billing details.";
            $stop_transaction = true;
        }
        if (empty($_POST['exp_year'])) {
            $errors['exp_year'][] = "Please enter your credit card's expiration year under billing details.";
            $stop_transaction = true;
        }
        if (empty($_POST['card_code'])) {
            $errors['card_code'][] = "The <b>Security Code</b> is the code on the back of your card under billing details.";
            $stop_transaction = true;
        }
    }
    if ($_POST['processor'] == 'pfp' && get_option('web_invoice_pfp_shipping_details') == 'True' || $_POST['processor'] == 'sagepay' && get_option('web_invoice_sagepay_shipping_details') == 'True') {
        if (empty($_POST['shipto_first_name'])) {
            $errors['shipto_first_name'][] = "Please enter your first name under shipping details.";
            $stop_transaction = true;
        }
        if (empty($_POST['shipto_last_name'])) {
            $errors['shipto_last_name'][] = "Please enter your last name under shipping details. ";
            $stop_transaction = true;
        }
        if (empty($_POST['shipto_email_address'])) {
            $errors['shipto_email_address'][] = "Please provide an email address under shipping details.";
            $stop_transaction = true;
        }
        if (empty($_POST['shipto_phonenumber'])) {
            $errors['shipto_phonenumber'][] = "Please enter your phone number under shipping details.";
            $stop_transaction = true;
        }
        if (empty($_POST['shipto_address'])) {
            $errors['shipto_address'][] = "Please enter your address under shipping details.";
            $stop_transaction = true;
        }
        if (empty($_POST['shipto_city'])) {
            $errors['shipto_city'][] = "Please enter your city under shipping details.";
            $stop_transaction = true;
        }
        if (empty($_POST['shipto_zip'])) {
            $errors['shipto_zip'][] = "Please enter your ZIP code under shipping details.";
            $stop_transaction = true;
        }
        if (empty($_POST['shipto_country'])) {
            $errors['shipto_country'][] = "Please enter your country under shipping details.";
            $stop_transaction = true;
        }
        if (empty($_POST['shipto_state']) && $_POST['shipto_country'] == 'US') {
            $errors['shipto_state'][] = "Please select your state under shipping details.";
            $stop_transaction = true;
        }
    }
    // Charge Card
    if (!$stop_transaction) {
        if (isset($_POST['processor']) && $_POST['processor'] == 'sagepay') {
            $data_arr = array();
            $data_arr['VendorTxCode'] = $invoice->display('trx_id');
            $data_arr['VendorEMail'] = get_option("web_invoice_email_address");
            $data_arr['Amount'] = $invoice->display('amount');
            $data_arr['Currency'] = $invoice->display('currency');
            $data_arr['Description'] = $invoice->display('subject');
            $data_arr['SuccessURL'] = web_invoice_build_invoice_link($invoice_id);
            $data_arr['FailureURL'] = web_invoice_build_invoice_link($invoice_id);
            $data_arr['CustomerName'] = "{$_POST['first_name']} {$_POST['last_name']}";
            $data_arr['CustomerEMail'] = $_POST['email_address'];
            $data_arr['BillingFirstnames'] = $_POST['first_name'];
            $data_arr['BillingSurname'] = $_POST['last_name'];
            $data_arr['BillingAddress1'] = $_POST['address'];
            $data_arr['BillingCity'] = $_POST['city'];
            $data_arr['BillingPostCode'] = $_POST['zip'];
            $data_arr['BillingCountry'] = $_POST['country'];
            if (!empty($_POST['state'])) {
                $data_arr['BillingState'] = substr($_POST['state'], 0, 2);
            }
            $data_arr['BillingPhone'] = $_POST['phonenumber'];
            if (get_option('web_invoice_sagepay_shipping_details') == 'True') {
                $data_arr['DeliveryFirstnames'] = $_POST['shipto_first_name'];
                $data_arr['DeliverySurname'] = $_POST['shipto_last_name'];
                $data_arr['DeliveryAddress1'] = $_POST['shipto_address'];
                $data_arr['DeliveryCity'] = $_POST['shipto_city'];
                $data_arr['DeliveryPostCode'] = $_POST['shipto_zip'];
                $data_arr['DeliveryCountry'] = $_POST['shipto_country'];
                if (!empty($_POST['shipto_state'])) {
                    $data_arr['DeliveryState'] = substr($_POST['shipto_state'], 0, 2);
                }
                $data_arr['DeliveryPhone'] = $_POST['shipto_phonenumber'];
            } else {
                $data_arr['DeliveryFirstnames'] = $_POST['first_name'];
                $data_arr['DeliverySurname'] = $_POST['last_name'];
                $data_arr['DeliveryAddress1'] = $_POST['address'];
                $data_arr['DeliveryCity'] = $_POST['city'];
                $data_arr['DeliveryPostCode'] = $_POST['zip'];
                if (!empty($_POST['state'])) {
                    $data_arr['DeliveryState'] = substr($_POST['state'], 0, 2);
                }
                $data_arr['DeliveryCountry'] = $_POST['country'];
                $data_arr['DeliveryPhone'] = $_POST['phonenumber'];
            }
            $itemized_array = $invoice->display('itemized');
            $basket = count($itemized_array);
            foreach ($itemized_array as $itemized_item) {
                $basket .= ":" . $itemized_item[name] . ":" . $itemized_item[quantity] . ":" . number_format($itemized_item[price], 2) . ":" . number_format($itemized_item[price] * ($tax / 100), 2) . ":" . number_format($itemized_item[price] * ($tax / 100) + $itemized_item[price], 2) . ":" . number_format(($itemized_item[price] * ($tax / 100) + $itemized_item[price]) * $itemized_item[quantity], 2);
            }
            $data_arr['Basket'] = $basket;
            $datas_arr = array();
            foreach ($data_arr as $key => $_val) {
                $datas_arr[] = "{$key}={$_val}";
            }
            $datas = join('&', $datas_arr);
            $enc_data = web_invoice_xor_encrypt($datas, get_option('web_invoice_sagepay_vendor_key'));
            print $enc_data;
        } else {
            if (isset($_POST['processor']) && $_POST['processor'] == 'pfp') {
                require_once 'gateways/payflowpro.class.php';
                if ($recurring) {
                    $arb = new Web_Invoice_PayflowProRecurring();
                    $arb->transaction($_POST['card_num']);
                    $arb->setTransactionType('R');
                    // Billing Info
                    $arb->setParameter("CVV2", $_POST['card_code']);
                    $arb->setParameter("EXPDATE ", $_POST['exp_month'] . substr($_POST['exp_year'], 2));
                    $arb->setParameter("AMT", $invoice->display('amount'));
                    $arb->setParameter("CURRENCYCODE", $invoice->display('currency'));
                    if ($recurring) {
                        $arb->setParameter("RECURRING", 'Y');
                    }
                    //Subscription Info
                    $arb->setParameter('BILLINGFREQUENCY', $invoice->display('interval_length'));
                    if (get_option('web_invoice_pfp_authentication') == '3token' || get_option('web_invoice_pfp_authentication') == 'unipay') {
                        $arb->setParameter('DESC', $invoice->display('subscription_name'));
                        $arb->setParameter('BILLINGPERIOD', web_invoice_pfp_convert_interval($invoice->display('interval_length'), $invoice->display('interval_unit')));
                        $arb->setParameter('PROFILESTARTDATE', date('c', strtotime($invoice->display('startDateM'))));
                        $arb->setParameter('TOTALBILLINGCYCLES', $invoice->display('totalOccurrences'));
                    } else {
                        $arb->setParameter('PROFILENAME', $invoice->display('subscription_name'));
                        $arb->setParameter('START', date('mdY', strtotime($invoice->display('startDateM')) + 3600 * 24));
                        $arb->setParameter('TERM', $invoice->display('totalOccurrences'));
                        $arb->setParameter('PAYPERIOD', web_invoice_pfp_wpppe_convert_interval($invoice->display('interval_length'), $invoice->display('interval_unit')));
                    }
                    $arb->setParameter('ACTION', 'A');
                    $arb->setParameter("CUSTBROWSER", $_SERVER['HTTP_USER_AGENT']);
                    $arb->setParameter("CUSTHOSTNAME", $_SERVER['HTTP_HOST']);
                    $arb->setParameter("CUSTIP ", $_SERVER['REMOTE_ADDR']);
                    //Customer Info
                    $arb->setParameter("FIRSTNAME", $_POST['first_name']);
                    $arb->setParameter("LASTNAME", $_POST['last_name']);
                    $arb->setParameter("STREET", $_POST['address']);
                    $arb->setParameter("CITY", $_POST['city']);
                    $arb->setParameter("STATE", $_POST['state']);
                    $arb->setParameter("COUNTRYCODE", $_POST['country']);
                    $arb->setParameter("ZIP", $_POST['zip']);
                    $arb->setParameter("PHONENUM", $_POST['phonenumber']);
                    $arb->setParameter("EMAIL", $_POST['email_address']);
                    $arb->setParameter("COMMENT1", "{$_POST['first_name']} {$_POST['last_name']} " . $invoice->display('subscription_name') . " Recurring");
                    if (get_option('web_invoice_pfp_shipping_details') == 'True') {
                        //Shipping Info
                        $arb->setParameter("SHIPTONAME", "{$_POST['shipto_first_name']} {$_POST['shipto_last_name']}");
                        $arb->setParameter("SHIPTOSTREET", $_POST['shipto_address']);
                        $arb->setParameter("SHIPTOCITY", $_POST['shipto_city']);
                        $arb->setParameter("SHIPTOSTATE", $_POST['shipto_state']);
                        $arb->setParameter("SHIPTOCOUNTRY", $_POST['shipto_country']);
                        $arb->setParameter("SHIPTOZIP", $_POST['shipto_zip']);
                        $arb->setParameter("SHIPTOPHONENUM", $_POST['shipto_phonenumber']);
                    }
                    // Order Info
                    $arb->setParameter("COMMENT2", $invoice->display('subject'));
                    $arb->setParameter("CUSTREF", $invoice->display('display_id'));
                    $arb->createAccount();
                    if ($arb->isSuccessful()) {
                        echo "Transaction okay.";
                        update_usermeta($wp_users_id, 'last_name', $_POST['last_name']);
                        update_usermeta($wp_users_id, 'first_name', $_POST['first_name']);
                        update_usermeta($wp_users_id, 'city', $_POST['city']);
                        update_usermeta($wp_users_id, 'state', $_POST['state']);
                        update_usermeta($wp_users_id, 'zip', $_POST['zip']);
                        update_usermeta($wp_users_id, 'tax_id', $_POST['tax_id']);
                        update_usermeta($wp_users_id, 'company_name', $_POST['company_name']);
                        update_usermeta($wp_users_id, 'streetaddress', $_POST['address']);
                        update_usermeta($wp_users_id, 'phonenumber', $_POST['phonenumber']);
                        update_usermeta($wp_users_id, 'country', $_POST['country']);
                        if (get_option('web_invoice_pfp_shipping_details') == 'True') {
                            update_usermeta($wp_users_id, 'shipto_last_name', $_POST['shipto_last_name']);
                            update_usermeta($wp_users_id, 'shipto_first_name', $_POST['shipto_first_name']);
                            update_usermeta($wp_users_id, 'shipto_streetaddress', $_POST['shipto_address']);
                            update_usermeta($wp_users_id, 'shipto_city', $_POST['shipto_city']);
                            update_usermeta($wp_users_id, 'shipto_state', $_POST['shipto_state']);
                            update_usermeta($wp_users_id, 'shipto_zip', $_POST['shipto_zip']);
                            update_usermeta($wp_users_id, 'shipto_phonenumber', $_POST['shipto_phonenumber']);
                            update_usermeta($wp_users_id, 'shipto_country', $_POST['shipto_country']);
                        }
                        web_invoice_update_recurring_start_date($invoice_id, strtotime(date('Y-m-d')));
                        web_invoice_update_invoice_meta($invoice_id, 'subscription_id', $arb->getSubscriberID());
                        web_invoice_update_invoice_meta($invoice_id, 'recurring_transaction_id', $arb->getTransactionID());
                        web_invoice_update_invoice_meta($invoice_id, 'pfp_status', 'active');
                        web_invoice_update_log($invoice_id, 'subscription', ' Subscription initiated, Subcription ID - ' . $arb->getSubscriberID());
                        web_invoice_paid($invoice_id);
                        web_invoice_mark_as_paid($invoice_id);
                    }
                    if ($arb->isError()) {
                        $errors['processing_problem'][] .= "One-time credit card payment is processed successfully. However, recurring billing setup failed.";
                        $stop_transaction = true;
                        web_invoice_update_log($invoice_id, 'subscription_error', 'Response Code: ' . $arb->getResponseCode() . ' | Subscription error - ' . $arb->getResponseText());
                        web_invoice_update_log($invoice_id, 'pfp_failure', "Failed PFP payment. REF: " . serialize($payment));
                    }
                } else {
                    $payment = new Web_Invoice_PayflowPro(true);
                    $payment->transaction($_POST['card_num']);
                    // Billing Info
                    $payment->setParameter("CVV2", $_POST['card_code']);
                    $payment->setParameter("EXPDATE ", $_POST['exp_month'] . substr($_POST['exp_year'], 2));
                    $payment->setParameter("AMT", $invoice->display('amount'));
                    $payment->setParameter("CURRENCYCODE", $invoice->display('currency'));
                    if ($recurring) {
                        $payment->setParameter("RECURRING", 'Y');
                    }
                    $payment->setParameter("CUSTBROWSER", $_SERVER['HTTP_USER_AGENT']);
                    $payment->setParameter("CUSTHOSTNAME", $_SERVER['HTTP_HOST']);
                    $payment->setParameter("CUSTIP ", $_SERVER['REMOTE_ADDR']);
                    //Customer Info
                    $payment->setParameter("FIRSTNAME", $_POST['first_name']);
                    $payment->setParameter("LASTNAME", $_POST['last_name']);
                    $payment->setParameter("STREET", $_POST['address']);
                    $payment->setParameter("CITY", $_POST['city']);
                    $payment->setParameter("STATE", $_POST['state']);
                    $payment->setParameter("COUNTRYCODE", $_POST['country']);
                    $payment->setParameter("ZIP", $_POST['zip']);
                    $payment->setParameter("PHONENUM", $_POST['phonenumber']);
                    $payment->setParameter("EMAIL", $_POST['email_address']);
                    $payment->setParameter("COMMENT1", "WP User - " . $invoice->recipient('user_id'));
                    if (get_option('web_invoice_pfp_shipping_details') == 'True') {
                        //Shipping Info
                        $payment->setParameter("SHIPTONAME", "{$_POST['shipto_first_name']} {$_POST['shipto_last_name']}");
                        $payment->setParameter("SHIPTOSTREET", $_POST['shipto_address']);
                        $payment->setParameter("SHIPTOCITY", $_POST['shipto_city']);
                        $payment->setParameter("SHIPTOSTATE", $_POST['shipto_state']);
                        $payment->setParameter("SHIPTOCOUNTRY", $_POST['shipto_country']);
                        $payment->setParameter("SHIPTOZIP", $_POST['shipto_zip']);
                        $payment->setParameter("SHIPTOPHONENUM", $_POST['shipto_phonenumber']);
                    }
                    // Order Info
                    $payment->setParameter("COMMENT2", $invoice->display('subject'));
                    $payment->setParameter("CUSTREF", $invoice->display('display_id'));
                    $payment->process();
                    if ($payment->isApproved()) {
                        echo "Transaction okay.";
                        update_usermeta($wp_users_id, 'last_name', $_POST['last_name']);
                        update_usermeta($wp_users_id, 'first_name', $_POST['first_name']);
                        update_usermeta($wp_users_id, 'city', $_POST['city']);
                        update_usermeta($wp_users_id, 'state', $_POST['state']);
                        update_usermeta($wp_users_id, 'zip', $_POST['zip']);
                        update_usermeta($wp_users_id, 'tax_id', $_POST['tax_id']);
                        update_usermeta($wp_users_id, 'company_name', $_POST['company_name']);
                        update_usermeta($wp_users_id, 'streetaddress', $_POST['address']);
                        update_usermeta($wp_users_id, 'phonenumber', $_POST['phonenumber']);
                        update_usermeta($wp_users_id, 'country', $_POST['country']);
                        if (get_option('web_invoice_pfp_shipping_details') == 'True') {
                            update_usermeta($wp_users_id, 'shipto_last_name', $_POST['shipto_last_name']);
                            update_usermeta($wp_users_id, 'shipto_first_name', $_POST['shipto_first_name']);
                            update_usermeta($wp_users_id, 'shipto_streetaddress', $_POST['shipto_address']);
                            update_usermeta($wp_users_id, 'shipto_city', $_POST['shipto_city']);
                            update_usermeta($wp_users_id, 'shipto_state', $_POST['shipto_state']);
                            update_usermeta($wp_users_id, 'shipto_zip', $_POST['shipto_zip']);
                            update_usermeta($wp_users_id, 'shipto_phonenumber', $_POST['shipto_phonenumber']);
                            update_usermeta($wp_users_id, 'shipto_country', $_POST['shipto_country']);
                        }
                        //Mark invoice as paid
                        web_invoice_paid($invoice_id);
                        web_invoice_update_log($invoice_id, 'pfp_success', "Successful payment. REF: {$payment->getTransactionID()}");
                        web_invoice_update_invoice_meta($invoice_id, 'transaction_id', $payment->getTransactionID());
                        web_invoice_mark_as_paid($invoice_id);
                        // if(get_option('web_invoice_send_thank_you_email') == 'yes') web_invoice_send_email_receipt($invoice_id);
                    } else {
                        $errors['processing_problem'][] .= $payment->getResponseText();
                        $stop_transaction = true;
                        web_invoice_update_log($invoice_id, 'pfp_failure', "Failed PFP payment. REF: " . $payment->getTransactionID() . " " . serialize($payment));
                    }
                }
            } else {
                require_once 'gateways/authnet.class.php';
                require_once 'gateways/authnetARB.class.php';
                $payment = new Web_Invoice_Authnet(true);
                $payment->transaction($_POST['card_num']);
                // Billing Info
                $payment->setParameter("x_card_code", $_POST['card_code']);
                $payment->setParameter("x_exp_date ", $_POST['exp_month'] . $_POST['exp_year']);
                $payment->setParameter("x_amount", $invoice->display('amount'));
                if ($recurring) {
                    $payment->setParameter("x_web_invoice_recurring_billing", true);
                }
                // Order Info
                $payment->setParameter("x_description", $invoice->display('subject'));
                $payment->setParameter("x_invoice_num", $invoice->display('display_id'));
                $payment->setParameter("x_test_request", false);
                $payment->setParameter("x_duplicate_window", 30);
                //Customer Info
                $payment->setParameter("x_first_name", $_POST['first_name']);
                $payment->setParameter("x_last_name", $_POST['last_name']);
                $payment->setParameter("x_address", $_POST['address']);
                $payment->setParameter("x_city", $_POST['city']);
                $payment->setParameter("x_state", $_POST['state']);
                $payment->setParameter("x_country", $_POST['country']);
                $payment->setParameter("x_zip", $_POST['zip']);
                $payment->setParameter("x_phone", $_POST['phonenumber']);
                $payment->setParameter("x_email", $_POST['email_address']);
                $payment->setParameter("x_cust_id", "WP User - " . $invoice->recipient('user_id'));
                $payment->setParameter("x_customer_ip ", $_SERVER['REMOTE_ADDR']);
                $payment->process();
                if ($payment->isApproved()) {
                    echo "Transaction okay.";
                    update_usermeta($wp_users_id, 'last_name', $_POST['last_name']);
                    update_usermeta($wp_users_id, 'first_name', $_POST['first_name']);
                    update_usermeta($wp_users_id, 'city', $_POST['city']);
                    update_usermeta($wp_users_id, 'state', $_POST['state']);
                    update_usermeta($wp_users_id, 'zip', $_POST['zip']);
                    update_usermeta($wp_users_id, 'tax_id', $_POST['tax_id']);
                    update_usermeta($wp_users_id, 'company_name', $_POST['company_name']);
                    update_usermeta($wp_users_id, 'streetaddress', $_POST['address']);
                    update_usermeta($wp_users_id, 'phonenumber', $_POST['phonenumber']);
                    update_usermeta($wp_users_id, 'country', $_POST['country']);
                    //Mark invoice as paid
                    web_invoice_paid($invoice_id);
                    web_invoice_mark_as_paid($invoice_id);
                    // if(get_option('web_invoice_send_thank_you_email') == 'yes') web_invoice_send_email_receipt($invoice_id);
                    if ($recurring) {
                        $arb = new Web_Invoice_AuthnetARB();
                        // Customer Info
                        $arb->setParameter('customerId', "WP User - " . $invoice->recipient('user_id'));
                        $arb->setParameter('firstName', $_POST['first_name']);
                        $arb->setParameter('lastName', $_POST['last_name']);
                        $arb->setParameter('address', $_POST['address']);
                        $arb->setParameter('city', $_POST['city']);
                        $arb->setParameter('state', $_POST['state']);
                        $arb->setParameter('zip', $_POST['zip']);
                        $arb->setParameter('country', $_POST['country']);
                        $arb->setParameter('customerEmail', $_POST['email_address']);
                        $arb->setParameter('customerPhoneNumber', $_POST['phonenumber']);
                        // Billing Info
                        $arb->setParameter('amount', $invoice->display('amount'));
                        $arb->setParameter('cardNumber', $_POST['card_num']);
                        $arb->setParameter('expirationDate', $_POST['exp_month'] . $_POST['exp_year']);
                        //Subscription Info
                        $arb->setParameter('refID', $invoice->display('display_id'));
                        $arb->setParameter('subscrName', $invoice->display('subscription_name'));
                        $arb->setParameter('interval_length', $invoice->display('interval_length'));
                        $arb->setParameter('interval_unit', $invoice->display('interval_unit'));
                        $arb->setParameter('startDate', $invoice->display('startDate'));
                        $arb->setParameter('totalOccurrences', $invoice->display('totalOccurrences'));
                        // First billing cycle is taken care off with initial payment
                        $arb->setParameter('trialOccurrences', '1');
                        $arb->setParameter('trialAmount', '0.00');
                        $arb->setParameter('orderInvoiceNumber', $invoice->display('display_id'));
                        $arb->setParameter('orderDescription', $invoice->display('subject'));
                        $arb->createAccount();
                        if ($arb->isSuccessful()) {
                            web_invoice_update_recurring_start_date($invoice_id, strtotime(date('Y-m-d')));
                            web_invoice_update_invoice_meta($invoice_id, 'subscription_id', $arb->getSubscriberID());
                            web_invoice_update_log($invoice_id, 'subscription', ' Subscription initiated, Subcription ID - ' . $arb->getSubscriberID());
                        }
                        if ($arb->isError()) {
                            $errors['processing_problem'][] .= "One-time credit card payment is processed successfully.  However, recurring billing setup failed." . $arb->getResponse();
                            $stop_transaction = true;
                            web_invoice_update_log($invoice_id, 'subscription_error', 'Response Code: ' . $arb->getResponseCode() . ' | Subscription error - ' . $arb->getResponse());
                        }
                    }
                } else {
                    $errors['processing_problem'][] .= $payment->getResponseText();
                    $stop_transaction = true;
                }
            }
        }
        // Uncomment these to troubleshoot.  You will need FireBug to view the response of the AJAX post.
        //echo $arb->xml;
        //echo $arb->response;
        //echo $arb->getResponse();
        // echo $payment->getResponseText();
        // echo $payment->getTransactionID();
        // echo $payment->getAVSResponse();
        // echo $payment->getAuthCode();
    }
    if ($stop_transaction && is_array($_POST)) {
        foreach ($_POST as $key => $value) {
            if (array_key_exists($key, $errors)) {
                foreach ($errors[$key] as $k => $v) {
                    $errors_msg .= "error|{$key}|{$v}\n";
                }
            } else {
                $errors_msg .= "ok|{$key}\n";
            }
        }
    }
    echo $errors_msg;
}
示例#6
0
 function processRequest($ip, $request)
 {
     $this->ip = $ip;
     $this->ap_custemailaddress = $request['ap_custemailaddress'];
     $this->ap_custfirstname = $request['ap_custfirstname'];
     $this->ap_custlastname = $request['ap_custlastname'];
     $this->ap_custaddress = $request['ap_custaddress'];
     $this->ap_custcity = $request['ap_custcity'];
     $this->ap_custstate = $request['ap_custstate'];
     $this->ap_custcountry = $request['ap_custcountry'];
     $this->ap_custzip = $request['ap_custzip'];
     $this->ap_merchant = $request['ap_merchant'];
     $this->ap_referencenumber = $request['ap_referencenumber'];
     $this->ap_totalamount = $request['ap_totalamount'];
     $this->ap_currency = $request['ap_currency'];
     $this->ap_amount = $request['ap_amount'];
     $this->ap_itemname = $request['ap_itemname'];
     $this->ap_securitycode = $request['ap_securitycode'];
     $this->ap_status = $request['ap_status'];
     $this->ap_test = $request['ap_test'];
     if (!$this->_allowedIp()) {
         $this->_logFailure('Invalid IP');
         header('HTTP/1.0 403 Forbidden');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were unable to authenticate the request';
         exit(0);
     }
     if (!$this->invoice->id) {
         $this->_logFailure('Invoice not found');
         header('HTTP/1.0 404 Not Found');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Invoice not found';
         exit(0);
     }
     if ($this->ap_currency != web_invoice_meta($this->invoice->id, 'web_invoice_currency_code')) {
         $this->_logFailure('Invalid currency');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: AP0';
         exit(0);
     }
     if ($this->ap_totalamount != $this->invoice->display('amount')) {
         $this->_logFailure('Invalid amount');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: AP1';
         exit(0);
     }
     if ($this->ap_merchant != get_option('web_invoice_alertpay_address')) {
         $this->_logFailure('Invalid pay_to_email');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: AP2';
         exit(0);
     }
     if ($this->ap_securitycode != get_option('web_invoice_alertpay_secret')) {
         $this->_logFailure('Invalid security code');
         header('HTTP/1.0 403 Forbidden');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were unable to authenticate the request';
         exit(0);
     }
     if (strtolower($this->ap_status) != "success") {
         $this->_logSuccess('Payment failed (status)');
         header('HTTP/1.0 200 OK');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Thank you very much for letting us know. REF: Not success';
         exit(0);
     }
     if ($this->ap_test == 1) {
         if (get_option('web_invoice_alertpay_test_mode') == 'TRUE') {
             $this->_logFailure('Test payment');
             $this->updateContactInfo();
         }
     } else {
         $this->updateContactInfo();
         web_invoice_mark_as_paid($this->invoice->id);
     }
     header('HTTP/1.0 200 OK');
     header('Content-type: text/plain; charset=UTF-8');
     print 'Thank you very much for letting us know';
     exit(0);
 }
示例#7
0
 function processRequest($ip, $request)
 {
     $this->ip = $ip;
     $this->tco_order_number = $request['order_number'];
     $this->tco_cart_order_id = $request['cart_order_id'];
     $this->tco_credit_card_processed = $request['credit_card_processed'];
     $this->tco_key = $request['key'];
     $this->tco_demo = $request['demo'];
     $this->tco_total = $request['total'];
     if (!$this->invoice->id) {
         $this->_logFailure('Invoice not found');
         header('HTTP/1.0 404 Not Found');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Invoice not found';
         exit(0);
     }
     $calc_key = md5(get_option('web_invoice_2co_secret_word') . get_option('web_invoice_2co_sid') . $this->tco_order_number . $this->tco_total);
     if (strtolower($this->tco_key) != strtolower($calc_key)) {
         $this->_logFailure('Invalid security code');
         header('HTTP/1.0 403 Forbidden');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were unable to authenticate the request';
         exit(0);
     }
     if (strtolower($this->tco_credit_card_processed) != "y") {
         $this->_logSuccess('2CO order # ' . $this->tco_order_number);
         header('HTTP/1.0 200 OK');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Thank you very much for letting us know. REF: Not success';
         exit(0);
     }
     if (strtolower($this->tco_demo) == "y") {
         if (get_option('web_invoice_2co_demo_mode') == 'TRUE') {
             $this->_logFailure('Test payment');
         }
     } else {
         if (intval($this->tco_total) >= $this->invoice->display('due_amount')) {
             web_invoice_mark_as_paid($this->invoice->id);
         }
         $payment_id = web_invoice_payment_register($this->invoice->id, $this->tco_total, $this->trx_id, 1);
         web_invoice_update_payment_meta($payment_id, 'time_stamp', time());
     }
     header('HTTP/1.0 200 OK');
     header('Content-type: text/plain; charset=UTF-8');
     print 'Thank you very much for letting us know';
     exit(0);
 }
示例#8
0
 function Web_Invoice_Decider($web_invoice_action = null)
 {
     global $wpdb, $web_invoice_memory_head_room;
     if (26214400 > $web_invoice_memory_head_room) {
         $this->message = sprintf(__("Less than 25MB of memory available for Web Invoice, please set <code>memory_limit = %s</code> in your" . "<code>php.ini</code> if Web Invoice crashes unexpectedly", WEB_INVOICE_TRANS_DOMAIN), web_invoice_return_bytes_nice(web_invoice_return_bytes(ini_get('memory_limit')) + 27000000));
     }
     $web_invoice_action = !empty($_REQUEST['web_invoice_action']) ? $_REQUEST['web_invoice_action'] : $web_invoice_action;
     $invoice_id = $_REQUEST['invoice_id'];
     if (!$invoice_id) {
         $invoice_id = $_REQUEST['multiple_invoices'][0];
     }
     $web_invoice_recurring_billing = web_invoice_meta($invoice_id, 'web_invoice_recurring_billing');
     //echo "do this: " . $web_invoice_action;
     echo "<div class='wrap'>";
     switch ($web_invoice_action) {
         case "save_and_preview":
             if (empty($invoice_id)) {
                 web_invoice_show_message("Error - invoice id was not passed.");
             } else {
                 web_invoice_show_message(web_invoice_process_invoice_update($invoice_id), 'updated fade');
                 if (web_invoice_meta($invoice_id, 'subscription_id') && web_invoice_meta($invoice_id, 'recurring_transaction_id')) {
                     require_once 'gateways/payflowpro.class.php';
                     $pfp = new Web_Invoice_PayflowProRecurring();
                     if (web_invoice_meta($invoice_id, 'web_invoice_recurring_billing')) {
                         $pfp->updateProfile($invoice_id);
                         web_invoice_update_log($invoice_id, 'pfp_subscription_update', "Subscription updated. REF: " . $pfp->getRef());
                     } else {
                         if ($pfp->deleteProfile(web_invoice_meta($invoice_id, 'subscription_id'))) {
                             web_invoice_update_log($invoice_id, 'pfp_subscription_update', "Subscription cancelled. REF: " . $pfp->getRef());
                             web_invoice_update_invoice_meta($invoice_id, 'pfp_status', 'cancelled');
                             web_invoice_delete_invoice_meta($invoice_id, 'subscription_id');
                         }
                     }
                 }
                 web_invoice_saved_preview($invoice_id);
                 do_action('web_invoice_invoice_save', $invoice_id);
             }
             break;
         case "clear_log":
             web_invoice_show_message(web_invoice_clear_invoice_status($invoice_id), 'updated fade');
             web_invoice_options_manageInvoice($invoice_id);
             break;
         case "doPausePfp":
             if (web_invoice_meta($invoice_id, 'subscription_id') && web_invoice_meta($invoice_id, 'recurring_transaction_id')) {
                 require_once 'gateways/payflowpro.class.php';
                 $pfp = new Web_Invoice_PayflowProRecurring();
                 if (web_invoice_meta($invoice_id, 'web_invoice_recurring_billing')) {
                     $profile_id = web_invoice_meta($invoice_id, 'subscription_id');
                     if ($pfp->pauseProfile($profile_id)) {
                         web_invoice_update_log($invoice_id, 'pfp_subscription_update', "Subscription paused. REF: " . $pfp->getRef());
                         web_invoice_update_invoice_meta($invoice_id, 'pfp_status', 'paused');
                         web_invoice_delete_invoice_meta($invoice_id, 'subscription_id');
                         do_action('web_invoice_invoice_pause_recurring', $invoice_id);
                         $message = 'Paused subscription.';
                     } else {
                         $message = 'Failed to pause subscription.';
                     }
                     $message .= " <a href='admin.php?page=new_web_invoice&web_invoice_action=doInvoice&invoice_id=" . $invoice_id . "'>Continue editing</a>";
                     web_invoice_show_message($message, 'updated fade');
                 }
             }
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "doRestartRecurringPfp":
             if (web_invoice_meta($invoice_id, 'recurring_transaction_id')) {
                 require_once 'gateways/payflowpro.class.php';
                 $pfp = new Web_Invoice_PayflowProRecurring();
                 if (web_invoice_meta($invoice_id, 'web_invoice_recurring_billing')) {
                     $profile_id = web_invoice_meta($invoice_id, 'recurring_transaction_id');
                     if ($pfp->reactivateProfile($profile_id, $invoice_id)) {
                         web_invoice_update_log($invoice_id, 'pfp_subscription_update', "Subscription reactivated. REF: " . $pfp->getRef());
                         web_invoice_update_invoice_meta($invoice_id, 'pfp_status', 'active');
                         web_invoice_update_invoice_meta($invoice_id, 'subscription_id', $profile_id);
                         do_action('web_invoice_invoice_restart_recurring', $invoice_id);
                         $message = 'Reactivated subscription.';
                     } else {
                         $message = 'Failed to reactivate subscription.';
                     }
                     $message .= " <a href='admin.php?page=new_web_invoice&web_invoice_action=doInvoice&invoice_id=" . $invoice_id . "'>Continue editing</a>";
                     web_invoice_show_message($message, 'updated fade');
                 }
             }
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "complete_removal":
             web_invoice_complete_removal();
             web_invoice_show_settings();
             break;
         case "doInvoice":
             if (isset($invoice_id)) {
                 web_invoice_options_manageInvoice($invoice_id);
             } else {
                 web_invoice_options_manageInvoice();
             }
             break;
         case "overview":
             web_invoice_default();
             break;
         case "user_overview":
             web_invoice_user_default();
             break;
         case "web_invoice_show_welcome_message":
             web_invoice_show_welcome_message();
             break;
         case "web_invoice_recurring_billing":
             web_invoice_recurring_overview();
             break;
         case "send_now":
             web_invoice_show_message(web_invoice_send_email($invoice_id));
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "first_setup":
             if (isset($_POST['web_invoice_web_invoice_page'])) {
                 update_option('web_invoice_web_invoice_page', $_POST['web_invoice_web_invoice_page']);
             }
             if (isset($_POST['web_invoice_payment_method'])) {
                 update_option('web_invoice_payment_method', join($_POST['web_invoice_payment_method'], ','));
             }
             if (isset($_POST['web_invoice_gateway_username'])) {
                 update_option('web_invoice_gateway_username', $_POST['web_invoice_gateway_username']);
             }
             if (isset($_POST['web_invoice_gateway_tran_key'])) {
                 update_option('web_invoice_gateway_tran_key', $_POST['web_invoice_gateway_tran_key']);
             }
             if (isset($_POST['web_invoice_gateway_merchant_email'])) {
                 update_option('web_invoice_gateway_merchant_email', $_POST['web_invoice_gateway_merchant_email']);
             }
             // PayPal
             if (isset($_POST['web_invoice_paypal_address'])) {
                 update_option('web_invoice_paypal_address', $_POST['web_invoice_paypal_address']);
             }
             if (isset($_POST['web_invoice_paypal_only_button'])) {
                 update_option('web_invoice_paypal_only_button', $_POST['web_invoice_paypal_only_button']);
             }
             if (isset($_POST['web_invoice_paypal_sandbox'])) {
                 update_option('web_invoice_paypal_sandbox', $_POST['web_invoice_paypal_sandbox']);
             }
             // Payflow
             if (isset($_POST['web_invoice_payflow_login'])) {
                 update_option('web_invoice_payflow_login', $_POST['web_invoice_payflow_login']);
             }
             if (isset($_POST['web_invoice_payflow_partner'])) {
                 update_option('web_invoice_payflow_partner', $_POST['web_invoice_payflow_partner']);
             }
             if (isset($_POST['web_invoice_payflow_only_button'])) {
                 update_option('web_invoice_payflow_only_button', $_POST['web_invoice_payflow_only_button']);
             }
             if (isset($_POST['web_invoice_payflow_silent_post'])) {
                 update_option('web_invoice_payflow_silent_post', $_POST['web_invoice_payflow_silent_post']);
             }
             // Other/Bank
             if (isset($_POST['web_invoice_other_details'])) {
                 update_option('web_invoice_other_details', $_POST['web_invoice_other_details']);
             }
             // Moneybookers
             if (isset($_POST['web_invoice_moneybookers_address'])) {
                 update_option('web_invoice_moneybookers_address', $_POST['web_invoice_moneybookers_address']);
             }
             if (isset($_POST['web_invoice_moneybookers_recurring_address'])) {
                 update_option('web_invoice_moneybookers_recurring_address', $_POST['web_invoice_moneybookers_recurring_address']);
             }
             if (isset($_POST['web_invoice_moneybookers_merchant'])) {
                 update_option('web_invoice_moneybookers_merchant', $_POST['web_invoice_moneybookers_merchant']);
             }
             if (isset($_POST['web_invoice_moneybookers_secret'])) {
                 update_option('web_invoice_moneybookers_secret', $_POST['web_invoice_moneybookers_secret']);
             }
             if (isset($_POST['web_invoice_moneybookers_ip'])) {
                 update_option('web_invoice_moneybookers_ip', $_POST['web_invoice_moneybookers_ip']);
             }
             // AlertPay
             if (isset($_POST['web_invoice_alertpay_address'])) {
                 update_option('web_invoice_alertpay_address', $_POST['web_invoice_alertpay_address']);
             }
             if (isset($_POST['web_invoice_alertpay_merchant'])) {
                 update_option('web_invoice_alertpay_merchant', $_POST['web_invoice_alertpay_merchant']);
             }
             if (isset($_POST['web_invoice_alertpay_secret'])) {
                 update_option('web_invoice_alertpay_secret', $_POST['web_invoice_alertpay_secret']);
             }
             web_invoice_options_manageInvoice();
             break;
         case "web_invoice_settings":
             web_invoice_process_settings();
             web_invoice_show_settings();
             break;
         case "web_invoice_email_templates":
             web_invoice_process_email_templates();
             web_invoice_show_email_templates();
             break;
         case "delete_invoice":
             web_invoice_show_message(web_invoice_delete($_REQUEST['multiple_invoices']));
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "send_invoice":
             if (empty($_REQUEST['multiple_invoices'])) {
                 web_invoice_show_message("No invoices selected, nothing sent.");
             } else {
                 web_invoice_show_message(web_invoice_send_email($_REQUEST['multiple_invoices']), 'updated fade');
             }
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "send_reminder":
             if (empty($_REQUEST['multiple_invoices'])) {
                 web_invoice_show_message("No invoices selected, no reminder sent.");
             } else {
                 web_invoice_show_message(web_invoice_send_email($_REQUEST['multiple_invoices'], 'reminder'), 'updated fade');
             }
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "archive_invoice":
             if (empty($_REQUEST['multiple_invoices'])) {
                 web_invoice_show_message("No invoices selected, nothing archived.");
             } else {
                 web_invoice_show_message(web_invoice_archive($_REQUEST['multiple_invoices']), 'updated fade');
             }
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "unarchive_invoice":
             if (empty($_REQUEST['multiple_invoices'])) {
                 web_invoice_show_message("No invoices selected, nothing un-archived.");
             } else {
                 web_invoice_show_message(web_invoice_unarchive($_REQUEST['multiple_invoices']), 'updated fade');
             }
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "mark_as_paid":
             if (empty($_REQUEST['multiple_invoices'])) {
                 web_invoice_show_message("No invoices selected, nothing marked as paid.");
             } else {
                 web_invoice_show_message(web_invoice_mark_as_paid($_REQUEST['multiple_invoices']), 'updated fade');
             }
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "mark_as_sent":
             if (empty($_REQUEST['multiple_invoices'])) {
                 web_invoice_show_message("No invoices selected, nothing marked as sent..");
             } else {
                 web_invoice_show_message(web_invoice_mark_as_sent($_REQUEST['multiple_invoices']), 'updated fade');
             }
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         case "save_not_send":
             // Already saved, this just shows a message
             $web_invoice_custom_invoice_id = web_invoice_meta($invoice_id, 'web_invoice_custom_invoice_id');
             if ($web_invoice_custom_invoice_id) {
                 $message = "Invoice <b>{$web_invoice_custom_invoice_id}</b> saved.";
             } else {
                 $message = "Invoice <b>#" . $invoice_id . "</b> saved.";
             }
             $message .= " <a href=" . web_invoice_build_invoice_link($invoice_id) . ">View Web Invoice</a>";
             web_invoice_show_message($message, ' updated fade');
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
         default:
             if ($web_invoice_recurring_billing) {
                 web_invoice_recurring_overview();
             } else {
                 web_invoice_default();
             }
             break;
     }
     echo "</div>";
 }
 function processRequest($ip, $request)
 {
     $this->ip = $ip;
     $this->pay_to_email = $request['pay_to_email'];
     $this->pay_from_email = $request['pay_from_email'];
     $this->merchant_id = $request['merchant_id'];
     $this->mb_transaction_id = $request['mb_transaction_id'];
     $this->transaction_id = $request['transaction_id'];
     $this->mb_amount = $request['mb_amount'];
     $this->mb_currency = $request['mb_currency'];
     $this->status = $request['status'];
     $this->md5sig = $request['md5sig'];
     $this->amount = $request['amount'];
     $this->currency = $request['currency'];
     if (isset($request['rec_payment_id'])) {
         $this->recurring_payment_id = $request['rec_payment_id'];
     }
     if (isset($request['rec_payment_type'])) {
         $this->recurring_payment_type = $request['rec_payment_type'];
     }
     if (!$this->_allowedIp()) {
         $this->_logFailure('Invalid IP');
         header('HTTP/1.0 403 Forbidden');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were unable to authenticate the request';
         exit(0);
     }
     if (!$this->invoice->id) {
         $this->_logFailure('Invoice not found');
         header('HTTP/1.0 404 Not Found');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Invoice not found';
         exit(0);
     }
     if ($this->currency != web_invoice_meta($this->invoice->id, 'web_invoice_currency_code')) {
         $this->_logFailure('Invalid currency');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: MB0';
         exit(0);
     }
     if ($this->amount != $this->invoice->display('amount')) {
         $this->_logFailure('Invalid amount');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: MB1';
         exit(0);
     }
     if ($this->pay_to_email != get_option('web_invoice_moneybookers_address') && $this->pay_to_email != get_option('web_invoice_moneybookers_recurring_address')) {
         $this->_logFailure('Invalid pay_to_email');
         header('HTTP/1.0 400 Bad Request');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were not expecting you. REF: MB2';
         exit(0);
     }
     $secret_word = strtoupper(md5(get_option('web_invoice_moneybookers_secret')));
     $our_signature = strtoupper(md5("{$this->merchant_id}{$this->transaction_id}{$secret_word}{$this->mb_amount}{$this->mb_currency}{$this->status}"));
     if ($this->md5sig != $our_signature) {
         $this->_logFailure('Invalid signature, we calculated ' . $our_signature);
         header('HTTP/1.0 403 Forbidden');
         header('Content-type: text/plain; charset=UTF-8');
         print 'We were unable to authenticate the request';
         exit(0);
     }
     if ($this->status != 2) {
         if ($this->status == -2) {
             $this->_logSuccess('Payment failed (status)');
         }
         if ($this->status == -1) {
             $this->_logSuccess('Payment cancelled (status)');
         }
         if ($this->status == 0) {
             $this->_logSuccess('Payment pending (status)');
         }
         header('HTTP/1.0 200 OK');
         header('Content-type: text/plain; charset=UTF-8');
         print 'Thank you very much for letting us know. REF: Pending';
         exit(0);
     }
     $this->_logSuccess('Paid');
     web_invoice_mark_as_paid($this->invoice->id);
     header('HTTP/1.0 200 OK');
     header('Content-type: text/plain; charset=UTF-8');
     print 'Thank you very much for letting us know';
     exit(0);
 }