x

How to add a shipping price to my checkout (Prebuild checkout page)

I'm currently using Checkout API, to generate my checkout page, however, i don't know how I can add a shipping row above the taxes. 

 

Here is my current page: https://connect.squareup.com/v2/checkout?c=CBESEL6qa8_ais1QFsL5b00J3hY&l=8E4Q21SQ2FHAV

 

Any help is appreciated 

Tags (1)
1,521 Views
Message 1 of 6
Report
5 REPLIES 5
Admin

Thanks for your question @CHN! While it's not possible to select shipping after items are added by your customer, you can take a look at this workaround that explains how shipping can be added. 

 

Let us know if you have other questions on this!

Bea_
Beta Community Manager, Square
Join the Beta Community
Evaluate | Influence | Engage
1,510 Views
Message 2 of 6
Report

It does not really answer, because im not using the online store. According to the documentation it need to be added through the PHP request. Does it have to be added as a product ? or ?

 

This is my current request builder:

function payment(){
    //Replace your access token and location ID
    $accessToken = '-';
    $locationId = '-';

    // Create and configure a new API client object
    $defaultApiConfig = new \SquareConnect\Configuration();
    $defaultApiConfig->setAccessToken($accessToken);
    $defaultApiConfig->setSSLVerification(FALSE);
    $defaultApiClient = new \SquareConnect\ApiClient($defaultApiConfig);
    $checkoutClient = new SquareConnect\Api\CheckoutApi($defaultApiClient);

    //Puts our line item object in an array called lineItems.
    $lineItems = array();

    foreach($_SESSION['products'] as $product){
      //Create a Money object to represent the price of the line item.
      $price = new \SquareConnect\Model\Money;
      $price->setAmount((int)str_replace(".","", $product['price']));
      $price->setCurrency('CAD');

      //Create the line item and set details
      $book = new \SquareConnect\Model\CreateOrderRequestLineItem;
      $book->setName($product['name']);
      $book->setQuantity($product['qty']);
      $book->setBasePriceMoney($price);
      array_push($lineItems, $book);
    }

    $taxItems = array();

    //GST
    $taxes = new \SquareConnect\Model\CreateOrderRequestTax();
    $taxes->setPercentage("5");
    $taxes->setName("GST");
    $taxes->setType("ADDITIVE");
    array_push($taxItems, $taxes);

    //QST
    $taxes = new \SquareConnect\Model\CreateOrderRequestTax();
    $taxes->setPercentage("9.975");
    $taxes->setName("QST");
    $taxes->setType("ADDITIVE");
    array_push($taxItems, $taxes);

    // Create an Order object using line items from above
    $order = new \SquareConnect\Model\CreateOrderRequest();
    $order->setIdempotencyKey(uniqid()); //uniqid() generates a random string.

    //sets the lineItems array in the order object and taxes
    $order->setLineItems($lineItems);
    $order->setTaxes($taxItems);

    ///Create Checkout request object.
    $checkout = new \SquareConnect\Model\CreateCheckoutRequest();

    $checkout->setIdempotencyKey(uniqid()); //uniqid() generates a random string.
    $checkout->setOrder($order); //this is the order we created in the previous step.
    $checkout->setRedirectUrl("http://www.lastpostfund.ca/EN/foh.php"); //Replace with the URL where you want to redirect your customers after transaction.


    try {
      $result = $checkoutClient->createCheckout(
        $locationId,
        $checkout
      );
      //Save the checkout ID for verifying transactions
      $checkoutId = $result->getCheckout()->getId();
      //Get the checkout URL that opens the checkout page.
      $checkoutUrl = $result->getCheckout()->getCheckoutPageUrl();
      echo urlencode($checkoutUrl);
      //header("Location: ".$checkoutUrl);
    } catch (Exception $e) {
        $_SESSION['error'] = 'Exception when calling CheckoutApi->createCheckout: '.$e->getMessage();
    }
  }

 

1,504 Views
Message 3 of 6
Report
Admin

Hi again@CHN, sorry for the delay! I checked in with an API specialist for you and to charge for shipping you would need to add it as a line item. 

️ Helen
Seller Community Manager

Did you find help in the Seller Community? Mark a Best Answer to help others.
1,479 Views
Message 4 of 6
Report

The problem is that there will be a '1X' for the quantity in front of the line item. Is there anyway to remove it or at least of hide it ?

1,471 Views
Message 5 of 6
Report
Admin

@CHN

 

There is no way to make that 1X quantity go away at this time.

kellyj
Technical Program Manager: AI
Square Inc
1,453 Views
Message 6 of 6
Report