Zen Cart Logo
Forums / Addon Payment Modules / Square Payment Module for Zen Cart [Support Thread]

Square Payment Module for Zen Cart [Support Thread]

Sticky

Views: 366,761

Results 221 to 240 of 835
5 Oct 2018, 10:44 AM
#221
gerrim avatar

gerrim

New Zenner

Join Date:
Jul 2013
Location:
Brisbane, Australia
Posts:
39
Plugin Contributions:
0

Square Payment Module for Zen Cart [Support Thread]

DrByte:

The fact that your 2nd echo does not appear means the code before it is failing with fatal errors. Your server's PHP error-logs will contain more information. Clearly something's unusual about your server config which is preventing this from operating normally.

Thanks, Dr Byte - appreciate the advice on the way forward. I've started investigating how to access those PHP error logs. Will report back after speaking with my ISP (need their intervention to enable PHP error tracking, which is currently turned off) and when I know more. Fingers crossed.

24 Oct 2018, 1:41 PM
#222
mvstudio avatar

mvstudio

Zen Follower

Join Date:
Apr 2008
Posts:
447
Plugin Contributions:
1

Re: Square Payment Module for Zen Cart [Support Thread]

dbltoe:

Anyone had a go with the addition of Apple Pay? https://medium.com/square-corner-blo...s-1f85cb6fe433

It appears that the two javascript files used are combined into jscript_square.php file. My attempt at adding the required info resulted in messing up the form.

I changed jscript_square.php to```
<?php/**

  • Javascript to prep functionality for Square payment module
  • @package square
  • @copyright Copyright 2003-2017 Zen Cart Development Team
  • @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  • @version $Id: Author: Chris Brown [email protected] New in v1.5.6 $
    */
    if (!defined(MODULE_PAYMENT_SQUARE_STATUS) || MODULE_PAYMENT_SQUARE_STATUS != 'True' || (!defined('MODULE_PAYMENT_SQUARE_APPLICATION_ID') || MODULE_PAYMENT_SQUARE_ACCESS_TOKEN == '')) {
    return false;
    }
    ?>
<script type="text/javascript" src="https://js.squareup.com/v2/paymentform"></script> <script type="text/javascript"> var cardNonce; var paymentForm = new SqPaymentForm({ // locationId: locationId // applicationId: '<?php echo MODULE_PAYMENT_SQUARE_APPLICATION_ID; ?>', inputClass: 'paymentInput', inputStyles: [ { fontSize: '14px', padding: '7px 12px', backgroundColor: "white" } ], cardNumber: { elementId: 'square_cc-number', placeholder: '•••• •••• •••• ••••' }, cvv: { elementId: 'square_cc-cvv', placeholder: 'CVV' }, expirationDate: { elementId: 'square_cc-expires', placeholder: 'MM/YY' }, postalCode: { elementId: 'square_cc-postcode', placeholder: '11111' }, callbacks: { cardNonceResponseReceived: function (errors, nonce, cardData) { if (errors) { console.error("Encountered errors:"); var error_html = "" errors.forEach(function (error) { console.error(' ' + error.message); error_html += "<li> " + error.message + " </li>"; }); document.getElementById('card-errors').innerHTML = '<ul>' + error_html + '</ul>'; $('#paymentSubmitButton').disabled = false; } else { // success $('#paymentSubmitButton').disabled = true; $("#card-errors").empty() document.getElementById('card-nonce').value = nonce; document.getElementById('card-type').value = cardData.card_brand; document.getElementById('card-four').value = cardData.last_4; document.getElementById('card-exp').value = ('0'+cardData.exp_month.toString()).substr(-2) + cardData.exp_year.toString().substr(-2); document.getElementsByName('checkout_payment')[0].submit(); } }, unsupportedBrowserDetected: function () { document.getElementById('card-errors').innerHTML = '<p class="error alert">This browser is not supported for Square Payments. Please contact us to let us know! Meanwhile, please pay using an alternate method; or shop using a different browser such as FireFox or Chrome.</p>'; paymentForm.destroy(); }, inputEventReceived: function (inputEvent) { switch (inputEvent.eventType) { case 'focusClassAdded': methodSelect('pmt-square'); break; case 'cardBrandChanged': document.getElementById('sq-card-brand').innerHTML = inputEvent.cardBrand; break; } }, methodsSupported: function (methods) { if (methods.applePay === true) { // Show apple pay button var element = document.getElementById('sq-apple-pay'); element.style.display = 'inline-block'; } } paymentFormLoaded: function () { paymentForm.setPostalCode('<?php echo $order->billing['postcode']; ?>'); } } }); createPaymentRequest: function () { return { requestShippingAddress: true, currencyCode: "USD", countryCode: "US", total: { label: "{{ MERCHANT NAME }}", amount: "100.00", pending: false, }, lineItems: [ { label: "Subtotal", amount: "80.00", pending: false, }, { label: "Shipping", amount: "0.00", pending: true, }, { label: "Tax", amount: "10.00", pending: false, } ] }; }; // ... $(function () { $.ajaxSetup({ headers: {"X-CSRFToken": "<?php echo $_SESSION['securityToken']; ?>"} }); $('form[name="checkout_payment"]').submit(function(e) { if($('#pmt-square').is(':checked') || this['payment'].value == 'square' || document.getElementById('pmt-square').checked == true) { e.preventDefault(); paymentForm.requestCardNonce(); } }); }); </script> <style> .paymentInput {display:inline;font-size:1em;margin:0 0.1em 10px 0;height:35px;padding-left:5px;width:50%;} .paymentInput {background-color: white;border:3px solid #ccc;} .paymentInput--error {color: red; border-color: red;} </style>

[COLOR=#3E3E3E]


Has anyone being able to figure out the Apple Pay? I've tried similar approaches as this with no good results. :( :no:
15 Nov 2018, 4:22 AM
#224
spikenzie avatar

spikenzie

New Zenner

Join Date:
Nov 2018
Location:
Montreal
Posts:
6
Plugin Contributions:
0

Re: Square Payment Module for Zen Cart [Support Thread]

My set-up:
ZC 1.5.5f
PHP 7.1.23
mySQL 5.5.60
Template: BusinessSet_res Black for ZC 1.5.5
Plugins: Sales report 3.2.0, Group price per item 155, InstantSearch 1.0.2, CEON URI Mapping 4.5.5 and Optional payment method 1.2

We are running a web store from Canada. We have our default currency set to USD and allow customers to check out in USD, CAD and Euro. Works great with PayPal and payments go into the same respective currency in PayPal.

Since we where doing upgrades we decided to add Square Payments. Our Square account is in CAD (this is Square's rule - since our business is located in Canada). The installation went smoothly, Square payments show up at checkout, all looks good.

When we checkout using Square and the order total is in USD the amount captured by Square is correct (as seen both in the Square dashboard and on the Admin Orders details page). That is, the order total in USD times the exchange rate into CAD. Eg. rate is 1:1.3, sale for a $1.00 USD order gets captured by Square as $1.30 CAD.

Problem: But if the checkout is done in CAD the amount captured by Square is wrong. It only captures the value amount in USD but in CAD. Eg. customers checks out with a product priced in the admin at $1.00 USD but they have their log in currency set to CAD, so they see it as $1.30 CAD, OK so far. At check out, Square then captures the sale as $1.00 CAD. Essentially shorting us by 30% (the current exchange rate) rather then just capturing the $1.30 CAD displayed to the customer and matching the currency used by Square. Afterwords, when logged in as a customers (or admin side) the order details, amounts and currencies display correctly, just not the amount captured by Square (as seen both in the Square dashboard and on the Admin Orders details page).

There is one warning created in the log file: Illegal string offset 'id' in /homepage/.…./Store/includes/modules/payments/square.php on line 143

Update: For a test I installed a fresh 1.5.5f with only Square Payment 0.94 and a fresh database with only example products no other plug-in or mods and I get the same results (but without the log warning).

Any ideas?

15 Nov 2018, 4:45 AM
#226
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Square Payment Module for Zen Cart [Support Thread]

Spikenzie:

We are running a web store from Canada. We have our default currency set to USD ...

Our Square account is in CAD (this is Square's rule - since our business is located in Canada).

Right now the module can handle currency conversions based on when the Square account's currency is different from the customer's checkout currency.

But it doesn't also consider that your store's "default" currency (upon which all your pricing is based) is different from the Square account's currency.

I'll try to work out that logic this week and post back. Hmmmm....

17 Nov 2018, 1:48 AM
#227
spikenzie avatar

spikenzie

New Zenner

Join Date:
Nov 2018
Location:
Montreal
Posts:
6
Plugin Contributions:
0

Re: Square Payment Module for Zen Cart [Support Thread]

Thanks DrByte, that would be great.

An update on the log file warning,

There is one warning created in the log file: Illegal string offset 'id' in /homepage/.…./Store/includes/modules/payments/square.php on line 143

This was because I had the Square Payments Payment Zone set to Canada but in my Zone Definitions for Canada I had no sub-zones (provinces) set.

17 Nov 2018, 9:22 PM
#228
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Square Payment Module for Zen Cart [Support Thread]

Spikenzie:

We are running a web store from Canada. We have our default currency set to USD ...

Our Square account is in CAD (this is Square's rule - since our business is located in Canada).

I'm between afternoon events right now so have limited time to test, but I'm wondering if making the following edit may solve the issue for you?

Line 274 of /includes/modules/payments/square.php
change:
if ($order->info['currency'] != $location->currency) {
to
if ($order->info['currency'] != $location->currency || $order->info['currency'] != DEFAULT_CURRENCY) {

Does that sort it out for all the combinations you posted about?

19 Nov 2018, 2:15 AM
#229
spikenzie avatar

spikenzie

New Zenner

Join Date:
Nov 2018
Location:
Montreal
Posts:
6
Plugin Contributions:
0

Re: Square Payment Module for Zen Cart [Support Thread]

Yes, all the captured amounts are now correct. Yay, thanks!

A side effect of this change that I noticed, but is no a big deal, on the admin side (and the note sent to Square) all transactions now say "Converted from: n.nn CAD" or "Converted from: n.nn USD" even when no conversion "math" is required (eg. CAD -> CAD).

19 Nov 2018, 3:44 AM
#230
spikenzie avatar

spikenzie

New Zenner

Join Date:
Nov 2018
Location:
Montreal
Posts:
6
Plugin Contributions:
0

Re: Square Payment Module for Zen Cart [Support Thread]

My mistake, log files warnings are still being generated but not when the sale transaction happens but rather when an order is opened "edited" in the admin side.

If an order is opened to look at and then you navigate elsewhere one error log file is created (action=edit). If you open an order update it status then three error log files are created (one with action=edit, then action=update_order and finally another action=edit).

Here are the two types of log warnings in full;

[18-Nov-2018 22:13:36 America/New_York] Request URI: /testadmin/orders.php?page=1&oID=8&action=edit, IP address: xxx.xxx.xxx.xxx
#1 square->update_status() called at [/yadayada/myTestSite/includes/modules/payment/square.php:130]
#2 square->__construct() called at [/yadayada/myTestSite/testadmin/orders.php:441]

[18-Nov-2018 22:13:36 America/New_York] PHP Warning: Illegal string offset 'id' in /yadayada/myTestSite/includes/modules/payment/square.php on line 143

and

[18-Nov-2018 22:13:36 America/New_York] Request URI: /testadmin/orders.php?page=1&oID=8&action=update_order, IP address: xxx.xxx.xxx.xxx
#1 square->update_status() called at [/yadayada/myTestSite/includes/modules/payment/square.php:130]
#2 square->__construct() called at [/yadayada/myTestSite/testadmin/orders.php:194]

[18-Nov-2018 22:13:36 America/New_York] PHP Warning: Illegal string offset 'id' in /yadayada/myTestSite/includes/modules/payment/square.php on line 143

Everything seems to be working, but at this rate the logs folder will get pretty full.

Any ideas on how to tame the warnings?

20 Nov 2018, 5:36 PM
#231
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Square Payment Module for Zen Cart [Support Thread]

To get rid of that 'id' error, a temporary fix is this ...

In that file, on line 140 you'll see the first line below. Add the second line:

        if (!isset($order->billing['country'])) return;
[B]        if (!isset($order->billing['country']['id'])) return;[/B]

I may use a different approach in the future, but for now that should suffice.

20 Nov 2018, 5:46 PM
#232
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Square Payment Module for Zen Cart [Support Thread]

Spikenzie:

Yes, all the captured amounts are now correct. Yay, thanks!

A side effect of this change that I noticed, but is no a big deal, on the admin side (and the note sent to Square) all transactions now say "Converted from: n.nn CAD" or "Converted from: n.nn USD" even when no conversion "math" is required (eg. CAD -> CAD).

Okay, looking again around line 274, let's test one more change, to get rid of the CAD->CAD message.
Add the extra condition, as shown, including the { } braces:

       // force conversion to Square Account's currency:
        if ($order->info['currency'] != $location->currency || $order->info['currency'] != DEFAULT_CURRENCY) {
            global $currencies;
            $payment_amount = round($order->info['total'] * $currencies->get_value($location->currency), 2);
            $currency_code  = $location->currency;
[B]            if ($order->info['currency'] != $location->currency) {[/B]
                $this->currency_comment = '(Converted from: ' . round($order->info['total'] * $order->info['currency_value'], 2) . ' ' . $order->info['currency'] . ')';
[B]            }[/B]
            // @TODO - if Square adds support for transmission of tax and shipping amounts, these may need recalculation here too
        }
 

While you're at it, do you mind testing another optimization I'd like to use. Does this still give the same converted price correctly for the actual payment collected?

        // force conversion to Square Account's currency:
        if ($order->info['currency'] != $location->currency || $order->info['currency'] != DEFAULT_CURRENCY) {
            global $currencies;
            $payment_amount = $currencies->rateAdjusted($order->info['total'], true, $location->currency);
            $currency_code  = $location->currency;
            if ($order->info['currency'] != $location->currency) {
                $this->currency_comment = '(Converted from: ' . round($order->info['total'] * $order->info['currency_value'], 2) . ' ' . $order->info['currency'] . ')';
            }
            // @TODO - if Square adds support for transmission of tax and shipping amounts, these may need recalculation here too
        }
21 Nov 2018, 2:11 AM
#233
spikenzie avatar

spikenzie

New Zenner

Join Date:
Nov 2018
Location:
Montreal
Posts:
6
Plugin Contributions:
0

Re: Square Payment Module for Zen Cart [Support Thread]

Hey DrByte, all of your suggestions worked!

To get rid of that 'id' error, a temporary fix is this ...
No more id log warnings,

Okay, looking again around line 274, let's test one more change, to get rid of the CAD->CAD message.
"Converted from:" text appears at correct time
and

...do you mind testing another optimization...
the optimization you wanted me to test still calculates the correct converted amounts (or not converted amounts when that is the case) Note: my tests were under $5.00
Thanks!

21 Nov 2018, 4:38 AM
#234
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Square Payment Module for Zen Cart [Support Thread]

Great! I've posted a new v0.95 version of the module, including these fixes.

27 Nov 2018, 6:00 PM
#235
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,763
Plugin Contributions:
9

Re: Square Payment Module for Zen Cart [Support Thread]

All of a sudden, Square is bouncing with INVALID_ENUM_VALUE with the detail - "is not a valid enum value for 'billing_address.country' "

Is this something 0.95 might fix or do we need to come up with a country field to satisfy a new requirement.

[27-Nov-2018 17:04:48 UTC] Request URI: /index.php?main_page=checkout_process, IP address: 72.190.125.38
#1 trigger_error() called at [/home/spicdavi/public_html/includes/modules/payment/square.php:338]
#2 square->before_process() called at [/home/spicdavi/public_html/includes/classes/payment.php:245]
#3 payment->before_process() called at [/home/spicdavi/public_html/includes/modules/checkout_process.php:84]
#4 require(/home/spicdavi/public_html/includes/modules/checkout_process.php) called at [/home/spicdavi/public_html/includes/modules/pages/checkout_process/header_php.php:14]
#5 require(/home/spicdavi/public_html/includes/modules/pages/checkout_process/header_php.php) called at [/home/spicdavi/public_html/index.php:36]

[27-Nov-2018 17:04:48 UTC] PHP Notice: Square Connect [configuration] error.
Response Body:
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[category] => INVALID_REQUEST_ERROR
```
=> INVALID_ENUM_VALUE

[detail] => `` is not a valid enum value for `billing_address.country`.
[field] => billing_address.country
)

)

)

Response Headers:
Array
(
[0] => HTTP/1.1 400 Bad Request
[Content-Type] => application/json
[Vary] => Origin, Accept-Encoding
[X-Content-Type-Options] => nosniff
[X-Download-Options] => noopen
[X-Frame-Options] => SAMEORIGIN
[X-Permitted-Cross-Domain-Policies] => none
[X-Xss-Protection] => 1; mode=block
[Date] => Tue, 27 Nov 2018 17:04:47 GMT
[keep-alive] => timeout=60
[Strict-Transport-Security] => max-age=631152000
[content-length] => 182
)
in /home/spicdavi/public_html/includes/modules/payment/square.php on line 338
27 Nov 2018, 6:31 PM
#236
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,763
Plugin Contributions:
9

Re: Square Payment Module for Zen Cart [Support Thread]

More info to the above. Both transaction attempts were American Express with Free Shipping. Both were finally successful in ordering, but neither has responded to requests for what difficulties they had when ordering.

30 Nov 2018, 3:59 AM
#237
spikenzie avatar

spikenzie

New Zenner

Join Date:
Nov 2018
Location:
Montreal
Posts:
6
Plugin Contributions:
0

Re: Square Payment Module for Zen Cart [Support Thread]

I have found a potential store user problem with this plug-in. It is not so much a bug but rather an issue that could cause financial problems for shop owners and unsatisfied customers.

This is the scenario, you let customers shop in multiple currencies but Square only takes payments in the currency in the country that the shop is based. We are in Canada but our store is set to a default currency of USD. If a Canadian customer checks out and their cart is set to USD their CC will be billed in CAD at about 30% more then their cart total. There is no warning from Square (or rather this plug-in) that they are going to do a currency conversion. See the potential problem?

I've been trying for a long time to create something I'm calling a clarity message that would appear at check-out, something like;

Square checkout only processes payments in (your square's currency), your order total is (your order total in some other currency), your CC will be billed (your order currency converted to your square's currency).

I had it working and nice looking from the user side; it would show the clear we will be charging your CC something else (if that was the case) or a generic "Secure check out with Square Payments" type message if no conversion was required.

I did this by using simon1066's post #126 to add an image, where he wrote:

Here's one way to add an image:

,and the logic from DrByte's post # 232 where he wrote

if ($order->info['currency'] != $location->currency) {

Problems where two fold, where I needed to insert the "if" logic into the code to get the payment title it caused errors on the admin side in modules payments menu and in places other than checkout the message would appear sort of like "your payment will be (nothing printed here) $."

I now have a static work around without amounts that look like this;

Attachment 18145

but, it does not appear correctly on the admin / customer orders pages or the order confirmation emailed to users. And, I don't think the message without amounts it is clear enough for some people.

Any ideas?

30 Nov 2018, 8:19 PM
#238
haredo avatar

haredo

Totally Zenned

Join Date:
Apr 2006
Location:
Texas
Posts:
6,176
Plugin Contributions:
0

Re: Square Payment Module for Zen Cart [Support Thread]

Fresh install 155f
PHP: 7.1.24
Square Payment Module 0.95
One Page Checkout (OPC) 2.0.5

Dr. Bytes,
OPC turned on
Category set up as Document - General called Printable Brochure
Product enabled under it called Document - Product which I have the pdf & zip of the brochure to download
When clicking confirm to order** when logged in **to download pdf/zip the cursor just spins and does not complete the order
Also using guest check out the cursor just spin and does not complete the order

OPC turned off
I can successfully purchase the downloadable brochure pdf/zip sucessfully.

This is the error console below.

[Attachment no longer available]

1 Dec 2018, 12:09 PM
#239
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Square Payment Module for Zen Cart [Support Thread]

Note that the jQuery issue that @haredo describes occurs when the cart contains only unpriced items, e.g. the demo product A Free Product - All (index.php?main_page=product_info&cPath=24&products_id=57), i.e. the payment method for the order is set to FreeOrder/freecharger.

This is similar in nature to the issue that was previously corrected when PayPal Express Checkout/Shortcut-Button was selected.

1 Dec 2018, 7:49 PM
#240
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Square Payment Module for Zen Cart [Support Thread]

FWIW, I was able to correct the integration issue by editing the /includes/modules/pages/checkout_payment/jscript_square.php (it's also copied to the /checkout_one/jscript_square.php for the OPC integration) and changing:

if ($payment_modules->in_special_checkout()) {
    return false;
}

to

if ($payment_modules->in_special_checkout()[B] || (isset($payment_modules->paymentClass) && $payment_modules->paymentClass->code != 'square')[/B]) {
    return false;
}

The result is that Square's jQuery module doesn't load if the payment class is selected and it's not Square.