Example #1
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;
}
Example #2
0
function web_invoice_generate_pdf_content($invoice_id)
{
    global $post, $web_invoice_print;
    $web_invoice_print = true;
    $invoice = new Web_Invoice_GetInfo($invoice_id);
    $lines = preg_split("/\n/", get_option('web_invoice_business_address'));
    $lines_recepient = preg_split("/\n/", $invoice->recipient('streetaddress'));
    $lc = max(count($lines_recepient), count($lines));
    ob_start();
    ?>
	<style type="text/css">
		.noprint { display: none; }
		#invoice_page { width: 500px; margin: 0 auto; font-size: 11px; font-family: 'Trebuchet MS','Lucida Grande',Verdana,Tahoma,Arial; }
		th { text-align: left; font-size: 13px; padding: 5px; }
		td { font-size: 12px; vertical-align: top; padding: 5px; }
		tr td { background-color: #fefefe; }
		tr.alt_row  td { background-color: #eee; }
		span.description_text { color: #333; font-size: 0.8em; }
		tr.web_invoice_bottom_line { font-size: 1.1em; font-weight: bold; }
		table { width: 100%; }
		h2 { font-size: 1.1em; }
		h1 { text-align: center; }
		p { margin: 5px 0px; }
		div.clear { clear: both; }
		
		#invoice_client_info { width: 100%; text-align: right; padding-top: -<?php 
    print ($lc + 3) * 20 + 7;
    ?>
px; }
		#invoice_business_info { width: 100%; text-align: left; height: <?php 
    print ($lc + 3) * 15 + 7;
    ?>
px; }
	</style>
	<?php 
    do_action('web_invoice_front_top', $invoice_id);
    print '<div class="clear"></div>';
    //If this is not recurring invoice, show regular message
    if (!($recurring = web_invoice_recurring($invoice_id))) {
        web_invoice_show_invoice_overview($invoice_id);
    }
    // Show this if recurring
    if ($recurring) {
        web_invoice_show_recurring_info($invoice_id);
    }
    if (web_invoice_paid_status($invoice_id)) {
        web_invoice_show_already_paid($invoice_id);
        do_action('web_invoice_front_paid', $invoice_id);
    } else {
        //Show Billing Information
        web_invoice_show_billing_information($invoice_id);
        do_action('web_invoice_front_unpaid', $invoice_id);
    }
    do_action('web_invoice_front_bottom', $invoice_id);
    ?>
	<script type="text/php">
		if ( isset($pdf) ) {
    		$font = Font_Metrics::get_font("verdana", "bold");
			$font_light = Font_Metrics::get_font("verdana");
			$pdf->page_text(52, 810, "Powered by Web Invoice ".WEB_INVOICE_VERSION_NUM, $font_light, 10, array(0,0,0));
    		$pdf->page_text(510, 810, "Page {PAGE_NUM} of {PAGE_COUNT}", $font, 10, array(0,0,0));
  		}
	</script>
	<?php 
    $content = ob_get_contents();
    ob_clean();
    return $content;
}