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.