Create a quick pay form

I am trying to take a payment in a web page. I do not not need anything except the payment, I think this is a “quick pay”. I know a description, price and the customer. About 3 years ago on another project I achieved this but the API has changed and the code I preciously used does not work.

The effect I want is write a web page and in the middle write a payment form. If I wrote the API the code would look like:

@WebServlet(urlPatterns = { "/square/pay/" })
public class ServletSquare
	extends HttpServlet
{	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		PrintWriter out = response.getWriter();

		out.print("<!DOCTYPE html><html><head><title>Square pay example</title></head><body>");
		out.print("<p>Order number: 12345</p>");
		out.print("<p>Desription: the prodeuct</p>");
		out.print("<p>Amount: 99.00</p>");
		out.print("<p>Please pay...</p>");

		SquareClient squareClient = SquareClient
			.builder()
				.token("SQUAYRETOKEN")
				.environment(Environment.SANDBOX)	// or PRODUCTION
			)
			.build();

		// pseudo code follows... create a payment request and write to the page
		Payment payment = squareClient.payment().create(
			...add customer, product description, amount, redirectUrl
		);

		out.print(paymentRequest.phetPayemntForm());			// write the form

		out.print("</body></html>");
	}
}

I am missing the one-liner: out.print(paymentform);

The form action should call the webhooks to update the payment status.

I can create a payment link but this takes the customer to the square site, maybe not a bad thing but not what I want nor the embedded form I have used.

The developer.square.com/explorer/… is useful but incomplete. It does not show how to extract values; the javadoc is needed to decode the methods needed. I can create the square data objects and make requests of square but It does not help write a payment form.

In the previous project that no longer works I added a dummy form that was enabled by 6 boatloads of script. The form was:

<form class="payment-form" id="fast-checkout">"
<div class="wrapper">");
<div id="card-container"></div>");
<button id="card-button" type="button">Pay with Card</button>");
<span id="payment-flow-message"></span>");
</div>");
</form>");

Similar to

<useful link redacted to avoid 422 error>

which with the correct applicationid and correct locationid (cut and paste from my working server that is accessing the square back-end) reports "applicationid and/or locationid is incorrect.

It is a silly method as the it runs client side (or not when the browser is updated) and the applicationid and locationid is put in the client’s script with no security. The script had no version and unsurprisingly failed after time. Using 0.5MByte of script is the product being paid for volume not quality.

Please provide or refer me to any simple quick pay form example that works.

The Square Payment Form (SqPaymentForm) has been retired. You’ll want to switch to the Web Payments SDK, the current replacement that supports cards, digital wallets (Apple Pay/Google Pay), ACH, and gift cards.

Useful links:

Hello,
To address your security concern directly: Square’s architecture requires a split between the client side and the server side. 1. The Client Side (JavaScript) renders a secure, isolated credit card input (via iframes hosted by Square) and generates a temporary, single-use token called a source ID (or nonce). Your Application ID and Location ID are exposed to the client, but they are public identifiers and cannot be used to steal money or execute unauthorized API calls. metropcsbytmobile com
2. The Server Side (Java) takes that temporary token and your hidden, highly secure Access Token to actually execute the charge via the PaymentsApi.

Best Regards

$ echo ‘Caesar code, shift 13’ | tr ‘[a-m][n-z]’ ‘[n-z][a-m]’ | tr
‘[a-m][n-z]’ ‘[n-z][a-m]’

This did not work.

I copied the page here:

$ echo
‘uggcf://tvguho.pbz/fdhner/jro-cnlzragf-dhvpxfgneg/oybo/znva/choyvp/rknzcyrf/pneq-punetr.ugzy’

tr ‘[a-m][n-z]’ ‘[n-z][a-m]’

changing the lines:
const appId = ‘{APPLICATION_ID}’;
const locationId = ‘{LOCATION_ID}’;

to the values which work in the SDK and it reports “applicationid and/or
locationid is incorrect”

This leads to the example above. “For a complete code example of the
card payment setup, see the charge card payment file.” link as above.

This leads to the examples that are 4 years out-of-date and do not
compile with the latest API.

$ echo
‘uggcf://tvguho.pbz/fdhner/pbaarpg-ncv-rknzcyrf/gerr/znfgre/pbaarpg-rknzcyrf/i2/wnin_cnlzrag/fep/znva/wnin/pbz/fdhnerhc/pbaarpgrknzcyrf/rpbzzrepr’

How does the server get the token from the client? Does not the server
negotiates with square first then and send (writes in the page) the
token too the client.

Does it come back via the webhook?