Miscellaneous Code
  Home arrow Miscellaneous Code arrow GoEMerchant.com Gateway Class
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

GoEMerchant.com Gateway Class
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2004-01-12

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    This class allows you to submit Credit Card transactions to the merchant provider GoEmerchant.com. It requires Curl. There is a debug feature you can turn on that will allow you to test it as you code without needing to send a request to their server.

    By : sleighboy

    <?php
    /* Author: Daniel Anderson */
    /* http://www.dattrix.com/ */
    /* GoEMerchant.com Gateway PHP Class*/
    /* Requires: CURL */

    class GoEmerchant {

    /* Specify your username and password */
    var $merchant = "USERNAME";
    var $password = "PASSWORD";

    /* You can set this to 1, and it will not send the transaction. It will just return whatever you specify for debug_return */
    var $debug = 0;
    var $debug_return = 0;

    /* An array that stores the last data sent to the class */
    var $recent_transaction = array("success"=>"","authcode"=>"","authresponse"=>"","avs_code"=>"","orderid_given"=>"","orderid_returned"=>"","total"=>"","cardname"=>"","cardnum1"=>"","cardnum2"=>"","cardnum3"=>"","cardnum4"=>"","cardexpm"=>"","cardexpy"=>"","cvv2"=>"","nameoncard"=>"","cardstreet"=>"","cardcity"=>"","cardstate"=>"","cardzip"=>"","cardcountry"=>"");

    /* Will be 1 if Curl is available */
    var $curl_available;

    /* Array that will store errors */
    var $error;

    /* This function runs automatically upon object creation to determine if Curl is available*/
    function GoEmerchant(){
    if(extension_loaded("curl"))
    $this->curl_available = 1;
    else
    $this->curl_available = 0;
    }

    /* This does the processing, the $orderid argument is your own order ID number, everything else should be pretty self-explanatory , default Country is US*/
    function process_credit_card($orderid,$total,$cardnum1,$cardnum2,$cardnum3,$cardnum4,$cardexpm,$cardexpy,$cvv2,$nameoncard,$cardstreet,$cardcity,$cardstate,$cardzip,$cardcountry = "US"){

    /* If you set debug to 1, it skips any real processing and just returns what you told it to return */
    if($this->debug == 0){
    /* Make sure all arguments are passed to function */
    if($cardcountry != "US")
    $num_args = 15;
    else
    $num_args = 14;

    if(func_num_args() == $num_args){
    /*Auto-Correct Total Field*/
    $total = str_replace("\$","",str_replace(",","",$total));


    /*Check argument data types*/
    $cc_string = $cardnum1 . $cardnum2 . $cardnum3 . $cardnum4;
    if(!is_numeric($cc_string)){
    $this->error[] = "Invalid Credit Card Number Format";
    }
    unset($cc_string);

    if(strlen($cardexpm) != 2){
    $this->error[] = "Invalid Credit Card Expiry Month Format";
    }

    if(strlen($cardexpy) != 2){
    $this->error[] = "Invalid Credit Card Expiry Year Format";
    }

    if(strlen($cardstate) != 2){
    $this->error[] = "Invalid Credit Card State Format";
    }

    if(strlen($cardcountry) != 2){
    $this->error[] = "Invalid Credit Card Country Format";
    }

    /* Determine Card Type*/
    switch (substr($cardnum1,0,1)) {
    default:
    $this->error[] = "Invalid/Unknown Card Type";
    break;

    case 3 :
    $card_type = "Amex";
    break;

    case 4 :
    $card_type = "Visa";
    break;

    case 5 :
    $card_type = "MasterCard";
    break;

    case 6 :
    $card_type = "Discover";
    break;
    }

    /* Run error checks based on card type */
    switch($card_type){
    case 'Amex':
    if(strlen($cvv2) != 4)
    $this->error[] = "American Express Requires Four-Digit CVV2 Code";

    if(strlen($cardnum4) != 3)
    $this->error[] = "Invalid American Express Card Number";
    break;

    case 'MasterCard':
    if(strlen($cvv2) != 3)
    $this->error[] = "MasterCard Requires Three-Digit CVV2 Code";
    break;

    case 'Visa':
    if(strlen($cvv2) != 3)
    $this->error[] = "Visa Requires Three-Digit CVV2 Code";
    break;

    case 'Discover':
    if(strlen($cvv2) != 3)
    $this->error[] = "Discover Requires Three-Digit CVV2 Code";
    break;
    }


    if(count($this->error) == 0){
    $this->recent_transaction["orderid_given"] = $orderid;
    $this->recent_transaction["total"] = $total;
    $this->recent_transaction["cardname"] = $card_type;
    $this->recent_transaction["cardnum1"] = $cardnum1;
    $this->recent_transaction["cardnum2"] = $cardnum2;
    $this->recent_transaction["cardnum3"] = $cardnum3;
    $this->recent_transaction["cardnum4"] = $cardnum4;
    $this->recent_transaction["cardexpm"] = $cardexpm;
    $this->recent_transaction["cardexpy"] = $cardexpy;
    $this->recent_transaction["cvv2"] = $cvv2;
    $this->recent_transaction["nameoncard"] = $nameoncard;
    $this->recent_transaction["cardstreet"] = $cardstreet;
    $this->recent_transaction["cardcity"] = $cardcity;
    $this->recent_transaction["cardstate"] = $cardstate;
    $this->recent_transaction["cardzip"] = $cardzip;
    $this->recent_transaction["cardcountry"] = $cardcountry;

    $csess = curl_init();

    curl_setopt ($csess, CURLOPT_URL, "https://www.goemerchant7.com/cgi-bin/gateway/gateway.cgi");
    curl_setopt ($csess, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($csess, CURLOPT_HEADER, 0);
    curl_setopt ($csess, CURLOPT_POST, 1);
    curl_setopt ($csess, CURLOPT_POSTFIELDS, "merchant=" . $this->merchant . "&password=" . $this->password . "&operation_type=auth&orderid=" . urlencode($orderid) . "&total=" . number_format($total,2,'.','') . "&cardname=" . $card_type . "&cardnum1=" . $cardnum1 ."&cardnum2=" . $cardnum2 ."&cardnum3=" . $cardnum3 ."&cardnum4=" . $cardnum4 ."&cardexpm=" . $cardexpm . "&cardexpy=" . $cardexpy . "&CVV2=" . $cvv2 . "&nameoncard=" . urlencode($nameoncard) . "&cardstreet=" . urlencode($cardstreet) . "&cardcity=" . urlencode($cardcity) . "&cardstate=" . urlencode($cardstate) . "&cardzip=" . $cardzip . "&cardcountry=" . urlencode($cardcountry) . "");

    $returned = curl_exec ($csess);

    if(curl_errno($csess) == 0){
    $get_status = explode("|",$returned);
    $this->recent_transaction["success"] = $get_status[0];
    $this->recent_transaction["authcode"] = $get_status[1];
    $this->recent_transaction["authresponse"] = trim(strip_tags($get_status[2]));
    $this->recent_transaction["avs_code"] = $get_status[3];
    $this->recent_transaction["orderid_returned"] = $get_status[4];

    if($this->recent_transaction["success"] == 1)
    return true;
    else
    return false;

    }else{
    $this->error[] = "Error Contacting CC Authorization Server";
    return false;
    }

    curl_close ($csess);
    }
    }else{
    $this->error[] = "Function process_credit_card Missing argument(s)";
    return false;
    }

    }else{
    /* If debugging was toggled, then do as it was instructed to do */
    if($this->debug_return == 0){
    $this->recent_transaction["success"] = 0;
    $this->recent_transaction["authcode"] = "";
    $this->recent_transaction["authresponse"] = "Developer Debugging Forces Decline";
    $this->recent_transaction["avs_code"] = 0;
    $this->recent_transaction["orderid_returned"] = $orderid;
    return false;
    }else{
    $this->recent_transaction["success"] = 1;
    $this->recent_transaction["authcode"] = "ASDFG12345";
    $this->recent_transaction["authresponse"] = "Developer Debugging Forces Accept";
    $this->recent_transaction["avs_code"] = 1;
    $this->recent_transaction["orderid_returned"] = $orderid;
    return true;
    }
    }
    }

    }


    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    Build Forge Express demo: Enabling software delivery excellence for small and midsized businesses

    This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process.
    FREE! Go There Now!


    NEW! Download DB2 Express-C 9.5

    Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Software Analyzer V7.0

    Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
    FREE! Go There Now!


    NEW! Evaluate Rational Business Developer V7.1

    Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase.
    FREE! Go There Now!


    NEW! Rational 'Talks to You' Teleconference Series

    This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today!
    FREE! Go There Now!


    NEW! Rational Testing eKits

    Discover how Rational tools and best practices for testing can make your job easier. The new Rational Testing eKits provide you with valuable resources – including demos, webcasts, tutorials, and articles – that help you address your specific testing needs across the software lifecycle. Five new eKits are available covering the topics of Requirements and Test Management, Functional Testing, Performance Testing, Code Quality and Embedded Systems, and SOA and Web Services Testing.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    FREE! Go There Now!


    NEW! Webcast: WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek