If this is your first visit, check our documentation. To post, register or login.
Forums / Community Contributed Add-Ons / Addon Payment Modules / Square WebPay support thread.

Square WebPay support thread.

Started by carlwhat on 6 Apr 2022, 6:02 PM · Views: 129,956

Results 801 to 808 of 808
11 Sep 2026, 2:43 AM
#801
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
862
Plugin Contributions:
0

Square WebPay support thread.

Hey Carl,
I'm running ZC 2.2.2 on PHP 8.5. I have a square account that I haven't used in quite some time. Just went through new verification there and account looks good. I'm wondering firstly (looks like it does) does your plugin work with my configuration? Secondly, do I need to make any changes to my square account to accept google and apple pay using your plugin?

Also, is it encapsulated? If not, does it touch any core files?

Thank you,

John

11 Sep 2026, 4:57 AM
#802
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Re: Square WebPay support thread.

bumba000:

Hey Carl,
I'm running ZC 2.2.2 on PHP 8.5. I have a square account that I haven't used in quite some time. Just went through new verification there and account looks good. I'm wondering firstly (looks like it does) does your plugin work with my configuration? Secondly, do I need to make any changes to my square account to accept google and apple pay using your plugin?

Also, is it encapsulated? If not, does it touch any core files?

Thank you,

John

john,

if you are talking about my commercial square plugin for zen-cart, i just confirmed that it will work in your environment. if you are talking about the free plugin available for download here on this forum, unfortunately it will not.

with regards to google pay, no additional changes need to be made on your square account.

with regards to apple pay, there is a small change that i believe needs to get done. it is documented in the notes section on version 2.0.0. which comes with the download.

it is not encapsulated (but might be in the future), but there are no core files modified.

i do not believe that any plugin i have done over the last 7-10 years has modified any core files, so no worries on that.

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

15 Oct 2026, 9:14 PM
#804
dbltoe avatar

dbltoe

Totally Zenned

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

Re: Square WebPay support thread.

For anyone running Square WebPay 3.1.2 whose customers get stuck at checkout, these are the changes we've been running on the stores we host since August. They're edits to our own licensed copies, which the license allows. They're posted here as edits you can make to your own copy, not as replacement files.

What we saw

A Square card token can only be used once. On one store, between July 9 and August 16, three shoppers had a payment fail and then got CARD_TOKEN_USED on their next try. That error means Square received a token it had already seen. The card is fine, but the shopper has no way past the error. None of the three placed an order. Over the same period on the same store, shoppers with an ordinary decline went on to order 68.4% of the time, and shoppers with a CVV failure went on to order 79.4% of the time.

In one of the three, the CARD_TOKEN_USED came six seconds after the first decline. That's too fast for anyone to have re-typed a card.

What changed

These edits went in on August 12 on one store and August 18 on the other. Over the next six weeks, the two stores logged 83 failed payments. None of them was CARD_TOKEN_USED.

To be upfront about the limits: we can't make a live card decline on demand, so this is evidence from real shoppers' logs, not a reproduction.

The edits

Back up both files first. Line numbers are from an unmodified 3.1.2.

1. Server-side guard against a reused token

File: includes/modules/payment/square_webPay.php

Insert this immediately before $response = $this->paymentRequest('create', $body); (line 469). Nothing is removed. If the same token comes back a second time, the shopper is sent back to re-enter the card instead of hitting CARD_TOKEN_USED. Because the token is recorded before the call to Square, a resubmitted confirmation page can't charge the card twice either.

$sqUsedTokens = $_SESSION['sq_webpay_used_tokens'] ?? [];
if (!empty($this->tokenResult->token) && in_array($this->tokenResult->token, $sqUsedTokens, true)) {
    $messageStack->add_session(
        'checkout_payment',
        defined('MODULE_PAYMENT_SQ_WEBPAY_ERROR_REENTER_CARD')
            ? MODULE_PAYMENT_SQ_WEBPAY_ERROR_REENTER_CARD
            : 'For your security this card entry can only be submitted once. Please re-enter your card details and try again.',
        'error'
    );
    zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
if (!empty($this->tokenResult->token)) {
    $sqUsedTokens[] = $this->tokenResult->token;
    $_SESSION['sq_webpay_used_tokens'] = $sqUsedTokens;
}

2. Checkout script

File: includes/modules/pages/checkout_payment/jscript_square_webPay.php

One Page Checkout's copy of this script just loads this one, so this covers both checkouts.

In tokenize(), the billing contact sends the street, suburb, state, and city through JSON.stringify(), so Square receives them wrapped in quote marks ("CA" instead of CA). The country also goes out as country, but Square's docs name that field countryCode. Change lines 149, 153, 155, and 156 to:

addressLines: [squareOrderValues.orderBilling.street_address || '', squareOrderValues.orderBilling.suburb || ''],
countryCode: squareOrderValues.orderBilling.country.iso_code_2,
state: squareOrderValues.orderBilling.state || '',
city: squareOrderValues.orderBilling.city || '',

In handlePaymentMethodSubmission(), replace the try block (lines 250 to 268) so it:

  • checks the form before tokenizing, so no token is created for a form that then fails validation
  • reuses the hidden tokenResult field instead of adding another one on every click
  • keeps the button disabled until the form is submitted (the existing catch turns it back on if anything fails)
try {
    // Validate before tokenizing, so a token isn't created for a form that then fails.
    if (!document.forms["checkout_payment"].checkValidity()) {
        document.forms["checkout_payment"].reportValidity();
        return;
    }

    cardButton.disabled = true;
    const token = await tokenize(paymentMethod);

    // Reuse the hidden field rather than adding another on every attempt.
    var tokenResult = document.forms["checkout_payment"].querySelector('input[name="tokenResult"]');
    if (!tokenResult) {
        tokenResult = document.createElement("input");
        tokenResult.setAttribute("type", "hidden");
        tokenResult.setAttribute("name", "tokenResult");
        document.querySelector('[name="checkout_payment"]').appendChild(tokenResult);
    }
    tokenResult.setAttribute("value", JSON.stringify(token));

    // Stay disabled through submittal.
    document.forms["checkout_payment"].submit();
} catch (e) {

3. Tell the shopper the real reason for a decline

File: includes/modules/payment/square_webPay.php, in paymentRequest()

As shipped, a declined card goes down the exception path, so every decline is shown to the shopper as "Unable to process payment due to a communications error. You may try again or contact us for assistance." A shopper who's told the store is having trouble tends to retry the same card. Replace the single $messageStack->add_session(...) line at 516 with:

$declineShown = false;
if ($e instanceof \Square\Exceptions\SquareApiException) {
    foreach ($e->getErrors() as $sqError) {
        if (!is_object($sqError) || !method_exists($sqError, 'getCode')) {
            continue;
        }
        $messageStack->add_session('checkout_payment', MODULE_PAYMENT_SQ_WEBPAY_TEXT_ERROR . ' [' . $sqError->getCode() . '] ' . $sqError->getDetail(), 'error');
        $declineShown = true;
    }
}
if ($declineShown === false) {
    $messageStack->add_session('checkout_payment', MODULE_PAYMENT_SQ_WEBPAY_TEXT_COMM_ERROR, 'error');
}

This uses the message the module already shows on its other error path, so the shopper sees Square's code and reason, like [CVV_FAILURE]. Real connection problems still get the communications-error message.

We have a few smaller ones too: a guard against double-submitting a refund, a 12-hour clock with no AM/PM in the log headers, and keeping ordinary declines out of the store owner's error alerts. I'm happy to post those if anyone wants them.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

22 Oct 2026, 3:12 PM
#805
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
862
Plugin Contributions:
0

Re: Square WebPay support thread.

One more question regarding the square plugin by Carl (mxworks) - I'm wondering if this can be used for just the apple and google pay.

We use authorize aim for credit cards and for time being would like to keep it that way. We'd like to accept only apple and google pay using our square account.

Is there an admin setting in this plugin that will prevent the square credit card fields from showing on checkout, or would this be handled with a code modification?

Thank you,

John

22 Oct 2026, 3:53 PM
#806
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Re: Square WebPay support thread.

bumba000:

One more question regarding the square plugin by Carl (mxworks) - I'm wondering if this can be used for just the apple and google pay.

We use authorize aim for credit cards and for time being would like to keep it that way. We'd like to accept only apple and google pay using our square account.

Is there an admin setting in this plugin that will prevent the square credit card fields from showing on checkout, or would this be handled with a code modification?

Thank you,

John

john

i will not be in front of my computer until next monday.

but i do believe this is all possible from configuration switches in the admin.

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

27 Oct 2026, 1:34 PM
#807
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Re: Square WebPay support thread.

bumba000:

One more question regarding the square plugin by Carl (mxworks) - I'm wondering if this can be used for just the apple and google pay.

We use authorize aim for credit cards and for time being would like to keep it that way. We'd like to accept only apple and google pay using our square account.

Is there an admin setting in this plugin that will prevent the square credit card fields from showing on checkout, or would this be handled with a code modification?

Thank you,

John

i have confirmed this will work.

you probably will want to override one of the language definitions to something like:

'MODULE_PAYMENT_SQ_WEBPAY_TEXT_CATALOG_TITLE' => 'GooglePay / ApplePay',

i suppose one could get fancy within that file to check if one is in an apple supported environment and change the definition accordingly.

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

3 Nov 2026, 7:27 PM
#808
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,753
Plugin Contributions:
0

Re: Square WebPay support thread.

Just a reminder - We do not allow advertising paid/pro/commercial modules on the forum. We will be ramping up enforcement.

Please see: https://docs.zen-cart.com/user/zen_cart_forum/code_of_conduct/

Please do not PM for support issues: a private solution doesn't benefit the community.

Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.