I have my own webserver with an online store. Square has buy it now buttons which are good for a single purchase. But, what if a buyer wants to buy multiple items? In PayPal, one would create a form with the contents of the shopping cart. The PayPay example of unencrypted HTML code looks like this:
<form action="hxxpx://xxx!paypal!com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="[email protected]"> <input type="hidden" name="item_name_1" value="Item Name 1"> <input type="hidden" name="amount_1" value="1.00"> <input type="hidden" name="shipping_1" value="1.75"> <input type="hidden" name="item_name_2" value="Item Name 2"> <input type="hidden" name="amount_2" value="2.00"> <input type="hidden" name="shipping_2" value="2.50"> <input type="submit" value="PayPal"> </form>
What is the example in Square?
Thanks.
Hi @UniDaisy. Square has API/Developer documentation that probably answers your questions. Here is the link to the Square API, which seems like the best starting point. Hopefully that helps.
@UniDaisy Here’s another link to the Square Developer Platform.
I looked at the API documentation which lead me to Github. I am a PHP user and found checkout.php as a possible solution. (https://github.com/square/connect-api-examples/blob/master/connect-examples/v2/php_checkout/checkout...) Since the checkout will be generated by the back end instead of the client, it looks very promising. I have not tried it yet. In the code it says:
// Note this line needs to change if you don't use Composer:
// require('square-php-sdk/autoload.php');
require 'vendor/autoload.php';
use Dotenv\Dotenv;
use Square\Models\CreateOrderRequest;
use Square\Models\CreateCheckoutRequest;
use Square\Models\Order;
use Square\Models\OrderLineItem;
use Square\Models\Money;
use Square\Exceptions\ApiException;
use Square\SquareClient;
The autoload.php file is critical to making this work because I guess it creates several functions necessary to interface with the Square API. In the PHP quick start guide: https://developer.squareup.com/docs/sdks/php/quick-start, there is a link to composer: https://getcomposer.org/. From there autoload.php can be downloaded.
Back to the code in checkout.php...
$create_order_request = new CreateOrderRequest();
$create_order_request->setOrder($order);
That code is the magic that makes it work. The very simple example takes 2 items (A & B) and creates $order. My plan is to query my shopping cart database for the customer's order and output the results into an array ($order[]).
That's my plan among other things. Hope it works.
Thanks.
Square Community
Square Products