We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    Okay, I think I’ve managed to replicate the Russian demo site using the 0.9.1 version of the code. "&flytoCart=’image’" works if you omit the "&changePrice" parameter in the example, for what it’s worth. The docs say it’s not implemented, but that’s not true. Next step will be to try to integrate the Paypal work I had done earlier as well as to figure out some different cart styles.

    Anyone got favorites? I think we also need a "View cart" and "Continue shopping" option, no?

    MattC
      • 22574
      • 181 Posts
      Cheers that worked, it didn’t work the first time because I didn’t have the red=1.00, why does it need the money value out of curiosity?

      Also I am going to try adding a paypal function I’ll let you know how I go.

        • 18913
        • 654 Posts
        Hi,
        You could set it to 0. I think also something like == works as a blank. Not sure, but it needs something as a placeholder. Maybe "blue=blue"? I’d need to look into that.

        Let us know how your paypal integration works. What code are you using - your own or something like the payment gateway class mentioned earlier in this (I think) thread?

        Matt
          • 18913
          • 654 Posts
          For anyone else googing around with this approach, here is the snippet I have - called by its own document page - which deals with Paypal. The document is referred to by the eForm call on the order page. This is just what I’m working with at the moment. Not all the code may be needed, other stuff should be added, etc. etc. But it serves to try out the loop. The good thing is that the other two gateways I think are approached the same way. So it should be possible to get them to work in fairly short order (though I’m not attempting that.).

          Also, I’ve got hardcode in this code some index pages, which refer to ipn, thank you and failure pages. You’d need to change those for your own purposes, as well as have a paypal test account set up.

          Hope this helps,
          Matt

          PS If anyone can point out logic problems, improvements, etc. I’d be appreciative.
          PPS One thing not dealt with here is "exploding" the order submitted, or handling multiple orders in the database. There ought to be some looping logic added...

          <?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'];
          
            require_once $base_dir."snippets/payment/PaymentGateway.php";
            require_once $base_dir."snippets/payment/Paypal.php";
          
          	// Create an instance of the paypal library
          	$myPaypal = new Paypal();
          	// Specify your paypal email
          	$myPaypal->addField('business', 'your teststore email address');
          	// Specify the currency
          	$myPaypal->addField('currency_code', 'USD');
          	// Specify the url where paypal will send the user on success/failure
          	$myPaypal->addField('return', 'http://your_website_url/index.php?id=88');
          	$myPaypal->addField('cancel_return', 'http://your_website_url/index.php?id=95');
          	// Specify the url where paypal will send the IPN
          	$myPaypal->addField('notify_url', 'http://your_website_url/index.php?id=96');
          
          
                $user = $modx->userLoggedIn();
                $userId = $user['id'];
                $user_purchase_query = $modx->db->select("*", $dbprefix."web_user_settings", "webuser = $userId", "", "");
                if($modx->db->getRecordCount($user_purchase_query)>0){
          
          	// Specify the product information
          	$myPaypal->addField('item_name', $order_id);
          	$myPaypal->addField('amount', $price);
          	$myPaypal->addField('item_number', $userId);
          
          	// Specify any custom value
          	$myPaypal->addField('custom', 'SHK test '.$userId);
          
               }
          
          	// Enable test mode if needed	
          	$myPaypal->enableTestMode();
          
          	// Let's start the train!
          	$myPaypal->submitPayment();
          
            return true;
          
          ?>
            • 26931
            • 2,314 Posts
            hey mconsidine - nice smiley thanks for sharing!
              • 22574
              • 181 Posts
              Hey mconsidine,

              Thanks for this but I am trying to get this working.
              "The document is referred to by the eForm call on the order page"
              So should I have the eform chunk "shopOrderForm" for action post to the paypal snippet page?

              Also where are thesnippets/payment/PaymentGateway.php and snippets/payment/Paypal.php files?

              Thanks
                • 18913
                • 654 Posts
                Hi,
                Here’s what I did. No doubt there’s a better way wink (I’ll assume you’re okay to the point of getting the Shopkeeper orderform correctly called.

                - For the gateway code, I used what is found here :

                http://www.phpfour.com/blog/2009/02/php-payment-gateway-library-for-paypal-authorizenet-and-2checkout/

                - I created the following folder
                assets/snippets/payments
                and put the contents of the ZIP file found at the location above there. So that is where Paypal.php,
                PaymentGateway.php, et. al. live.
                - In MODx, I created a snippet called

                shk_paypal

                - The contents of the snippet are what was referred to above. But I’ll include it again here anyway :
                <?php
                //MattC start
                //function sendOrderToPayPal() {
                 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'];
                
                  require_once $base_dir."snippets/payment/PaymentGateway.php";
                  require_once $base_dir."snippets/payment/Paypal.php";
                
                	// Create an instance of the paypal library
                	$myPaypal = new Paypal();
                	// Specify your paypal email
                	$myPaypal->addField('business', 'your_developer_paypal_test_store_email');
                	// Specify the currency
                	$myPaypal->addField('currency_code', 'USD');
                	// Specify the url where paypal will send the user on success/failure
                	$myPaypal->addField('return', 'http://your_MODx_website/index.php?id=88');
                	$myPaypal->addField('cancel_return', 'http://your_MODx_website/index.php?id=95');
                	// Specify the url where paypal will send the IPN
                	$myPaypal->addField('notify_url', 'http://your_MODx_website/index.php?id=96');
                
                
                      $user = $modx->userLoggedIn();
                      $userId = $user['id'];
                      $user_purchase_query = $modx->db->select("*", $dbprefix."web_user_settings", "webuser = $userId", "", "");
                      if($modx->db->getRecordCount($user_purchase_query)>0){
                
                	// Specify the product information
                	$myPaypal->addField('item_name', $order_id);
                	$myPaypal->addField('amount', $price);
                	$myPaypal->addField('item_number', $userId);
                
                	// Specify any custom value
                	$myPaypal->addField('custom', 'SHK test '.$userId);
                     }
                
                	// Enable test mode if needed	
                	$myPaypal->enableTestMode();
                
                	// Let's start the train!
                	$myPaypal->submitPayment();
                
                  return true;
                //}
                //MattC end
                ?>
                

                (You’ll see that a lot of the values that I used for the fields don’t make a lot of sense. I was just trying to get info going out and back. Also, I’ve never been clear on how the IPN page is supposed to work...)

                - Over in the document pane, I created a new document whose content is
                    [!shk_paypal!]
                

                It’s document ID is 97.

                - On my orderform, I changed my call to go to the paypal snippet document instead of the thank you page. So
                "gotoid" was changed to 97 :
                  [!Shopkeeper? &lang=`en` &currency=`USD` &cartType=`full` &orderFormPage=`[*id*]`!]
                  [!eForm? &formid=`shopOrderForm`&tpl=`shopOrderForm`&report=`shopOrderReport`&vericode=`1`&ccsender=`1`&gotoid=`97`&subject=`SHK order`&eFormOnBeforeMailSent=`populateOrderData`&eFormOnMailSent=`sendOrderToManager`!]
                

                (The thank you/cancel pages are dealt with in the shk_paypal snippet)

                Finally, note that this is set up so that you have to be logged in as a webuser in order to send an order as the code I pulled from Shopkeeper (if I remember correctly) queries the database for order info that has been entered.

                I think that’s it. Hope this helps. Feedback/discussion would be appreciated, particularly as it appears this payment gateway class can handle more than just Paypal.

                Regards,
                MattC
                  • 8345
                  • 147 Posts
                  Quote from: mconsidine at Dec 11, 2009, 12:54 PM

                  Finally, note that this is set up so that you have to be logged in as a webuser in order to send an order as the code I pulled from Shopkeeper (if I remember correctly) queries the database for order info that has been entered.

                  Thanks MattC, just one question - how to do it so that you don’t have to be logged on as webuser?
                    • 18913
                    • 654 Posts
                    I think Shopkeeper requires you to be logged in in order to place an order, as the order info is associated with the userid... Unless I don’t understand what you are asking.
                    MattC
                      • 8345
                      • 147 Posts
                      Nope, at the moment I have Shopkeeper set up so that you just fill in your email address and some more details at checkout page and after clicking "Order" button eForm just sends the order confirmation to admin and to the customer. Also information is stored in Shopkeeper module.