Create the POST-message according to the API reference. The example code is populated with example data for a test order.

$postData holds the array that you’ll send to Hygglig. In the array you must have the following:

  • Merchant key = Your key
  • Checksum = SHA1(totalamount of cart and secret key)
  • Articles = Your cart items
  • Prices are including VAT multiplied with 100
  • Quantity should be multiplied with 100
  • Total amount is: (Price of items * 100) * (Quantity of items * 100)
// POST-message
$startCheckoutAPIAddress ="http://sandbox.hygglig.com/Checkout/api/Checkout/StartCheckout";
$totalAmount = 6000000;
$startCheckoutCheckSum = (SHA1($totalAmount . $secret));
$postData = array(
   'MerchantKey' => $key,
   'Checksum' => $startCheckoutCheckSum,
   'SuccessURL' => 'http://yourwebshopaddress.com/urlToSuccess',
   'CheckoutURL' => 'http://yourwebshopaddress.com/urlToCheckout',
   'OrderReference' => '123456',
   'TermsURL' => 'http://yourwebshopaddress.com/urlToTerms',
   'Email' => 'testperson@hygglig.com',
   'Postcode' => '10000',
   'PushNotificationURL' => 'http://yourwebshopaddress.com/urlToPush',
   'Currency' => 'SEK',
   'Articles' => array(
      array(
         'ArticleName' => 'Hygglig Artikel',
         'ArticleNumber'=>'1',
         'Description'=>'En fantastisk artikel från Hygglig',
         'Price'=>'15000',
         'Quantity'=>'300',
         'VAT'=>'2500'
      ),
      array(
         'ArticleName' => 'Frakt',
         'ArticleNumber'=>'999',
         'Description'=>'Fraktsätt: Hyggligt',
         'Price'=>'15000',
         'Quantity'=>'100',
         'VAT'=>'2500',
      ),
   )
);

Optimize the checkout for returning customers

When you render the checkout iframe you may add data about the consumer;
Email and Postcode.

We at Hygglig recommend using this feature for consumers who log into an account on your page where you already have stored data about the consumer. If you choose to add consumer data, the consumer will not need to re-enter the data into the checkout, and your conversion will increase.

If optional data is sent, the consumer will reach the checkout in the last state, presented with a “one click purchase” possibility.

Receive the answer from Hygglig

Receive and validate the response from Hygglig:

  • A successfull request for iFrame will grant you a Token value.
  • Any unsuccessfull atempts will give you an error code and error description in return.

Note: If a checkout session already exists, you should use the already configured order in that session instead of creating a new checkout session. This will provide a better user experience.

if(responseValidation($response) === FALSE){
//Print response code
echo "Error type: " . $response['Error']['Description'];
echo "Error number: " . $response['Error']['Code']; }
else{
//Continue to req of iframe }

Get the Checkout iFrame

Now get the iFrame.

//GetIFrame
$getiframeCheckSum = SHA1(strtoupper($token.$secret));
$getiframeAPIAddress = "http://sandbox.hygglig.com/Checkout/api/Checkout/GetIFrame";
$postData = array(
'MerchantKey' => $key,
'Checksum' => $getiframeCheckSum,
'Token' => $token, );

Render the checkout

Echo out the HtmlText to display the Hygglig Checkout.

//Validate response and then display HTML
$text = $response["HtmlText"];
echo $text;

Use our demo shop to get an idea of how it can look

Go ahead – add a product and go to checkout