Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help adding a simple coupon code to script

    Hi everyone, I'm a completely noob so forgive my ignorance. Here's my issue:

    I'm working on a very simple order form used to pay for a seminar registration fee - http://www.prudentkids.com/orderform.php

    My question is - is there any way to add a COUPON CODE field? I'm just looking at ONE coupon code (for example: REFERAFRIEND2010) that, when added, will give you 20% off (original price $167).

    Shouldn't be too hard right? Thanks everyone!

    Here's the code:

    PHP Code:
    <?php
        
    include_once("gatewayapi/inc_gatewayapi.php");
    ?>
    <html>
    <head>
    <title>Registration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" type="text/css" href="phpgatewayapi.css">
    <script language="JavaScript">
        var nVisaCardType                 = 0;
        var nMastercardCardType         = 1;
        var nDiscoverCardType            = 2;
        var nAmexCardType                = 3;
        var nDinersClubCardType            = 4;
        var nCarteBlancheCardType        = 5;
        var nEnRouteCardType            = 6;
        var nJCBCardType                = 7;
        var nUnknownCardType            = 8;    
        var cardPics = new Array();

        cardPics[nVisaCardType] = new Image();
        cardPics[nVisaCardType].src="images/cards/visa.jpg";
        cardPics[nMastercardCardType] = new Image();
        cardPics[nMastercardCardType].src="images/cards/mastercard.jpg";
        cardPics[nDiscoverCardType] = new Image();
        cardPics[nDiscoverCardType].src="images/cards/discover.jpg";
        cardPics[nAmexCardType] = new Image();
        cardPics[nAmexCardType].src="images/cards/amex.jpg";
        cardPics[nDinersClubCardType] = new Image();
        cardPics[nDinersClubCardType].src="images/cards/dinersclub.jpg";
        cardPics[nCarteBlancheCardType] = new Image();
        cardPics[nCarteBlancheCardType].src="images/cards/carteblanche.jpg";
        cardPics[nEnRouteCardType] = new Image();
        cardPics[nEnRouteCardType].src="images/cards/enroute.jpg";
        cardPics[nJCBCardType] = new Image();
        cardPics[nJCBCardType].src="images/cards/jcb.jpg";    
        cardPics[nUnknownCardType] = new Image();
        cardPics[nUnknownCardType].src="images/cards/invalid.gif";

        //
        // Algorithm to verify a credit number is valid
        //
        function checkLuhn10(number) {
            if (number.length > 19)
                return (false);

            sum = 0; mul = 1; l = number.length;
            for (i = 0; i < l; i++) {
                digit = number.substring(l-i-1,l-i);
            tproduct = parseInt(digit ,10)*mul;
            if (tproduct >= 10)
              sum += (tproduct % 10) + 1;
            else
              sum += tproduct;
            if (mul == 1)
              mul++;
            else
              mul--;
          }

          if ((sum % 10) == 0)
            return (true);
          else
            return (false);
        }

        //
        // Determine the credit card type from the credit card number
        //
        function getCardType(number) {
            var numLength = number.length;
            
            if(numLength > 4)
            {
                if((number.charAt(0) == '4') && ((numLength == 13)||(numLength==16)))
                    return(cardPics[nVisaCardType].src);
                else if((number.charAt(0) == '5' && ((number.charAt(1) >= '1') && (number.charAt(1) <= '5'))) && (numLength==16))
                    return(cardPics[nMastercardCardType].src);
                else if(number.substring(0,4) == "6011" && (numLength==16))
                    return(cardPics[nDiscoverCardType].src);
                else if((number.charAt(0) == '3' && ((number.charAt(1) == '4') || (number.charAt(1) == '7'))) && (numLength==15))
                    return(cardPics[nAmexCardType].src);
                else if((number.charAt(0) == '3') && (numLength==16))
                    return(cardPics[nJCBCardType].src);
                else if(((number.substring(0, 4) == "2131") || (number.substring(0, 4) == "1800")) && (numLength==15))
                    return(cardPics[nJCBCardType].src);
                else if(((number.substring(0, 4) == "2014") || (number.substring(0, 4) == "2149")) && (numLength==15))
                    return(cardPics[nEnRouteCardType].src);
                else if((number.charAt(0) == '3') && (number.charAt(1) == '8') && (numLength == 14))
                    return(cardPics[nCarteBlancheCardType].src);
                else if((number.charAt(0) == '3') && (((number.charAt(1) == '0') && ((number.charAt(2) >= '0') && (number.charAt(2) <= '5'))) 
                    || (number.charAt(1) == '6')) && (numLength == 14))
                    return(cardPics[nDinersClubCardType].src);
            }

            return(cardPics[nUnknownCardType].src);      
        }


        function handleCCTyping (field, event) {
            var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

          if (field.card_num.value.length >= 13) 
          {
              if(!checkLuhn10(field.card_num.value))
                {
                    field.cardimage.src=cardPics[nUnknownCardType].src;
                }
                else
                {
                    field.cardimage.src=getCardType(field.card_num.value);
                }
            } else {
                field.cardimage.src=cardPics[nUnknownCardType].src;
            }

            return true;
        }


        function copyAddress() 
        {     
            if(document.form1.sInfo.checked == true ) 
            { 
                document.form1.shipping_first_name.value     = document.form1.first_name.value ; 
                document.form1.shipping_last_name.value     = document.form1.last_name.value ; 
                document.form1.shipping_address.value         = document.form1.address.value ; 
                document.form1.shipping_city.value             = document.form1.city.value ; 
                document.form1.shipping_zip.value             = document.form1.zip.value ; 
                document.form1.shipping_state.value         = document.form1.state.value ; 
                <? if(!$GatewaySettings['AllowInternational']) { ?>            
                    document.form1.shipping_state.selectedIndex  = document.form1.shipping_state.selectedIndex;
                <? ?>
                document.form1.shipping_country.value         = document.form1.country.value ; 
                document.form1.shipping_country.selectedIndex = document.form1.country.selectedIndex;
            } 
        }


    </script>
    <script language="JavaScript">
    <!-- Begin
    function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=590,height=245,left = 

    490,top = 312');");
    }
    // End -->
    </script>
    </head>
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <center>
    <br>
    <img src="title.jpg" border="0"></img>
    </center> 
    <form method="post" name="form1" id="form1" action="process_transaction.php"> 
      <p align="center">&nbsp;</p>
      <p align="center"><strong>ORDER FORM<br><a href=""></a></strong></p>
      <p align="center">Please enter your billing information below
        and click submit to process the transaction.<br>
      </p>
      <table border="0" align="center" cellpadding="0" cellspacing="0">
        <tr class="background">
          <td><table width="600" border="0" cellpadding="3" cellspacing="1" class="front">
            <tr>
              <td colspan="2" class="highlight">TOTAL: $167.00</td>
            </tr>
            <tr>
              <td> First Name: </td>
              <td>
                <input name="first_name" type="text" id="first_name" size="40" maxlength="50" value="<? print $_REQUEST['first_name']; ?>">          </td>
            </tr>
            <tr>
              <td>Last Name:</td>
              <td>
                <input name="last_name" type="text" id="last_name" size="40" maxlength="50" value="<? print $_REQUEST['last_name']; ?>">          </td>
            </tr>
            <tr>
              <td>Address: </td>
              <td>
                <input name="address" type="text"  size="40" maxlength="60" value="<? print $_REQUEST['address']; ?>">          </td>
            </tr>
            <tr>
              <td>City: </td>
              <td>
                <input name="city" type="text" size="40" maxlength="40" value="<? print $_REQUEST['city']; ?>">          </td>
            </tr>
            <tr>
              <td>State: </td>
              <td>
                <? if($GatewaySettings['AllowInternational']) { ?>
                <input name="state" type="text" size="40" maxlength="40" value="<? print $_REQUEST['state']; ?>">
                <? } else { ?>
                <select name="state" id="select">
                  <? print printStateDropdown($_REQUEST['state']); ?>
                </select>
                <? ?>          </td>
            </tr>
            <tr>
              <td>Zip: </td>
              <td>
                <input name="zip" type="text" size="10" maxlength="20" value="<? print $_REQUEST['zip']; ?>">          </td>
            </tr>
            <tr>
              <td>Country: </td>
              <td>
                <select name="country" id="select2">
                  <? if($GatewaySettings['AllowInternational']) { ?>
                  <option value="">Select a country</option>
                  <? print_ISOSelectOptions($ISO3166TwoToNametrue$_REQUEST['country']); ?>
                  <? } else { ?>
                  <option value="US">United States</option>
                  <? ?>
                </select>          </td>
            </tr>
            <tr>
              <td>Phone Number: </td>
              <td>
                <input name="phone" type="text"  size="20" maxlength="25" value="<? print $_REQUEST['phone']; ?>">          </td>
            </tr>
            <tr>
              <td>Email Address: </td>
              <td>
                <input name="email" type="text"  size="40" maxlength="248" value="<? print $_REQUEST['email']; ?>">          </td>
            </tr>
            <tr>
              <td>Credit Card Number: </td>
              <td>
                <input name="card_num" type="text"  size="22"  maxlength="22" onchange="handleCCTyping(this.form, event);" onkeyup="handleCCTyping(this.form, 

    event);" ><img name="cardimage" src="images/cards/invalid.gif"  height="24" width="36" hspace="10" vspace="0"></td></tr>
            <tr>
              <td>Expiration Date:</td>
              <td><select name="exp_month" id="select3">
                  <? print printMonthDropdown($_REQUEST['exp_month']); ?>
                </select>
                  <select name="exp_year" id="select4">
                    <? print printYearDropdown($_REQUEST['exp_year']); ?>
                  </select></td>
            </tr>
            <tr>
              <td>Security Code:</td>
              <td>
                <input name="card_code" type="text" size="4" maxlength="4" value="<? print $_REQUEST['card_code']; ?>">      <A HREF="javascript:popUp

    ('cvv.html')">What is this?</A></td>
            </tr>

      
            <tr>
              <td>&nbsp;</td>
              <td><input type="submit" name="submit">
    &nbsp;
          <input type="reset" name="reset"></td>
            </tr>
          </table></td>
        </tr>
      </table>

      <input type="hidden" name="amount" value="167.00">
    </form>
    <br>


    <center>

    <a target="_blank" href="http://unitedbankservice.com/verified.php">
    <img src="cardlist.jpg" border="0"></a>
    <br>
    <br>


    <!-- (c) 2005, 2010. Authorize.Net is a registered trademark of CyberSource Corporation --> <div class="AuthorizeNetSeal"> <script type="text/javascript" 

    language="javascript">var ANS_customer_id="b443b458-ec48-44bf-b53a-64ac30d1cd5f";</script> <script type="text/javascript" language="javascript" 

    src="//verify.authorize.net/anetseal/seal.js" ></script> <a href="http://www.authorize.net/" id="AuthorizeNetText" target="_blank">Electronic Commerce</a> 
    </div>

    <br>
    <td width="600"><div style="FONT-SIZE: 15px; COLOR: #666666; FONT-FAMILY: Arial, Helvetica, sans-serif"                        

    align="center"> 
                            <p align="center">Prudent Consulting Group, LLC&nbsp;<font face="Verdana">◦</font> Henderson, Nevada 
                                89012, U.S.A. <font face="Verdana">◦</font> (702) 355-3982<br> 
                                <a href="http://www.prudentkids.com">Home</a>&nbsp;|&nbsp;<a 

    href="http://www.prudentkids.com/privacy.html">Privacy Policy</a>&nbsp;|&nbsp;<a href="http://www.prudentkids.com/termsofuse.html">Terms of 

    Use</a>&nbsp;|&nbsp;<a href="mailto:admin@prudentkids.com">Contact&nbsp;Us</a><br>
                                ©
                                <span id="Global_footer1_lblYear">2010</span> 
                                All rights reserved.</p> 
                        </div> 
    </center>
    </body>
    </html>
    Last edited by INFIDEL; 02-11-2010 at 10:28 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Not too hard, assuming you know the basics of PHP. Generally you will:

    1. Add the coupon code input element to the form
    2. Change process_transaction.php to recognize the value in the coupon code input, validate it, and then adjust the amount to charge, before it gets sent to your payment gateway.

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how about we assume I don't know the basics lol

    here's my inc_gatewaytransaction.php script:

    PHP Code:
    <?php
        
    include_once("inc_gatewayfunctions.php");

        
    // The scary looking words here just make it so we don't have to redefine these strings for
        // every GatewayTransaction instance.
        // **
        // Edit these error strings as you see fit.
        
    $GLOBALS['_transient']['static']['GatewayTransaction']->ErrorStrings = array (
                
    "MISSING_LOGIN"        =>    "The Gateway login information for this store is not configured properly.",
                
    "MISSING_AMOUNT"    =>    "This transaction requires an amount field.",
                
    "MISSING_CCNUMBER"    =>    "This transaction requires a credit card number.",
                
    "MISSING_EXPDATE"    =>    "This transaction requires a credit card expiration date."
                
    "MISSING_ROUTINGNUM"    =>    "This transaction requires a checking account routing number.",
                
    "MISSING_ACCOUNTNUM"    =>    "This transaction requires a checking account number.",
                
    "MISSING_TRANSACTIONID"    =>    "This transaction requires a Transaction Id to reference.",
                
    "MISSING_CURL"        =>    "The socket library for this store is missing or is not configured properly.",
                
    "MISSING_URL"        =>    "The Gateway url for this store is not configured properly.",
                
    "MISSING_DATA"        =>    "There seems to be a problem, no data was received for authorization. You have not been charged anything. Please try again or contact support for help.",
                
    "INVALID_CCNUMBER"    =>    "The credit card number entered is not valid.",
                
    "INVALID_EXPDATE"    =>    "The credit card expiration date entered is not valid.",
                
    "INVALID_ROUTINGNUM"    =>    "The checking account routing number entered is not valid.",
                
    "INVALID_AMEXCVV"    =>    "The security code for American Express cards is found on the front of the card on the right side, and should be 4 digits.",
                
    "INVALID_CVV"        =>    "The security code for your credit card should be found in the signature area on the back of the card, and should be 3 digits.",
                
    "INVALID_MD5HASH"    =>    "The MD5 Authentication string returned by the Payment Gateway does not match what is configured for this store.",
                
    "INVALID_TYPE"        =>     "This payment library does not recognize the type of transaction you are attempting. Please contact support for help.",
                
    "INVALID_METHOD"    =>    "This payment library does not recognize the method of payment you are attempting. Please contact support for help.",
                
    "UNACCEPTED_CARD"    =>    "We're sorry, we cannot accept this type of card. Please use a different one.",
                
    "UNACCEPTED_ECHECKS"    =>    "We're sorry, we cannot currently accept electronic checks as payment. Please select a different payment option.",
                
    "AMOUNT_TOOLOW"        =>    "We're sorry, we cannot accept transactions less than $1.00.",
                
    "AMOUNT_TOOHIGH"    =>    "We're sorry, we cannot accept transactions of $100,000 or more. Please split up your payments, or contact support for help.",
                
    "EXPIRED_EXPDATE"    =>    "We're sorry, this credit card has expired. Please use a different card or change the expiration date if you have received an updated card.",
                );

        
    $GLOBALS['_transient']['static']['GatewayTransaction']->GatewayFieldNames = array (
            
    /* (Gateway Field Name,        Max Length,    Pre-Processing Callback Function,     Field name to send to GatewayTransaction Class) */
            
    array ("x_customer_organization_type",        1,        NULL,                    "organization_type"),
            array (
    "x_drivers_license_num",            50,        NULL,                    "license_num"),
            array (
    "x_drivers_license_state",        2,        NULL,                    "license_state"),
            array (
    "x_drivers_license_dob",            10,        NULL,                    "license_dob"),    
            array (
    "x_login",                20,        NULL,                    "username"),
            array (
    "x_tran_key",                20,        NULL,                    "tran_key"),
            array (
    "x_password",                10,        NULL,                    "password"),
            array (
    "x_type",                18,        NULL,                    "type"),    
            array (
    "x_bank_aba_code",            9,        StripNonNumeric,            "check_aba_code"),
            array (
    "x_bank_acct_num",            20,        StripNonNumeric,            "check_acct_num"),
            array (
    "x_bank_acct_type",            8,        NULL,                    "check_acct_type"),
            array (
    "x_bank_name",                50,        NULL,                    "check_bank_name"),
            array (
    "x_bank_acct_name",            40,        NULL,                    "check_acct_name"),
            array (
    "x_echeck_type",                3,        NULL,                    "check_type"),    
            array (
    "x_trans_id",                10,        StripNonNumeric,            "tran_id"),    
            array (
    "x_version",                3,        NULL,                    "version"),
            array (
    "x_test_request",            5,        NULL,                    "test_mode"),
            array (
    "x_first_name",                50,        NULL,                    "first_name"),
            array (
    "x_last_name",                50,        NULL,                    "last_name"),
            array (
    "x_company",                50,        NULL,                    "company"),
            array (
    "x_address",                60,        NULL,                    "address"),
            array (
    "x_city",                40,        NULL,                    "city"),
            array (
    "x_state",                40,        NULL,                    "state"),
            array (
    "x_zip",                    20,        NULL,                    "zip"),
            array (
    "x_country",                60,        NULL,                    "country"),
            array (
    "x_phone",                25,        NULL,                    "phone"),
            array (
    "x_fax",                    25,        NULL,                    "fax"),
            array (
    "x_cust_id",                20,        NULL,                    "customer_id"),
            array (
    "x_customer_ip",                15,        NULL,                    "customer_ip"),
            array (
    "x_customer_tax_id",            9,        StripNonNumeric,            "customer_ssn"),
            array (
    "x_email",                248,        NULL,                    "email"),
            array (
    "x_email_customer",            5,        TRUEorFALSE,                "email_customer"),
            array (
    "x_merchant_email",            248,        NULL,                    "merchant_email"),
            array (
    "x_header_email_receipt",        1024,        NULL,                    "header_email_receipt"),
            array (
    "x_footer_email_receipt",        1024,        NULL,                    "footer_email_receipt"),
            array (
    "x_invoice_num",                20,        NULL,                    "invoice_num"),
            array (
    "x_description",                248,        NULL,                    "description"),
            array (
    "x_ship_to_first_name",            50,        NULL,                    "shipping_first_name"),
            array (
    "x_ship_to_last_name",            50,        NULL,                    "shipping_last_name"),
            array (
    "x_ship_to_company",            50,        NULL,                    "shipping_company"),
            array (
    "x_ship_to_address",            60,        NULL,                    "shipping_address"),
            array (
    "x_ship_to_city",            40,        NULL,                    "shipping_city"),
            array (
    "x_ship_to_state",            40,        NULL,                    "shipping_state"),
            array (
    "x_ship_to_zip",                20,        NULL,                    "shipping_zip"),
            array (
    "x_ship_to_country",            60,        NULL,                    "shipping_country"),
            array (
    "x_amount",                15,        StripNonMoney,                "amount"),
            array (
    "x_currency_code",            3,        NULL,                    "currency_code"),
            array (
    "x_method",                6,        NULL,                    "method"),
            array (
    "x_recurring_billing",            3,        NULL,                    "recurring_billing"),
            array (
    "x_card_num",                22,        StripNonNumeric,            "card_num"),
            array (
    "x_exp_date",                10,        StripNonNumeric,            "exp_date"),
            array (
    "x_card_code",                4,        StripNonNumeric,            "card_code"),
            array (
    "x_po_num",                25,        NULL,                    "purchase_order_num"),
            array (
    "x_tax",                    15,        StripNonMoney,                "tax"),
            array (
    "x_tax_exempt",                5,        TRUEorFALSE,                "tax_exempt"),
            array (
    "x_freight",                10,        StripNonMoney,                "freight"),
            array (
    "x_duty",                10,        StripNonMoney,                "duty"),
            array (
    "x_delim_data",                5,        TRUEorFALSE,                "delim_data"),
            array (
    "x_delim_char",                1,        NULL,                    "delim_char"),
            array (
    "x_encap_char",                1,        NULL,                    "encap_char"),
            array (
    "x_relay_response",            5,        TRUEorFALSE,            "relay_response"),
        );
                    
                    
        class 
    GatewayTransaction
        
    {
            
    // API settings;
            
    var $type;
            var 
    $method;
            var 
    $version;
            var 
    $username;
            var 
    $tran_key;
            var 
    $password;
            var 
    $test_mode;        // TRUE/FALSE
            
            // Email Settings
            
    var $email_customer;
            var 
    $merchant_email;
            var 
    $header_email_receipt;
            var 
    $footer_email_receipt;
            
            
    // Customer Information
            
    var $first_name;
            var 
    $last_name;
            var 
    $phone;
            var 
    $fax;
            var 
    $address;
            var 
    $city;
            var 
    $state;
            var 
    $zip;
            var 
    $country;
            var 
    $company;
            var 
    $email;
            var 
    $customer_ip;
            var 
    $customer_id;
        
            
    // Shipping Information
            
    var $shipping_company;
            var 
    $shipping_first_name;
            var 
    $shipping_last_name;
            var 
    $shipping_address;
            var 
    $shipping_city;
            var 
    $shipping_state;
            var 
    $shipping_zip;
            var 
    $shipping_country;
                
            
    // Transaction Information
            
    var $amount;
            var 
    $exp_month;
            var 
    $exp_year;
            var 
    $exp_date;
            var 
    $card_code;
            var 
    $card_num;
            var 
    $description;
            var 
    $tran_id;                // Gateway Transaction to reference for credit, void or prior_auth_capture
            
    var $purchase_order_num;        // Your own reference number - supposed to be the one given to customers
            
    var $invoice_num;            // Your own reference number
            
    var $tax;                // rarely used - tax is added into the $amount field    
            
    var $tax_exempt;            // rarely used - TRUE/FALSE
            
    var $freight;                // rarely used
            
    var $duty;                // rarely used
            
    var $recurring_billing;            // rarely used - TRUE/FALSE
            
    var $currency_code;            // rarely used - 3-letter currency like "USD" for US Dollars

        
            // E-Check Information
            
    var $check_type;
            var 
    $check_acct_name;
            var 
    $check_bank_name;
            var 
    $check_acct_type;
            var 
    $check_acct_num;
            var 
    $check_aba_code;
        
            
    // Extra stuff - you most likely should not send these
            
    var $organization_type;
            var 
    $license_state;
            var 
    $license_num;
            var 
    $license_dob;
            var 
    $customer_ssn;     

            
    // The API sets these so it can interpret the results
            
    var $delim_data;
            var 
    $delim_char;
            var 
    $encap_char;
            var 
    $relay_response;
            
            var 
    $ErrorStrings;
            var 
    $GatewayFieldNames;
        
            function 
    GatewayTransaction($variables$ipaddress)
            {
                global 
    $GatewaySettings;
                
                
    $this->ErrorStrings = & $GLOBALS['_transient']['static']['GatewayTransaction']->ErrorStrings;        
                
    $this->GatewayFieldNames = & $GLOBALS['_transient']['static']['GatewayTransaction']->GatewayFieldNames;                    
                
                
    // Gateway options
                
    $this->method "CC";   
                if(
    $variables['method'])
                    
    $this->method $variables['method'];
                    
                
    $this->type "AUTH_CAPTURE";         
                if(
    $variables['type'])
                    
    $this->type $variables['type'];
            
            
                
    // API Settings
                
    $this->username        $GatewaySettings['username'];
                
    $this->tran_key        $GatewaySettings['tran_key'];
                if(
    $variables['password'])
                    
    $this->password $variables['password'];
                
    $this->version        $GatewaySettings['version'];
                
    $this->test_mode    $GatewaySettings['test_mode'];
                if(
    $variables['test_mode'] && $GatewaySettings['AllowTestOverride'] == true)
                    
    $this->test_mode $variables['test_mode'];
                
                
                
    // Email Settings
                
    $this->email_customer     $GatewaySettings['email_customer'];
                if(
    $variables['email_customer'])
                    
    $this->email_customer $variables['email_customer'];
                
                
    $this->merchant_email    $GatewaySettings['merchant_email'];
                if(
    $variables['merchant_email'])
                    
    $this->merchant_email $variables['merchant_email'];
                
                
    $this->header_email_receipt $GatewaySettings['header_email_receipt'];
                if(
    $variables['header_email_receipt'])
                    
    $this->header_email_receipt $variables['header_email_receipt'];
                    
                
    $this->footer_email_receipt $GatewaySettings['footer_email_receipt'];
                if(
    $variables['footer_email_receipt'])
                    
    $this->footer_email_receipt $variables['footer_email_receipt'];
                
                
                
    // Contact Information
                
    $this->first_name    $variables['first_name']; 
                
    $this->last_name    $variables['last_name'];
                
    $this->phone        $variables['phone'];
                
    $this->fax        $variables['fax'];
                
    $this->address        $variables['address'];
                
    $this->city        $variables['city']; 
                
    $this->state        $variables['state'];
                
    $this->zip        $variables['zip'];
                
    $this->country        $variables['country'];
                
    $this->company        $variables['company'];
                
    $this->email        $variables['email'];
                
    $this->customer_ip    $ipaddress;
                
                
                
    // Transaction Information 
                
    $this->card_num            StripNonNumeric($variables['card_num']);
                
    $this->exp_month        StripNonNumeric($variables['exp_month']);
                
    $this->exp_year            StripNonNumeric($variables['exp_year']);
                
    $this->card_code        StripNonNumeric($variables['card_code']);
                
    $this->amount            StripNonMoney($variables['amount']);
                
    $this->customer_id        $variables['customer_id']; // For your reference; not used by authnet.
                
    $this->invoice_num        $variables['invoice_num'];
                
    $this->description        $variables['comments'];
                
    $this->tran_id            StripNonNumeric($variables['tran_id']);
                
    $this->recurring_billing    $variables['recurring_billing'];
                
    $this->currency_code        $variables['currency_code'];
                
                
                
    // Shipping Information 
                
    $this->shipping_company     $variables['shipping_company'];
                
    $this->shipping_first_name     $variables['shipping_first_name'];
                
    $this->shipping_last_name    $variables['shipping_last_name'];
                
    $this->shipping_address     $variables['shipping_address'];
                
    $this->shipping_city         $variables['shipping_city'];
                
    $this->shipping_state         $variables['shipping_state'];
                
    $this->shipping_zip         $variables['shipping_zip'];
                
    $this->shipping_country        $variables['shipping_country']; 
                
                
                
    // E-Check Information 
                
    $this->check_aba_code    StripNonNumeric($variables['check_aba_code']);      // Customer Routing Number
                
    $this->check_acct_num    StripNonNumeric($variables['check_acct_num']);      // Customer Account Number
                
    $this->check_acct_type    $variables['check_acct_type'];     // Customer Account Type ("CHECKING" or "SAVINGS")
                
    $this->check_bank_name    $variables['check_bank_name'];      // Customer Bank Name
                
    $this->check_acct_name    $variables['check_acct_name'];     // Customer Bank Account Owner
                
    $this->check_type    $variables['check_type'];           // Must be "WEB", if anything.
                
                
                // Optional Extra Data - rarely used
                
    $this->purchase_order_num    $variables['purchase_order_num']; 
                
    $this->tax_exempt        $variables['tax_exempt'];
                
                
    // The dollar amounts below must already be included in the 'amount' field. You would only 
                // put them here if you wanted the transaction to specifically note the different dollar amounts 
                // or if you were required to do so by your processor.
                // These are rarely used and generally unnecessary.
                
    $this->tax            $variables['tax'];
                
    $this->freight            $variables['freight'];
                
    $this->duty            $variables['duty'];        
                
                
    // Shouldn't be used unless directed to
                
    $this->organization_type    $variables['organization_type'];
                
    $this->license_state        $variables['license_state'];
                
    $this->license_num        $variables['license_num'];
                
    $this->license_dob        $variables['license_dob'];
                
    $this->customer_ssn        $variables['customer_ssn'];                 

                
    // API requirements - don't change
                
    $this->delim_data        "TRUE";
                
    $this->delim_char        ",";
                
    $this->encap_char        "";
                
    $this->relay_response    "FALSE";
            }
                
                
            function 
    VerifyFields(&$errorCode)
            {
                global 
    $GatewaySettings;
                    
                
    // Check for required settings
                
    if(!$this->username || (!$this->tran_key && !$this->password))
                {
                    
    $errorCode "MISSING_LOGIN";
                    return(
    false);
                }    
                    
                
    // Check for required Transaction data
                
    if($this->type == "AUTH_CAPTURE" 
                    
    || $this->type == "AUTH_ONLY"
                    
    || $this->type == "CREDIT")
                {
                    
    // Check for an amount
                    
    if(!VerifyAmount($this->amount$errorCode))
                        return(
    false);
                    
                    
    // Check for a payment method
                    
    if($this->type != "CREDIT")
                    {
                        if(
    $this->method == "CC")
                        {
                            if(!
    VerifyCCNumber($this->card_num$errorCode))
                                return(
    false);
                                
                            if(!
    VerifyExpirationDate($this->exp_month$this->exp_year$errorCode))
                                return(
    false);
                            else
                                
    $this->exp_date $this->exp_month $this->exp_year;
                                
                            if(
    $this->card_code)
                                if(!
    VerifyCVVCode($this->card_code$this->card_num$errorCode))
                                    return(
    false);
                        }
                        else if(
    $this->method == "ECHECK")
                        {
                            if(!
    $GatewaySettings['AllowEChecks'])
                            {
                                
    $errorCode "UNACCEPTED_ECHECKS";
                                return(
    false);
                            }
                            
                            if(!
    VerifyRoutingNumber($this->check_aba_code$errorCode))
                                return(
    false);
                                
                            if(!
    VerifyCheckingAccountNumber($this->check_acct_num$errorCode))
                                return(
    false);
                        }
                        else
                        {
                            
    $errorCode "INVALID_METHOD";
                            return(
    false);
                        }
                    }
                    else
                    {
                        if(
    $this->tran_id === "")
                        {
                            
    $errorCode "MISSING_TRANSACTIONID";
                            return(
    false);
                        }
                    }
                }
                else if(
    $this->type == "VOID"
                        
    || $this->type == "PRIOR_AUTH_CAPTURE")
                {
                        if(
    $this->tran_id === "")
                        {
                            
    $errorCode "MISSING_TRANSACTIONID";
                            return(
    false);
                        }                
                }
                else
                {
                    
    $errorCode "INVALID_TYPE";
                    return(
    false);
                }
                
                return(
    true);
            }        
                
                
            function 
    CreatePostString()
            {
                global 
    $GatewaySettings;
                
                
    $postString "";
                
                
    $numFields count($this->GatewayFieldNames);
                for(
    $iField 0$iField $numFields$iField++)
                {
                    list(
    $gField$maxLength$callback$classField) = $this->GatewayFieldNames[$iField];
                    
                    
    // Run special formatting functions
                    
    if($callback)
                        
    $value $callback($this->$classField);
                    else
                        
    $value $this->$classField;
                        
                    if(
    $value !== "")
                    {    
                        
    // Truncate to maximum length for field
                        
    $value substr($value0$maxLength);
                        
                        
    // Append value to request
                        
    $postString .= $gField "=" rawurlencode($value) . "&";
                    }
                }
                
                return(
    $postString);
            }
            
            
            function 
    ProcessTransaction(&$response, &$errorCode)
            {
                global 
    $GatewaySettings;
                
                if(!
    $this->VerifyFields($errorCode))
                    return(
    false);
                    
                
    $postString $this->CreatePostString();
                
                if(!
    SendHTTPPostData($postString$GatewaySettings['url'], $response$errorCode))
                    return(
    false);
                    
                return(
    true);
            }
            
            
            function 
    GetErrorString($errorCode)
            {
                return(
    $this->ErrorStrings[$errorCode]);
            }
        };




    ?>
    Last edited by INFIDEL; 02-12-2010 at 12:57 AM.

  • #4
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    help anyone else?

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    This isn't a place to get free work done; it's a place to help you with your PHP coding journey. If you need to hire someone to fix up your script I suggest posting in the Web Projects forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •