Jump to content
shichemt

Square Payments Plugin for osCommerce

Recommended Posts

This add-on will allow to accept Visa, MasterCard, American Express, Discover, JCB, or UnionPay credit cards via Square Payment Gateway on your osCommerce website.

 

Link to the contribution

 

Please post any bugs, problems and suggestions about  Square Payments Plugin for osCommerce in this topic. I will do my best to provide support.

Share this post


Link to post
Share on other sites

Thank you for creating this contribution!

 I had two issues that I've not been able to figure out after installing.

1)  When inserting the required code into "catalog/includes/template_bottom.php", the left column and right column of my website disappears.  I removed the code for now.

maximuminternational.com

2)  Also regarding the required code, I get a syntax error parse error unexpected '[' result from the last line of this code that is inserted into the template_bottom.php file (just above </body> at the end of the file).

 

<?php
      // SQUARE INSTALLATION 
      if (isset($payment) && $payment == MODULE_PAYMENT_SQUARE_TEXT_CODE) {
        
        $applicationID_query = tep_db_query("select configuration_value from configuration where configuration_key = 'MODULE_PAYMENT_SQUARE_APPLICATION_ID'");
        $applicationID = tep_db_fetch_array($applicationID_query)['configuration_value'];

I changed:

$applicationID = tep_db_fetch_array($applicationID_query)['configuration_value'];

To this:

$applicationID = tep_db_fetch_array($applicationID_query['configuration_value']);

Or this:

$applicationID = tep_db_fetch_array($applicationID_query('configuration_value'));

The error changes to syntax error parse error unexpected ';' for the same line of code.  I don't write code, so I don't know where to go from here, but think I could follow instructions to get this working.

I'm using osCommerce v2.3.3, PHP 5.3.29

Cory

Share this post


Link to post
Share on other sites

Remove this request and use only 

MODULE_PAYMENT_SQUARE_APPLICATION_ID


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

Tuto for 2.4 :
- How to Display a new page with app
- How to make Header Tags under app APP
- How to make a
boostrap modal with external element
 

 

Share this post


Link to post
Share on other sites
On 1/25/2019 at 9:43 PM, Gyakutsuki said:

Remove this request and use only 


MODULE_PAYMENT_SQUARE_APPLICATION_ID

This resolved both of my errors.  Thank you.

Now I just need to track down a "/checkout_payment.php?payment_error=square&error=INVALID_REQUEST_ERROR".

Share this post


Link to post
Share on other sites
On 1/28/2019 at 10:56 AM, Cory_C said:

This resolved both of my errors.  Thank you.

Now I just need to track down a "/checkout_payment.php?payment_error=square&error=INVALID_REQUEST_ERROR".

Let me know what you've done so far, and/or DM me a screenshot of the issue that you're encountering.

Share this post


Link to post
Share on other sites

We use Sucuri for malware prevention on our website.  I have been back in forth with them and our site host as this is most likely because of the Sucuri firewall protection where the requests I receive at the hosting server is from firewall range of IP's (USER -->>> FIREWALL -->>> SERVER).

Sucuri support is asking me:   "Have you checked with the module developer yet to see if they are familiar with working with reverse proxy systems in regards to seeing the correct user IP address?"

Share this post


Link to post
Share on other sites
On 2/4/2019 at 12:44 PM, Cory_C said:

We use Sucuri for malware prevention on our website.  I have been back in forth with them and our site host as this is most likely because of the Sucuri firewall protection where the requests I receive at the hosting server is from firewall range of IP's (USER -->>> FIREWALL -->>> SERVER).

Sucuri support is asking me:   "Have you checked with the module developer yet to see if they are familiar with working with reverse proxy systems in regards to seeing the correct user IP address?"

That's a really good question you can ask to Square because I only brought their payment gateway to osCommerce. AFAIK, the IP address that submits the order is what it gets submitted to the order page in the admin side, but I am not sure how Square handles that from their side.

Share this post


Link to post
Share on other sites

I am also having the same error INVALID_REQUEST_ERROR after attempting a transaction, is there anything special i have to do to make my installation compatible with the composer / autoload vendor stuff? 

Share this post


Link to post
Share on other sites

Here are the changes I had to make to get this addon to work. Thanks for your contribution, Square is a great asset!

////////////////
on template_bottom.php
Step 1: 
change
     $applicationID_query = tep_db_query("select configuration_value from configuration where configuration_key = 'MODULE_PAYMENT_SQUARE_APPLICATION_ID'");
     $applicationID = tep_db_fetch_array($applicationID_query)['configuration_value'];
to
	 $applicationID_query = tep_db_query("select configuration_value from configuration where configuration_key = 'MODULE_PAYMENT_SQUARE_APPLICATION_ID'");
     $application_array = tep_db_fetch_array($applicationID_query);
     $applicationID = $application_array['configuration_value'];

Step 2:
change 
     document.getElementById("form").submit();
to
     document.getElementById("checkout_confirmation").submit();

////////////////
on checkout_confirmation.php
Step 1:
change 
  echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');
to
  echo tep_draw_form('checkout_confirmation', $form_action_url, 'post', 'id="checkout_confirmation"');

Step 2:
after 
  if (is_array($payment_modules->modules)) {
    echo $payment_modules->process_button();
  } 

add
if ($payment_modules->selected_module != 'square') {  
	   echo tep_draw_button(IMAGE_BUTTON_CONFIRM_ORDER, 'check', null, 'primary');
}

 

Share this post


Link to post
Share on other sites
7 hours ago, djppimp said:

Here are the changes I had to make to get this addon to work. Thanks for your contribution, Square is a great asset!


////////////////
on template_bottom.php
Step 1: 
change
     $applicationID_query = tep_db_query("select configuration_value from configuration where configuration_key = 'MODULE_PAYMENT_SQUARE_APPLICATION_ID'");
     $applicationID = tep_db_fetch_array($applicationID_query)['configuration_value'];
to
	 $applicationID_query = tep_db_query("select configuration_value from configuration where configuration_key = 'MODULE_PAYMENT_SQUARE_APPLICATION_ID'");
     $application_array = tep_db_fetch_array($applicationID_query);
     $applicationID = $application_array['configuration_value'];

Step 2:
change 
     document.getElementById("form").submit();
to
     document.getElementById("checkout_confirmation").submit();

////////////////
on checkout_confirmation.php
Step 1:
change 
  echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');
to
  echo tep_draw_form('checkout_confirmation', $form_action_url, 'post', 'id="checkout_confirmation"');

Step 2:
after 
  if (is_array($payment_modules->modules)) {
    echo $payment_modules->process_button();
  } 

add
if ($payment_modules->selected_module != 'square') {  
	   echo tep_draw_button(IMAGE_BUTTON_CONFIRM_ORDER, 'check', null, 'primary');
}

 

Thank you much,

My install worked perfect but had 2 confirm order buttons one would post the sale through Square and the other would give php errors.

I made your modifications and now have one perfectly functioning confirm order button.

Thanks,
Joe

Share this post


Link to post
Share on other sites

I spoke too soon.

Ok, Everything works but I thought I would try a card that was valid but would get declined as its a out of money prepaid card. To see what the error message would be for a declined card.

And I got a php error of:

Warning: Missing argument 5 for tep_mail(), called in /home/connecto/public_html/catalog/includes/modules/payment/square.php on line 370 and defined in /home/connecto/public_html/catalog/includes/functions/general.php on line 3115

Warning: Missing argument 6 for tep_mail(), called in /home/connecto/public_html/catalog/includes/modules/payment/square.php on line 370 and defined in /home/connecto/public_html/catalog/includes/functions/general.php on line 3115

Warning: Cannot modify header information - headers already sent by (output started at /home/connecto/public_html/catalog/includes/functions/general.php:3115) in /home/connecto/public_html/catalog/includes/functions/general.php on line 148

 

Any clues what I should do???

I am no programmer but can follow PHP somewhat since I have setup my Oscommerce store 15yrs ago and have added modules that come with instructions.

Thank you for your help.

Joe

Share this post


Link to post
Share on other sites

I temporarily commented out the tep_mail so it just displays the CC error message to the customer and does not email it.

If anyone can help me get the email function working that would be great.

 

Thanks,
Joe

Share this post


Link to post
Share on other sites
22 hours ago, j0ec00l2k said:

I spoke too soon.

Ok, Everything works but I thought I would try a card that was valid but would get declined as its a out of money prepaid card. To see what the error message would be for a declined card.

And I got a php error of:

Warning: Missing argument 5 for tep_mail(), called in /home/connecto/public_html/catalog/includes/modules/payment/square.php on line 370 and defined in /home/connecto/public_html/catalog/includes/functions/general.php on line 3115

Warning: Missing argument 6 for tep_mail(), called in /home/connecto/public_html/catalog/includes/modules/payment/square.php on line 370 and defined in /home/connecto/public_html/catalog/includes/functions/general.php on line 3115

Warning: Cannot modify header information - headers already sent by (output started at /home/connecto/public_html/catalog/includes/functions/general.php:3115) in /home/connecto/public_html/catalog/includes/functions/general.php on line 148

 

Any clues what I should do???

I am no programmer but can follow PHP somewhat since I have setup my Oscommerce store 15yrs ago and have added modules that come with instructions.

Thank you for your help.

Joe

 

tep_mail(STORE_OWNER,  STORE_OWNER_EMAIL_ADDRESS, "Square Debug Error", "Square has encountered some errors:\n\n".var_export($e, true)."n\n\n". "Customer ID: ".$customer_id . "r\n\r\n\r\n".var_export($order, true));

Well from what I make of it the 2 variables that its looking for Store_Owner and Store_owner_Email_Address  are not defined in the general.php file

 

So I tried this..

tep_mail(STORE_OWNER, 'My Name', STORE_OWNER_EMAIL_ADDRESS, 'myemailaddress@gmail.com', "Square Debug Error", "Square has encountered some errors:\n\n".var_export($e, true)."n\n\n". "Customer ID: ".$customer_id . "r\n\r\n\r\n".var_export($order, true));

 

I did not get the email but it did not cause any php errors and it returned the customer to the payment page with the CC error.

 

Anyone?

Share this post


Link to post
Share on other sites

I resolved the namespace error.

I made the changes recommended by Joe, but now have 2 buttons when not a square payment.  Also get the invalid request error.

Any other suggestions?

Share this post


Link to post
Share on other sites

After much digging I found that $HTTP_POST_VARS['nonce'] is not getting set, therefore no card data.  HTTP_POST_VARS in general is working, as it is used extensively in osCommerce.  HELP please!

Share this post


Link to post
Share on other sites

The problem with the calls to tep_mail is that the last 2 arguments are missing.  They are the From Name and the From Email.  In modules/payment/square.php  at about line 370 You can change :

true))

to

true), STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS)

to fix the error.  These can also be set to any name, email you choose.

 

Carl

Share this post


Link to post
Share on other sites

Thank you so much for creating this module.  I am excited to put it to work, but I need a hand with a couple of errors. I'm afraid I do not code PHP and this is the first module I've tried to install.

osCommerce Online Merchant v2.2 RC2a
PHP Version 4.4.9

As the website administrator, I go to the module to install square. Square is not there and I see:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/username/public_html/includes/modules/payment/square.php on line 320

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/username/public_html/includes/modules/payment/square.php on line 320

Parse error: syntax error, unexpected T_STRING in /home/username/public_html/includes/modules/payment/square.php on line 320

I go to the file and I find line 320:

$transaction_api = new \SquareConnect\Api\TransactionApi();

 

It's in this function block:

function before_process() {
            global $order, $HTTP_POST_VARS, $customer_id;

            require(DIR_WS_CLASSES . "square" . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . 'autoload.php');
            
            $requirement_query = tep_db_query("select f.configuration_value as access_token, s.configuration_value AS locationId from configuration f, configuration s where f.configuration_key = 'MODULE_PAYMENT_SQUARE_ACCESS_TOKEN' AND s.configuration_key = 'MODULE_PAYMENT_SQUARE_LOCATION_ID';");
            $requirement_array = tep_db_fetch_array($requirement_query);
            
            $access_token = $requirement_array['access_token'];
            $locationID = $requirement_array['locationId'];
            
        
            $transaction_api = new \SquareConnect\Api\TransactionApi();
            $request_body = array (
              "card_nonce" => $HTTP_POST_VARS['nonce'],
              # Monetary amounts are specified in the smallest unit of the applicable currency.
              # This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.
              "amount_money" => array (
                "amount" => (round($order->info['total'], 2) * 100 ),
                
            # Amount explanation:
            # 100 is 1.00 USD
            # 10000 is 100.00 USD
                
                "currency" => "USD"
              ),

 

I tried a couple of syntax changes to line 320.

Original:

$transaction_api = new \SquareConnect\Api\TransactionApi();

Syntax Change 1:

$transaction_api = new ['\SquareConnect\Api\TransactionApi']();

Result:

The other warnings disappear and I'm left with the following error.

Parse error: syntax error, unexpected '[', expecting T_STRING or T_VARIABLE or '$' in /home/username/public_html/includes/modules/payment/square.php on line 320

I couldn't find the \SquareConnect\Api\TransactionApi  path in my file system.

I look forward to any thoughts you have. I'd love to start using Square.

Thanks!

 

 

 

 

 

Share this post


Link to post
Share on other sites
Posted (edited)
On 2/17/2019 at 6:21 AM, j0ec00l2k said:

 

....

tep_mail function only has 4 arguments (unless it is modified), and the line of code below is only for debug if there's any issues with a transaction.

STORE_OWNER/STORE_OWNER_EMAIL_ADDRESS are not defined in your system.

Therefore, change  :

tep_mail(STORE_OWNER,  STORE_OWNER_EMAIL_ADDRESS, "Square Debug Error", "Square has encountered some errors:\n\n".var_export($e, true)."n\n\n". "Customer ID: ".$customer_id . "r\n\r\n\r\n".var_export($order, true));

to

tep_mail("STORE_OWNER", "youremail@yourdomain.com", "Square Debug Error", "Square has encountered some errors:\n\n".var_export($e, true)."n\n\n". "Customer ID: ".$customer_id . "r\n\r\n\r\n".var_export($order, true));

and let us know if the issue was resolved.

 

 

** EDIT: if the issue is not resolved, can you pastebin your tep_mail function? Thank you.

Edited by shichemt
General Adjustment

Share this post


Link to post
Share on other sites
4 hours ago, EmpOphelia said:

...

Unfortunately PHP 5.2 and below are not supported as namespaces are being used in this plug-in and those versions do not support that. Please try upgrading to PHP 5.3 or later, and let us know if the issue was resolved.

Share this post


Link to post
Share on other sites
On 2/22/2019 at 5:33 PM, cmcdanel said:

...

nonce should be set through Square JS. Make sure that you've added the <script> tag in template_bottom.php and you're placing the order through HTTPS.

Share this post


Link to post
Share on other sites

Hello,

We are attempting to use this module. On the checkout_payment.php page, we end up with https://i.gyazo.com/de89d794624ee52ecd6baa5e7dc4e529.png

We cannot enter any CC details, nor select a credit card type. Upon hitting continue we will get "error_message=Please+select+a+payment+method+for+your+order."

We followed the original installation, then also tried j0ec00l2k's suggestions for making it compatible.

Using PHP 5.6.

 

Any help would be appreciated greatly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×