Create
1 min
To create a Checkout URL in Square, use the "CreateCheckoutURL" action. You need to prepare a request object and a list of line items. The request object should include the customer ID, checkout type, and whether tipping is allowed. Each line item should include the quantity, unit price, item currency, name, and note. See the Checkout URL - Square for all required fields.
Please note that you can only request one Checkout URL at a time.
This will return a response that includes the new Square Checkout URL.
The following is an example of a Checkout URL for Square.
// Create a Map to store all the data of a Customer
Map<String, Object> checkoutMap = new Map<String, Object>();
//checkoutMap.put('locationId',locationId); // if not entered, we will request to Square and fetch the main Location Id
checkoutMap.put('customerId',customerId);
checkoutMap.put('checkoutType', 'orderCheckout');
checkoutMap.put('allowTipping', true);
//Creating the line items
Map<String,Object> line_item = new Map<String,Object>();
line_item.put('quantity', '5');
line_item.put('unitPrice', '100');
line_item.put('itemCurrency', 'USD');
line_item.put('name', 'Ball');
line_item.put('note', 'To play cricket');
Map<String,Object> line_item1 = new Map<String,Object>();
line_item1.put('quantity', '1');
line_item1.put('unitPrice', '75000');
line_item1.put('itemCurrency', 'USD');
line_item1.put('name', 'Laptop');
line_item1.put('note', 'For gaming');
List<Object> line_items = new List<Object>();
line_items.add(line_item);
line_items.add(line_item1);
// Adding the line items
checkoutMap.put('lineItems', line_items);
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('checkout', new List<Object>{checkoutMap});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'CreateCheckoutURL');
reqObj.put('processorId',processorOrgId);
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = bw_payments.BreadwinnerPaymentsAPI.call(reqObj);
System.debug(resp);