We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4385
    • 372 Posts
    I was reading @mconsidine post about using the PHP PaymentGateway. Nice job.

    I think I might be needing to do this with Authorize.Net so I adapted what was there based on Matt’s example.

    <?php
    global $modx;
     $base_dir = $modx->config['rb_base_dir'];
    
      $dbname = $modx->db->config['dbase'];
      $dbprefix = $modx->db->config['table_prefix'];
      $mod_table = $dbprefix."manager_shopkeeper";
      $mod_config_table = $dbprefix."manager_shopkeeper_config";
      $reportTpl = $_SESSION['reporttpl'] ? $_SESSION['reporttpl'] : $fields['reportTpl'];
      $userLogged =  isset($_SESSION['webValidated']) ? true : false;
    
        //Get online payment info
        $order_id = $_SESSION['shk_order_id'];
        $fields['payment'] = $_SESSION['shk_payment_method'];
        $price = $_SESSION['shk_order_price'];
        $currency = $_SESSION['shk_currency'];
        $userId = $_SESSION['shk_order_user_id'];
        $order_email = $_SESSION['shk_order_user_email'];
    
      require_once $base_dir."snippets/payment/PaymentGateway.php";
      require_once $base_dir."snippets/payment/Authorize.php";
    
    
    	// Create an instance of the authorize.net library
    	$myAuthorize = new Authorize();
    	
    	// Specify your authorize.net login and secret
    	$myAuthorize->setUserInfo('YOUR_LOGIN', 'YOUR_KEY');
    	
    	// Specify the url where authorize.net will send the user on success/failure
    	$myAuthorize->addField('x_Receipt_Link_URL', 'http://www.google.com');
    	
    	// Specify the url where authorize.net will send the IPN
    	$myAuthorize->addField('x_Relay_URL', 'http://www.google.com/working_on_this_part');
    	
    	// Specify the product information
    	$myAuthorize->addField('x_Description', "Online order from " . $modx->config['site_name']);
    	$myAuthorize->addField('x_Amount', $price);
    	$myAuthorize->addField('x_Invoice_num', $order_id);
    	$myAuthorize->addField('x_Cust_ID', $order_email );
    
    
    // passing customer info
    	$myAuthorize->addField('x_first_name', $_SESSION['shk_order_user_fname']);
    	$myAuthorize->addField('x_address', $_SESSION['shk_order_user_address']);
    	$myAuthorize->addField('x_city', $_SESSION['shk_order_user_city']);
    	$myAuthorize->addField('x_state', $_SESSION['shk_order_user_state']);
    	$myAuthorize->addField('x_email', $_SESSION['shk_order_user_email']);
    
    	
    	// Enable test mode if needed
    	$myAuthorize->enableTestMode();
    	
    	// Let's start the train!
    	$myAuthorize->submitPayment();
    
    
      return true;
    ?>
    


    But to get the customer information to the gateway I had to modify shopkeeper.inc.php and added

    // customer payment information
    
          $_SESSION['shk_order_user_fname'] = $fields['name'];
          $_SESSION['shk_order_user_address'] = $fields['address'];
          $_SESSION['shk_order_user_city'] = $fields['city'];
          $_SESSION['shk_order_user_state'] = $fields['state'];
    // end add on
    


    Is there a better way with out modifying the source?

    After that I need to get the IPN to change the status of the order to paid.
      DropboxUploader -- Upload files to a Dropbox account.
      DIG -- Dynamic Image Generator
      gus -- Google URL Shortener
      makeQR -- Uses google chart api to make QR codes.
      MODxTweeter -- Update your twitter status on publish.
      • 4385
      • 372 Posts
      It seems to be working. But I had to modify the source.

      Also any insight on modifying the module? I want change the status (i think it is "2" in the database") to paid when Authorize.net hits the success page. I think I am getting a string back but can’t seem to be able to verify yet.

        DropboxUploader -- Upload files to a Dropbox account.
        DIG -- Dynamic Image Generator
        gus -- Google URL Shortener
        makeQR -- Uses google chart api to make QR codes.
        MODxTweeter -- Update your twitter status on publish.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You will have to modify source to conform to different gateways. That’s the hard part about ecommerce; there is no consistent way to interact with the different gateways, so each one basically needs a custom access module. When I did ShopX I tried to develop more of an API/plugin architecture, but it still was a royal pain in the neck.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org