HELP: SCA - migrating SQPaymentForm to Web Payments SDK - PHP

Looking at a failed payment in your API Logs it didn’t include a verification_token and that is why the payment failed.

You’ll need to modify your integration to call verifyBuyer with the token generated from the form and the buyer details. Once you have that token you can pass both the source_id and the verification_token in the payment request. :slightly_smiling_face:

how is it that SQUARE is no help on these matters. They wrote the code and can’t help make it work? I watched this thread and am still pulling my hair out trying to switch over to the V2. You mentioned how smooth the old version was to work with - agreed. This is busted stuff

[quote="you’ll need to modify…
[/quote]

can you provide an example please. I did the same thing…failed efforts directly from your SDK’s. So the SDK’s are incorrectly written? Can we get a good SDK that works?

We don’t have a PHP example of this however our Node example has an example of an SCA charge. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face:

thank you. I am limited on languages. PHP is the bomb for me

All the client side interaction is in JS regardless of what your backend. :slightly_smiling_face:

@jgdorado - how far have you got - I finally have my PHP solution functioning - it is merely and auth & capture with SCA (I don’t need to store customers, etc), but it’s working, and I have PHP server side providing a receipt view and sending a confirmation email to the owner (me)

If you need something similar, I may be able to give some code pointers?

Ben

@benjamieson I appreciate the offer. I do have an issue and I believe only someone like yourself can help. I am truly frustrated with square. I only need to charge the card, then process some forms (my own) and email those to us (for order processing) along with email confirmation and receipt to the customer. Should be easy enough but this new version fails to give me back control

So I’ve been using SQPaymentForm for years and integration was a cakewalk. The Web Payments SDk is not. I don’t code for a living I code as needed. I like PHP. So here’s where I’ve gotten so far and I’m stuck . I have been able to get the square/index.php to work with a correct charge amount. Using the sandbox it does charge the correct amount - so that works but that’s where I get stuck. Nothing I’ve done takes control back from the results. It ends there. It ignores all the code to continue the process. I’ve added code to the end of the ‘process_payment.php’ = ignored. I’ve found nowhere that SQUARE has written a place to for me to advance the process like ‘include’ or additional code… very weird and frustrating. Almost like they didn’t test this for themselves cause it doesn’t work

I appreciate any help or pointer as to where I can take control and continue to process the order (THX in advance - Jim)

As a foot note or question - maybe you know…, why wouldn’t ‘include’ the square/index.php work? It doesn’t - the process fails if I use ‘include’. I found only an onclick button transfer to operate their index.php works. I’ve not experienced that before

OK, I’m doing pretty much the same thing.

Sadly, nost in in Javascript, but if you have the actual payment part working, here’s what I did.

in the paymnet_flow.js file, at the bottom, I added an extra bit, whereby if all is good with the payment itself (which is in it’s own nested form) the following:

if (data.errors && data.errors.length > 0) {
      if (data.errors[0].detail) {
        window.showError(data.errors[0].detail);
        
		document.getElementById('card-button').disabled = false;
      } else {
        window.showError('Payment Failed. Please reload this page and try again.');
      }
    } else {
    	document.forms['theForm'].submit();
		
    }
  } catch (error) {
    console.error('Error:', error);
  }
}

The key part is:

document.forms['theForm'].submit();

as this submits the wrapper form (my actual form) which is set to my ‘extra_stuff_to_do.php’ page.

I already have, in that proper form (the one you and I know as it’s PHP) the amount, client info, order ID, etc

This means in my ‘extra_stuff_to_do.php’ I can process this, update a database, send an email, etc.

It’s a mess of a setup, but this new payment flow things is just plain bad all round.

My solution worked though! Which is basically all that mattered!

the php I’ve been trying from their SDK has a square/index.php (creates card to charge form) and it goes to the payment_process_php which does the charge and displays the result ‘payment successful’ . It’s crazy that no code I write from there will take control. I’m lost. Here’s the code from the end of payment_process.php. Logically I wait for the result so I’ve tried code after but it’s dead…Maybe you have an idea I hope. 4 days and Square has no idea yet either (and they wrote this)

try {
$create_payment_request = new CreatePaymentRequest($token, Uuid::uuid4(), $money);

$response = $payments_api->createPayment($create_payment_request);

if ($response->isSuccess()) {
echo json_encode($response->getResult());
} else {
echo json_encode(array(‘errors’ => $response->getErrors()));
}
} catch (ApiException $e) {
echo json_encode(array(‘errors’ => $e));
}

I’ve tried code after and in the middle but nothing gives it back to me it remains a dead page

a little more detail…

the square/index.php can’t be “included” it fails to load. I had to use a button. otherwise I think my code would or could just continue but I lose control after the button (check-out button)

Can ya give me an email address I can get you on? Late here, so will be tomorrow - send me a message here with a way to contact you outside of here.

We got this!!

Square owes you. I’m a day away from switching to Stripe

[email protected]

thank you so much Ben, I really appreciate your offer and help

Ben, we have been having similar challenges trying to migrate to the Web Payments SDK.

We are willing to pay you or anyone to help us in our migration only using Square PHP card template. We are also considering going to Stripe if the integration does not work in the next several days. We have been with Square for years, but to get little to no assistance in completing the migration task. My e-mail address is [email protected]. We can use Zoom or Google Meet.

Again, we will pay.

Thank you and have a blessed week!

Hi Ben, over a year on and the documentation still has not been updated, many of us are still unable to get this working, could you please share your copy of card-payment.html and process_payment.php
I am loosing hair over this :frowning:

What problems are you running into? :slightly_smiling_face:

sod’s law, I just got my first 200 in the api :slight_smile:
Though I must add that you guys really need to update your examples, people’s original process-payment.php needs to have variable names changed ($token = $data->token now needs to be $token = $data->sourceId), the advice needed is scattered over many pages and people’s posts/rants for help.
I have been a programmer for 40 years and even I found it a challenge to say the least.
I will be posting my own instructions to share once I clean up and close the many tabs open

Was this our PHP example out of the box that didn’t work or were you adding to one of our examples? :slightly_smiling_face:

Yes. Your own examples.

When I worked on my own solution, and clearly the issues remain, your PHP examples are utter junk, missing large amounts of critical steps, along with sloppy code errors.

I mentioned this elsewhere (unsure if direct support, in a thread here, etc) 2 years ago. Clearly nothings been improved!!

Hey Ben, thanks for popping by, it was a combination of your posts and examining the code in the test node server that helped me pinpoint the issues with connecting to the php side of things, there needs to be a complete php example in one place as this is what square documentation is lacking, updates to the code were made whch broke the links between the two client and server files.
If anyone needs a working example just drop me a message and I will pop one over to you.
I have already sent a copy over to two people today to help out :grin:

@Square, with regards to your php example, your card-payment.html taken from the test quickstart is almost correct to work with php (apart from the post URL), but the process-payment.php needed much modification.

1 Like