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 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; }
function web_invoice_show_paypal_form($invoice_id, $invoice) { if (get_option('web_invoice_paypal_sandbox') == 'True') { $_url = "https://www.sandbox.paypal.com/us/cgi-bin/webscr"; } else { $_url = "https://www.paypal.com/us/cgi-bin/webscr"; } ?> <div id="paypal_payment_form" class="payment_form"><?php if (get_option('web_invoice_paypal_only_button') == 'False') { ?> <h2 class="invoice_page_subheading"><?php _e('Billing Information', WEB_INVOICE_TRANS_DOMAIN); ?> </h2> <?php } ?> <form action="<?php print $_url; ?> " method="post" class="clearfix"><input type="hidden" name="currency_code" value="<?php echo $invoice->display('currency'); ?> " /> <input type="hidden" name="no_shipping" value="1" /> <input type="hidden" name="upload" value="1" /> <input type="hidden" name="business" value="<?php echo get_option('web_invoice_paypal_address'); ?> " /> <input type="hidden" name="return" value="<?php echo web_invoice_build_invoice_link($invoice_id); ?> " /> <input type="hidden" name="rm" value="2" /> <input type="hidden" name="invoice" id="invoice_num" value="<?php echo $invoice->display('display_id'); ?> " /> <?php if (web_invoice_recurring($invoice_id)) { ?> <input type="hidden" name="cmd" value="_xclick-subscriptions" /> <input type="hidden" name="t3" value="<?php echo web_invoice_paypal_convert_interval($invoice->display('interval_unit'), $invoice->display('interval_length')); ?> " /> <input type="hidden" name="src" value="1" /> <input type="hidden" name="srt" value="<?php echo $invoice->display('totalOccurrences'); ?> " /> <input type="hidden" name="p3" value="<?php echo $invoice->display('interval_length'); ?> " /> <input type="hidden" name="a3" value="<?php echo $invoice->display('amount'); ?> " /> <input type="hidden" name="item_name" value="<?php echo $invoice->display('subscription_name'); ?> "> <input type="hidden" name="item_number" value="<?php echo $invoice->display('display_id') . date('YMD'); ?> "> <?php } else { // Convert Itemized List into PayPal Item List if (is_array($invoice->display('itemized'))) { echo web_invoice_create_paypal_itemized_list($invoice->display('itemized'), $invoice_id); } } ?> <input type="hidden" name="amount" value="<?php echo $invoice->display('amount'); ?> " /> <input type="hidden" name="notify_url" value="<?php echo web_invoice_build_invoice_link_paypal($invoice_id); ?> " /> <input type="hidden" name="invoice" value="<?php echo $invoice_id; ?> " /> <fieldset id="credit_card_information"> <ol> <?php if (get_option('web_invoice_paypal_only_button') == 'False') { ?> <li><label for="first_name"><?php _e('First Name', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php echo web_invoice_draw_inputfield("first_name", $invoice->recipient('first_name')); ?> </li> <li><label for="last_name"><?php _e('Last Name', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php echo web_invoice_draw_inputfield("last_name", $invoice->recipient('last_name')); ?> </li> <li><label for="email"><?php _e('Email Address', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php echo web_invoice_draw_inputfield("email_address", $invoice->recipient('email_address')); ?> </li> <?php list($day_phone_a, $day_phone_b, $day_phone_c) = preg_split('/[\\/\\.\\-]/', $invoice->recipient('paypal_phonenumber')); ?> <li><label for="day_phone_a"><?php _e('Phone Number', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php echo web_invoice_draw_inputfield("night_phone_a", $day_phone_a, ' style="width:25px;" size="3" maxlength="3" '); ?> - <?php echo web_invoice_draw_inputfield("night_phone_b", $day_phone_b, ' style="width:25px;" size="3" maxlength="3" '); ?> - <?php echo web_invoice_draw_inputfield("night_phone_c", $day_phone_c, ' style="width:35px;" size="4" maxlength="4" '); ?> </li> <li><label for="address"><?php _e('Address', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php echo web_invoice_draw_inputfield("address", $invoice->recipient('streetaddress')); ?> </li> <li><label for="city"><?php _e('City', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php echo web_invoice_draw_inputfield("city", $invoice->recipient('city')); ?> </li> <li><label for="state"><?php _e('State (e.g. CA)', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php print web_invoice_draw_inputfield('state', $invoice->recipient('state')); ?> </li> <li><label for="zip"><?php _e('Zip Code', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php echo web_invoice_draw_inputfield("zip", $invoice->recipient('zip')); ?> </li> <li><label for="country"><?php _e('Country', WEB_INVOICE_TRANS_DOMAIN); ?> </label> <?php echo web_invoice_draw_select('country', web_invoice_country_array(), $invoice->recipient('country')); ?> </li> <?php } ?> <?php if (web_invoice_recurring($invoice_id)) { ?> <li><label for="submit"> </label> <input type="image" src="<?php print get_option('web_invoice_paypal_subscribe_button', '') == '' ? "https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" : get_option('web_invoice_paypal_subscribe_button', ''); ?> " name="submit" class="pay_button paypal_subscription" alt="Subscribe with PayPal - it's fast, free and secure!" /></li> <?php } else { ?> <li><label for="submit"> </label> <input type="image" src="<?php print get_option('web_invoice_paypal_button', '') == '' ? "https://www.paypal.com/en_US/i/btn/btn_paynow_LG.gif" : get_option('web_invoice_paypal_button', ''); ?> " name="submit" class="pay_button paypal" alt="Make payments with PayPal - it's fast, free and secure!" /></li> <?php } ?> </ol> <br class="cb" /> </fieldset> </form> </div> <?php }
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>"; }