{"__v":5,"_id":"56d016028629f91300fd9926","category":{"__v":4,"_id":"56d011e91991690b003b2a3a","pages":["56d01458a9fe510b00c6debd","56d016028629f91300fd9926","56d016d21991690b003b2a4e","56e6d20cf3b12a3200df21bf"],"project":"55a4d5531a5f991700a9409e","version":"55a4d5541a5f991700a940a1","reference":false,"createdAt":"2016-02-26T08:50:49.316Z","from_sync":false,"order":1,"slug":"click-get","title":"urb-it as click & Get"},"parentDoc":null,"project":"55a4d5531a5f991700a9409e","user":"555b35be8e87d01900b8049e","version":{"__v":15,"_id":"55a4d5541a5f991700a940a1","project":"55a4d5531a5f991700a9409e","createdAt":"2015-07-14T09:24:36.007Z","releaseDate":"2015-07-14T09:24:36.007Z","categories":["55a4d5541a5f991700a940a2","55a671d0aaf9cf1900115073","55a671e3aaf9cf1900115076","55a8dd90cf45e1390093f1e8","560268333ee4af1700047111","56027f4a930fe1170074bd77","56027f8a3ee4af170004713f","56027fd9930fe1170074bd78","5602b7654f15002100ee4487","5602b7a74f15002100ee4488","5603a674e5102a0d0070f86e","561f71204d67490d00804ad2","56d011e91991690b003b2a3a","56d438f68001e30b00896e33","572b09de4f41fc19002bfc55"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"createdAt":"2016-02-26T09:08:18.829Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"examples":{"codes":[]},"results":{"codes":[]},"settings":"56cc4a0bca43550b00281336","auth":"required","params":[],"url":"/"},"isReference":false,"order":1,"body":"[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Properties\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"h-3\": \"Description\",\n    \"0-0\": \"store_id\",\n    \"0-1\": \"guid\",\n    \"0-3\": \"Store id\",\n    \"1-0\": \"retailer_reference_id\",\n    \"1-1\": \"string\",\n    \"1-2\": \"External order or reference number\",\n    \"2-0\": \"nounce\",\n    \"2-1\": \"string\",\n    \"2-2\": \"A unique string\",\n    \"3-0\": \"currency\",\n    \"3-1\": \"string\",\n    \"3-2\": \"ISO4217 standard, Both numeric and upper case letter codes are accepted\",\n    \"4-0\": \"amount\",\n    \"4-1\": \"int\",\n    \"4-2\": \"Total price (including tax) in cents,\",\n    \"5-0\": \"return_url\",\n    \"5-1\": \"string\",\n    \"5-2\": \"The url to return to after successful transaction\",\n    \"6-0\": \"cancel_url\",\n    \"6-1\": \"string\",\n    \"6-2\": \"The url to return to in case the user cancels the checkout\",\n    \"7-0\": \"timestamp\",\n    \"7-1\": \"int\",\n    \"7-2\": \"Current Unix timestamp. This field is used only for hmac calculation.\",\n    \"8-0\": \"hmac\",\n    \"8-1\": \"string\",\n    \"8-2\": \"The signature that is used both for data integrity and authorization. Instructions how to generate the HMAC can be found [here](#hmac-signature)\",\n    \"0-2\": \"Store id provided by urb-it\"\n  },\n  \"cols\": 3,\n  \"rows\": 9\n}\n[/block]\n**Article** \n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Property\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"retailer_reference_id\",\n    \"0-1\": \"string\",\n    \"0-2\": \"Retailers article reference id (article id)\",\n    \"1-0\": \"description\",\n    \"1-1\": \"string\",\n    \"1-2\": \"Name or short description about the article\",\n    \"2-0\": \"price\",\n    \"2-1\": \"int\",\n    \"2-2\": \"Total price (including tax) in cents, multiplied by quantity\",\n    \"3-0\": \"vat_percentage\",\n    \"3-1\": \"int\",\n    \"3-2\": \"Percentage of tax rate, multiplied by 100 and provided as an integer. (ex: 2500 for 25%)\",\n    \"4-0\": \"quantity\",\n    \"4-1\": \"int\",\n    \"4-2\": \"Number of articles\"\n  },\n  \"cols\": 3,\n  \"rows\": 5\n}\n[/block]\n**Request** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"POST / HTTP/1.1\\nHost: checkout.urb-it.com\\nContent-Type: application/json\\n{\\n  \\\"retailer_reference_id\\\": \\\"ref1\\\",\\n  \\\"store_id\\\": \\\"3b8ddf21-51a0-4bf3-9c24-ed6e32c94e3e\\\",\\n  \\\"currency\\\": \\\"SEK\\\",\\n  \\\"return_url\\\": \\\"/\\\",\\n  \\\"cancel_url\\\": \\\"/\\\",\\n  \\\"error_url\\\": \\\"/\\\",\\n  \\\"timestamp\\\": 1456150457,\\n  \\\"nonce\\\": \\\"2a749ce9-0ec0-4cb8-9269-1a9feb0e6c5d\\\",\\n  \\\"amount\\\": 520000\\n  \\\"articles\\\": [\\n    {\\n      \\\"retailer_reference_id\\\": \\\"art1\\\",\\n      \\\"description\\\": \\\"Test\\\",\\n      \\\"price\\\": 520000,\\n      \\\"vat_percentage\\\": 2500,\\n      \\\"quantity\\\": 1\\n    }\\n  ],\\n  \\\"hmac\\\": \\\"6WJHos0/SxoZKIKjSwkhZd53OLEBIhf8OX7Cz/79cQk=\\\"\\n}\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\n**Response** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"HTTP/1.1 201 Created\\nContent-Type: application/json\\nLocation : https://stage-checkout.urb-it.com/c/{id}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"HMAC Signature\"\n}\n[/block]\nFollow the steps in order to create the signature\n\n1. Concatenate store key, currency, timestamp, nonce and the items separated by & character. The item field are separated by ‘:’ as you can see in the below code sample.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"sb.Append(contract.StoreId)\\n  .Append(\\\"&\\\" + contract.Currency)\\n  .Append(\\\"&\\\" + contract.Timestamp)\\n  .Append(\\\"&\\\" + contract.Nonce);\\n\\nforeach(var item in contract.Articles.OrderBy(i => i.RetailerReferenceId))\\n{\\n   sb.AppendFormat(\\\"&{0}:{0}:{0}:{0}\\\", item.RetailerReferenceId, item.VatPercentage,         item.Price, item.Quantity);\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Note\",\n  \"body\": \"The article items are sorted based on retailer reference id.\"\n}\n[/block]\n2. Sign the message\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var secretKeyByteArray = Convert.FromBase64String(sharedSecret);\\nvar hmac= String.Empty;\\nusing (var hmac = new HMACSHA256(secretKeyByteArray))\\n{\\n  byte[] signatureBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));\\n  hmac= Convert.ToBase64String(signatureBytes);\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Implementation Examples\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"StringBuilder sb = new StringBuilder();\\n\\nsb.Append(contract.StoreId)\\n  .Append(\\\"&\\\" + contract.Currency)\\n  .Append(\\\"&\\\" + contract.Timestamp)\\n  .Append(\\\"&\\\" + contract.Nonce);\\n\\nforeach(var item in contract.Articles.OrderBy(i => i.RetailerReferenceId))\\n{\\n   sb.AppendFormat(\\\"&{0}:{0}:{0}:{0}\\\", item.RetailerReferenceId, item.VatPercentage,             item.Price, item.Quantity);\\n}\\n\\nvar secretKeyByteArray = Convert.FromBase64String(sharedSecret);\\nvar hmac= String.Empty;\\nusing (var hmac = new HMACSHA256(secretKeyByteArray))\\n{\\n   byte[] signatureBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));\\n   hmac= Convert.ToBase64String(signatureBytes);\\n}\\n\\nvar request = new order()\\n{\\n    retailer_reference_id = \\\"id\\\",\\n    store_id = \\\"1234\\\",\\n    currency = \\\"SEK\\\",\\n    return_url = \\\"/\\\",\\n    cancel_url = \\\"/\\\",\\n    error_url = \\\"/\\\",\\n    timestamp = \\\"1231233\\\",\\n    nounce = \\\"3123\\\",\\n    articles = new[\\n                {\\n                    \\\"retailer_reference_id\\\": \\\"art1\\\",\\n                    \\\"description\\\": \\\"Test\\\",\\n                    \\\"price\\\": \\\"520000\\\",\\n                    \\\"vat_percentage\\\": \\\"2500\\\",\\n                    \\\"quantity\\\": \\\"1\\\"\\n                },\\n    hmac = hmac\\n};\\n\\nusing (var client = new HttpClient())\\n{\\n    var response = client.PostAsync(\\\"https://stage-checkout.urb-it.com/\\\",\\n        new StringContent(JsonConvert.SerializeObject(request).ToString(),\\n            Encoding.UTF8, \\\"application/json\\\"))\\n            .Result;\\n\\n    if (response.IsSuccessStatusCode)\\n    {\\n        var checkoutUrl = response.Headers.Location;\\n    }\\n}\",\n      \"language\": \"csharp\"\n    },\n    {\n      \"code\": \"define('URBIT_CHECKOUT_ENDPOINT', 'https://checkout.urb-it.com/');\\ndefine('URBIT_CHECKOUT_TOKEN', 'yourtoken');\\ndefine('URBIT_CHECKOUT_SECRET', 'yoursecret');\\n\\nfunction get_checkout_url($order) {\\n  $params = array(\\n    'store_id' => URBIT_CHECKOUT_TOKEN,\\n    'retailer_reference_id' => $order->get_order_number(),\\n    'currency' => 'SEK',\\n    'return_url' => 'http://example.com/order-received/'\\n    'cancel_url' => 'http://example.com/order-canceled/'\\n    'articles' => array(),\\n    'timestamp' => time(),\\n    'nonce' => md5(rand(0, 999999) . URBIT_CHECKOUT_TOKEN . microtime(true)),\\n    'amount' => 0\\n  );\\n  \\n  // Add all order articles to params array\\n  foreach($order->get_articles() as $article) {\\n    $price_in_cents = (float)$article->price_incl_vat * 100 * $article->quantity;\\n    \\n    $params['articles'][] = array(\\n      'retailer_reference_id' => $article->sku,\\n      'description' => $article->description,\\n      'price' => $price_in_cents,\\n      'vat_percentage' => $article->vat_percentage,\\n      'quantity' => $article->quantity\\n    );\\n    \\n    // Increase the order total\\n    $params['amount'] += $price_in_cents;\\n  }\\n  \\n  // Sort articles by reference ID\\n  usort($params['articles'], 'sort_articles_by_id');\\n  \\n  // Generate HMAC for authorization\\n  $params['hmac'] = get_hmac($params);\\n  \\n  $json = json_encode($params);\\n  $ch = curl_init($url);\\n  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, \\\"POST\\\");\\n  curl_setopt($ch, CURLOPT_POSTFIELDS, $json);\\n  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\\n\\t\\t\\n  $headers = array(\\n            'Content-Type: application/json',\\n            'Content-Length: ' . strlen($params);\\n        \\n  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\\n        \\n  $result = curl_exec($ch);\\n  \\n  // Read the location header and redirect the user.\\n}\\n\\n\\nfunction get_hmac($params) {\\n  $hmac_params = array($params['store_id'], $params['currency'], $params['timestamp'], $params['nonce']);\\n  \\n  foreach($params['articles'] as $article) {\\n    $hmac_params[] = implode(':', array($article['retailer_reference_id'], $article['vat_percentage'], $article['price'], $article['quantity']));\\n  }\\n  \\n  $data = implode('&', $hmac_params);\\n  $hmac_key = base64_decode(URBIT_CHECKOUT_SECRET);\\n  \\n  return base64_encode(hash_hmac('sha256', utf8_encode($data), $hmac_key, true));\\n}\\n\\n\\nfunction sort_articles_by_id($a, $b) {\\n  return strcmp($a['retailer_reference_id'], $b['retailer_reference_id']);\\n}\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]","excerpt":"Instructions to set up the Click&Get UI","slug":"render-the-clickget-ui","type":"post","title":"Render the Click&Get UI"}

postRender the Click&Get UI

Instructions to set up the Click&Get UI

Definition

{{ api_url }}{{ page_api_url }}

Documentation

[block:api-header] { "type": "basic", "title": "Properties" } [/block] [block:parameters] { "data": { "h-0": "Name", "h-1": "Type", "h-2": "Description", "h-3": "Description", "0-0": "store_id", "0-1": "guid", "0-3": "Store id", "1-0": "retailer_reference_id", "1-1": "string", "1-2": "External order or reference number", "2-0": "nounce", "2-1": "string", "2-2": "A unique string", "3-0": "currency", "3-1": "string", "3-2": "ISO4217 standard, Both numeric and upper case letter codes are accepted", "4-0": "amount", "4-1": "int", "4-2": "Total price (including tax) in cents,", "5-0": "return_url", "5-1": "string", "5-2": "The url to return to after successful transaction", "6-0": "cancel_url", "6-1": "string", "6-2": "The url to return to in case the user cancels the checkout", "7-0": "timestamp", "7-1": "int", "7-2": "Current Unix timestamp. This field is used only for hmac calculation.", "8-0": "hmac", "8-1": "string", "8-2": "The signature that is used both for data integrity and authorization. Instructions how to generate the HMAC can be found [here](#hmac-signature)", "0-2": "Store id provided by urb-it" }, "cols": 3, "rows": 9 } [/block] **Article** [block:parameters] { "data": { "h-0": "Property", "h-1": "Type", "h-2": "Description", "0-0": "retailer_reference_id", "0-1": "string", "0-2": "Retailers article reference id (article id)", "1-0": "description", "1-1": "string", "1-2": "Name or short description about the article", "2-0": "price", "2-1": "int", "2-2": "Total price (including tax) in cents, multiplied by quantity", "3-0": "vat_percentage", "3-1": "int", "3-2": "Percentage of tax rate, multiplied by 100 and provided as an integer. (ex: 2500 for 25%)", "4-0": "quantity", "4-1": "int", "4-2": "Number of articles" }, "cols": 3, "rows": 5 } [/block] **Request** [block:code] { "codes": [ { "code": "POST / HTTP/1.1\nHost: checkout.urb-it.com\nContent-Type: application/json\n{\n \"retailer_reference_id\": \"ref1\",\n \"store_id\": \"3b8ddf21-51a0-4bf3-9c24-ed6e32c94e3e\",\n \"currency\": \"SEK\",\n \"return_url\": \"/\",\n \"cancel_url\": \"/\",\n \"error_url\": \"/\",\n \"timestamp\": 1456150457,\n \"nonce\": \"2a749ce9-0ec0-4cb8-9269-1a9feb0e6c5d\",\n \"amount\": 520000\n \"articles\": [\n {\n \"retailer_reference_id\": \"art1\",\n \"description\": \"Test\",\n \"price\": 520000,\n \"vat_percentage\": 2500,\n \"quantity\": 1\n }\n ],\n \"hmac\": \"6WJHos0/SxoZKIKjSwkhZd53OLEBIhf8OX7Cz/79cQk=\"\n}", "language": "html" } ] } [/block] **Response** [block:code] { "codes": [ { "code": "HTTP/1.1 201 Created\nContent-Type: application/json\nLocation : https://stage-checkout.urb-it.com/c/{id}", "language": "text" } ] } [/block] [block:api-header] { "type": "basic", "title": "HMAC Signature" } [/block] Follow the steps in order to create the signature 1. Concatenate store key, currency, timestamp, nonce and the items separated by & character. The item field are separated by ‘:’ as you can see in the below code sample. [block:code] { "codes": [ { "code": "sb.Append(contract.StoreId)\n .Append(\"&\" + contract.Currency)\n .Append(\"&\" + contract.Timestamp)\n .Append(\"&\" + contract.Nonce);\n\nforeach(var item in contract.Articles.OrderBy(i => i.RetailerReferenceId))\n{\n sb.AppendFormat(\"&{0}:{0}:{0}:{0}\", item.RetailerReferenceId, item.VatPercentage, item.Price, item.Quantity);\n}", "language": "csharp" } ] } [/block] [block:callout] { "type": "warning", "title": "Note", "body": "The article items are sorted based on retailer reference id." } [/block] 2. Sign the message [block:code] { "codes": [ { "code": "var secretKeyByteArray = Convert.FromBase64String(sharedSecret);\nvar hmac= String.Empty;\nusing (var hmac = new HMACSHA256(secretKeyByteArray))\n{\n byte[] signatureBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));\n hmac= Convert.ToBase64String(signatureBytes);\n}", "language": "csharp" } ] } [/block] [block:api-header] { "type": "basic", "title": "Implementation Examples" } [/block] [block:code] { "codes": [ { "code": "StringBuilder sb = new StringBuilder();\n\nsb.Append(contract.StoreId)\n .Append(\"&\" + contract.Currency)\n .Append(\"&\" + contract.Timestamp)\n .Append(\"&\" + contract.Nonce);\n\nforeach(var item in contract.Articles.OrderBy(i => i.RetailerReferenceId))\n{\n sb.AppendFormat(\"&{0}:{0}:{0}:{0}\", item.RetailerReferenceId, item.VatPercentage, item.Price, item.Quantity);\n}\n\nvar secretKeyByteArray = Convert.FromBase64String(sharedSecret);\nvar hmac= String.Empty;\nusing (var hmac = new HMACSHA256(secretKeyByteArray))\n{\n byte[] signatureBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));\n hmac= Convert.ToBase64String(signatureBytes);\n}\n\nvar request = new order()\n{\n retailer_reference_id = \"id\",\n store_id = \"1234\",\n currency = \"SEK\",\n return_url = \"/\",\n cancel_url = \"/\",\n error_url = \"/\",\n timestamp = \"1231233\",\n nounce = \"3123\",\n articles = new[\n {\n \"retailer_reference_id\": \"art1\",\n \"description\": \"Test\",\n \"price\": \"520000\",\n \"vat_percentage\": \"2500\",\n \"quantity\": \"1\"\n },\n hmac = hmac\n};\n\nusing (var client = new HttpClient())\n{\n var response = client.PostAsync(\"https://stage-checkout.urb-it.com/\",\n new StringContent(JsonConvert.SerializeObject(request).ToString(),\n Encoding.UTF8, \"application/json\"))\n .Result;\n\n if (response.IsSuccessStatusCode)\n {\n var checkoutUrl = response.Headers.Location;\n }\n}", "language": "csharp" }, { "code": "define(‘URBIT_CHECKOUT_ENDPOINT’, ‘https://checkout.urb-it.com/’);\ndefine(‘URBIT_CHECKOUT_TOKEN’, ‘yourtoken’);\ndefine(‘URBIT_CHECKOUT_SECRET’, ‘yoursecret’);\n\nfunction get_checkout_url($order) {\n $params = array(\n ‘store_id’ => URBIT_CHECKOUT_TOKEN,\n ‘retailer_reference_id’ => $order->get_order_number(),\n ‘currency’ => ‘SEK’,\n ‘return_url’ => ‘http://example.com/order-received/’\n ‘cancel_url’ => ‘http://example.com/order-canceled/’\n ‘articles’ => array(),\n ‘timestamp’ => time(),\n ‘nonce’ => md5(rand(0, 999999) . URBIT_CHECKOUT_TOKEN . microtime(true)),\n ‘amount’ => 0\n );\n \n // Add all order articles to params array\n foreach($order->get_articles() as $article) {\n $price_in_cents = (float)$article->price_incl_vat * 100 * $article->quantity;\n \n $params[‘articles’][] = array(\n ‘retailer_reference_id’ => $article->sku,\n ‘description’ => $article->description,\n ‘price’ => $price_in_cents,\n ‘vat_percentage’ => $article->vat_percentage,\n ‘quantity’ => $article->quantity\n );\n \n // Increase the order total\n $params[‘amount’] += $price_in_cents;\n }\n \n // Sort articles by reference ID\n usort($params[‘articles’], ‘sort_articles_by_id’);\n \n // Generate HMAC for authorization\n $params[‘hmac’] = get_hmac($params);\n \n $json = json_encode($params);\n $ch = curl_init($url);\n curl_setopt($ch, CURLOPT_CUSTOMREQUEST, \"POST\");\n curl_setopt($ch, CURLOPT_POSTFIELDS, $json);\n curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n\t\t\n $headers = array(\n ‘Content-Type: application/json’,\n ‘Content-Length: ‘ . strlen($params);\n \n curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\n \n $result = curl_exec($ch);\n \n // Read the location header and redirect the user.\n}\n\n\nfunction get_hmac($params) {\n $hmac_params = array($params[‘store_id’], $params[‘currency’], $params[‘timestamp’], $params[‘nonce’]);\n \n foreach($params[‘articles’] as $article) {\n $hmac_params[] = implode(‘:’, array($article[‘retailer_reference_id’], $article[‘vat_percentage’], $article[‘price’], $article[‘quantity’]));\n }\n \n $data = implode(‘&’, $hmac_params);\n $hmac_key = base64_decode(URBIT_CHECKOUT_SECRET);\n \n return base64_encode(hash_hmac(‘sha256’, utf8_encode($data), $hmac_key, true));\n}\n\n\nfunction sort_articles_by_id($a, $b) {\n return strcmp($a[‘retailer_reference_id’], $b[‘retailer_reference_id’]);\n}", "language": "php" } ] } [/block]