How to Include Order Info

I am a newbie. I’ve been reading through the documentation and am struggling a bit. I just need some guidance or someone to point me in the right direction.

My PHP web site already has cart functionality and I’m just trying to integrate Square to pay. I have a total, including each item and its shipping cost, and the customer’s email and shipping address. After the payment has been successfully processed, I’d like to update my inventory, which is in a database on my site, send a confirmation email to the customer and send an email to myself that the payment was successfully processed and the item(s) can be shipped.

I know I need to use the Web Payments SDK and there are 2 components: the JavaScript and form in the client to collect the card info and processing the payment on the server using the Payments API.

The JavaScript on the client tokenizes the card info and that is passed to the server. Where/how is the total included? All of the examples I’ve seen have a total hard-coded in the server processing which isn’t that useful.

Can I also pass other information (i.e. the itemized breakdown and customer info) to the server processing so I can update inventory and send the 2 emails if the payment processes successfully? If yes, how? If no, what’s the best way to do post processing like that?

I’ve been reviewing connect-api-examples/connect-examples/v2/php_payment at master · square/connect-api-examples · GitHub as using that for guidance.

:waving_hand: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Common Square API Patterns
PHP SDK
In-App Payments SDK Quickstart

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

To integrate Square payments into your existing PHP website with cart functionality, you are on the right track by using the Web Payments SDK for the client-side and the Payments API for the server-side processing. Here’s a concise guide to help you proceed:

  1. Client-Side (Web Payments SDK):

    • Use the Web Payments SDK to create a payment form on your website. This form will collect the card information and tokenize it securely.
    • The SDK will generate a payment token (nonce) that you will send to your server for processing.
  2. Server-Side (Payments API):

    • On your server, use the Payments API to process the payment. The payment token from the client-side is used here.
    • You can pass the total amount, itemized breakdown, and customer information from your client-side to the server-side. This is typically done by including these details in the request payload when you send the payment token to your server.
  3. Including the Total and Additional Information:

    • Instead of hardcoding the total on the server, calculate the total on the client-side and send it along with the payment token to your server.
    • You can include additional information such as itemized breakdown and customer details in the payload sent to your server. This can be done using a JSON object or form data, depending on your implementation.
  4. Post-Processing:

    • After the payment is successfully processed, you can perform post-processing tasks such as updating your inventory, sending confirmation emails to the customer, and notifying yourself.
    • Use the response from the Payments API to confirm the payment status before proceeding with these tasks.
  5. Example and Guidance:

    • The GitHub example you are reviewing is a good starting point. It demonstrates how to handle the server-side processing using the Payments API.
    • Ensure that your server-side code securely handles the payment token and any sensitive information.

By following these steps, you can effectively integrate Square payments into your PHP website and handle post-payment processing tasks.

This answer was reviewed by @Bryan-Square.

Hello,

Thank you so much for your thoughtful message and excellent suggestions.

Best Regard,
Helen

PrepaidGiftBalance