Tokenizar una orden
Este proceso es requerido para todas las integraciones tanto para el plugin, el widget, el SDK o el API, por temas de seguridad trabajamos con órdenes tokenizadas para evitar que sean manipuladas desde el frontend.
Flujo para tokenizar una orden
Debes tener en cuenta que se requiere de un backend para poder tokenizar una orden, desde tu frontend del comercio recolecta los datos necesarios y enviarlos a tu servidor en el cual se tiene que generar un identificador único (ID), para luego realizar una petición POST a nuestro Checkout API y obtener una orden tokenizada, deberás guardar en tu base de datos el token y el ID de la orden obtenida para ser usado en cualquier integración que estés configurando.
Pasos para tokenizar una orden
1. Obtener la API KEY Privada
Puedes encontrar una guía al respecto ¿Cómo obtener mis API Keys?.
Para tokenizar la orden se necesita la API KEY privada obtenida en el Admin, esto debe ser parte del header de la petición a /merchants/orders con el nombre X-API-KEY
2. Datos de la orden
En estos JSON encontrarás los parámetros y estructura mínima requerida para tokenizar una orden de tipo delivery o pickup, puedes conocer más de cada parámetro de forma detallada, su tipo de dato, y si es requerido o no en Crear token de orden.
{
"order":{
"order_id":"LOCAL12022123",
"currency":"USD",
"store_code":"all",
"timezone":"America/Mexico_City",
"tax_amount":10,
"shipping_amount":10,
"items_total_amount":299,
"sub_total":299,
"total_amount":2990,
"total_discount":0,
"items":[
{
"id":"79",
"name":"10 ALITAS VOLANTE",
"description":"10 alitas picantes",
"total_amount":{
"amount":299,
"currency":"USD",
"currency_symbol":"$"
},
"unit_price":{
"amount":299,
"currency":"USD",
"currency_symbol":"$"
},
"tax_amount":{
"amount":754,
"currency":"USD",
"currency_symbol":"$"
},
"quantity":1,
"image_url":"https://images-staging.getduna.com/95463fb5-6279-4ec3-8ff9-fe07aacd2142/a901b84fcbeaedd5_domicilio_519_744x744.png?d=600x600"
}
],
"shipping_options":{
"type":"delivery",
"details":{
"store_name":"Store Name",
"address":"6 Rotermanni 11343 Talinn",
"address_coordinates":{
"lat":4.721245,
"lng":-74.04673
},
"contact":{
"name":"jhon snow",
"phone":"+9999999999"
},
"additional_details":{
"address_notes":"first floor"
}
}
},
"user_instructions":"NO REQUERIDO",
"metadata":{
"key1":"NO REQUERIDO",
"key2":"NO REQUERIDO"
}
}
}
{
"order":{
"order_id":"LOCAL12022123",
"currency":"USD",
"store_code":"all",
"timezone":"America/Mexico_City",
"tax_amount":10,
"shipping_amount":10,
"items_total_amount":299,
"sub_total":299,
"total_amount":2990,
"items":[
{
"id":"79",
"name":"10 ALITAS VOLANTE",
"description":"10 alitas picantes",
"total_amount":{
"amount":299,
"currency":"USD",
"currency_symbol":"$"
},
"unit_price":{
"amount":299,
"currency":"USD",
"currency_symbol":"$"
},
"tax_amount":{
"amount":754,
"currency":"USD",
"currency_symbol":"$"
},
"quantity":1,
"image_url":"https://images-staging.getduna.com/95463fb5-6279-4ec3-8ff9-fe07aacd2142/a901b84fcbeaedd5_domicilio_519_744x744.png?d=600x600"
}
],
"shipping_options":{
"type":"pickup",
"details":{
"store_name":"Store Name",
"address":"6 Rotermanni 11343 Talinn",
"address_coordinates":{
"lat":4.721245,
"lng":-74.04673
},
"contact":{
"name":"jhon snow",
"phone":"+9999999999"
},
"additional_details":{
"stock_location":"all",
"pickup_time":"20222206171300"
}
}
},
"user_instructions":"NO REQUERIDO",
"metadata":{
"key1":"NO REQUERIDO",
"key2":"NO REQUERIDO"
}
}
}
Nota:
Dejamos unas recetas para que puedas ver la diferencia entre los tipos de envío.
3. Tokenizar la orden
Realizar una petición POST desde el Servidor del comercio a DEUNA para obtener una orden tokenizada con la estructura mínima requerida.
Estos son ejemplos de lo que retorna DEUNA, puedes conocer más a detalle cada atributo y que representa en Crear token de orden.
Store code
Las credenciales de procesadores de pago se buscan con una combinación de el comercio y la tienda asociada a una orden.
Esta busqueda soporta tener una tienda predeterminadaall
configurada a nivel de comercio que se usara en caso de que se envie una orden con un codigo de tienda (store_code) que no tenga asociadas credenciales de una pasarela de pago.*Nota: La relacion de
"token": "yo-> order token",
"order es unica y no se admite repetir la configuracion de una pasarela para la misma tienda.
{
"token": "your order token",
"order": {
"order_id": " LOCAL12022123",
"store_code": "all", //
"currency": "USD",
"tax_amount": 10,
"display_tax_amount": "USD 0.10",
"shipping_amount": 10,
"display_shipping_amount": "USD 0.10",
"items_total_amount": 299,
"display_items_total_amount": "USD 2.99",
"sub_total": 299,
"display_sub_total": "USD 2.99",
"total_amount": 2990,
"display_total_amount": "USD 29.90",
"total_discount":0,
"display_total_discount": "USD 0.0",
"items": [
{
"id": "79",
"name": "10 ALITAS VOLANTE",
"description": "10 alitas picantes",
"options": "",
"total_amount": {
"amount": 299,
"original_amount": 0,
"display_amount": "USD 2.99",
"display_original_amount": "USD 0.00",
"currency": "USD",
"currency_symbol": "$",
"total_discount": 0,
"display_total_discount": "USD 0.00"
},
"unit_price": {
"amount": 299,
"display_amount": "USD 2.99",
"currency": "USD",
"currency_symbol": "$"
},
"tax_amount": {
"amount": 754,
"display_amount": "USD 7.54",
"currency": "USD",
"currency_symbol": "$"
},
"quantity": 1,
"uom": "",
"upc": "",
"sku": "",
"isbn": "",
"brand": "",
"manufacturer": "",
"category": "",
"color": "",
"size": "",
"weight": {
"weight": 0,
"unit": ""
},
"image_url": "https://images-staging.getduna.com/95463fb5-6279-4ec3-8ff9-fe07aacd2142/a901b84fcbeaedd5_domicilio_519_744x744.png?d=600x600",
"details_url": "",
"type": "",
"taxable": false,
"discounts": []
}
],
"discounts": [],
"shipping_address": {
"id": 0,
"user_id": "",
"first_name": "",
"last_name": "",
"phone": "",
"identity_document": "",
"lat": 0,
"lng": 0,
"address1": "",
"address2": "",
"city": "",
"zipcode": "",
"state_name": "",
"country_code": "",
"additional_description": "",
"address_type": "",
"is_default": false,
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "0001-01-01T00:00:00Z"
},
"shipping_options": {
"type": "delivery",
"details": {
"store_name": "Store Name",
"address": "6 Rotermanni 11343 Talinn",
"address_coordinates": {
"lat": 4.721245,
"lng": -74.04673
},
"contact": {
"name": "",
"phone": ""
},
"additional_details": {
"address_notes":"first floor"
}
}
},
"user_instructions": "NO REQUERIDO",
"metadata": {
"key1": "NO REQUERIDO",
"key2": "NO REQUERIDO"
},
"status": "pending",
"payment": {
"data": {
"amount": {
"amount": 0,
"currency": ""
},
"metadata": {},
"from_card": {
"card_brand": "",
"first_six": "",
"last_four": ""
},
"updated_at": "0001-01-01 00:00:00 +0000 UTC",
"method_type": "",
"merchant": {
"store_code": "",
"id": ""
},
"created_at": "0001-01-01 00:00:00 +0000 UTC",
"id": "",
"processor": "",
"customer": {
"email": "",
"id": ""
},
"status": "",
"reason": ""
}
},
"gift_card": [],
"redirect_url": "",
"webhook_urls": {
"notify_order": "https://{url_comercio}.com/notify",
"apply_coupon": "https://{url_comercio}.com/apply_coupon",
"remove_coupon": "https://{url_comercio}.com/remove_coupon",
"get_shipping_methods": "https://{url_comercio}.com/shipping_methods",
"update_shipping_method": "https://{url_comercio}.com/shipping_method/code",
"shipping_rate": "https://{url_comercio}.com/shipping"
},
"total_discount": 0,
"display_total_discount": "USD 0.00",
"shipping": {
"original_amount": 0,
"total_discount": 0,
"discounts": []
},
"cash_change": 0,
"shipping_method": {
"code": "",
"name": "",
"min_delivery_date": "",
"max_delivery_date": "",
"cost": 0,
"display_cost": "",
"tax_amount": 0,
"display_tax_amount": "",
"scheduler": []
},
"shipping_methods": [],
"timezone": "America/Mexico_City",
"scheduled_at": ""
}
}
{
"token": "your order token",
"order": {
"order_id": " LOCAL12022123",
"store_code": "all",
"currency": "USD",
"tax_amount": 10,
"display_tax_amount": "USD 0.10",
"shipping_amount": 10,
"display_shipping_amount": "USD 0.10",
"items_total_amount": 299,
"display_items_total_amount": "USD 2.99",
"sub_total": 299,
"display_sub_total": "USD 2.99",
"total_amount": 2990,
"display_total_amount": "USD 29.90",
"items": [
{
"id": "79",
"name": "10 ALITAS VOLANTE",
"description": "10 alitas picantes",
"options": "",
"total_amount": {
"amount": 299,
"original_amount": 0,
"display_amount": "USD 2.99",
"display_original_amount": "USD 0.00",
"currency": "USD",
"currency_symbol": "$",
"total_discount": 0,
"display_total_discount": "USD 0.00"
},
"unit_price": {
"amount": 299,
"display_amount": "USD 2.99",
"currency": "USD",
"currency_symbol": "$"
},
"tax_amount": {
"amount": 754,
"display_amount": "USD 7.54",
"currency": "USD",
"currency_symbol": "$"
},
"quantity": 1,
"uom": "",
"upc": "",
"sku": "",
"isbn": "",
"brand": "",
"manufacturer": "",
"category": "",
"color": "",
"size": "",
"weight": {
"weight": 0,
"unit": ""
},
"image_url": "https://images-staging.getduna.com/95463fb5-6279-4ec3-8ff9-fe07aacd2142/a901b84fcbeaedd5_domicilio_519_744x744.png?d=600x600",
"details_url": "",
"type": "",
"taxable": false,
"discounts": []
}
],
"discounts": [],
"shipping_address": {
"id": 0,
"user_id": "",
"first_name": "",
"last_name": "",
"phone": "",
"identity_document": "",
"lat": 0,
"lng": 0,
"address1": "",
"address2": "",
"city": "",
"zipcode": "",
"state_name": "",
"country_code": "",
"additional_description": "",
"address_type": "",
"is_default": false,
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "0001-01-01T00:00:00Z"
},
"shipping_options": {
"type": "pickup",
"details": {
"store_name": "Store Name",
"address": "6 Rotermanni 11343 Talinn",
"address_coordinates": {
"lat": 4.721245,
"lng": -74.04673
},
"contact": {
"name": "",
"phone": ""
},
"additional_details": {
"stock_location":"all",
"pickup_time":"20222206171300"
}
}
},
"user_instructions": "NO REQUERIDO",
"metadata": {
"key1": "NO REQUERIDO",
"key2": "NO REQUERIDO"
},
"status": "pending",
"payment": {
"data": {
"amount": {
"amount": 0,
"currency": ""
},
"metadata": {},
"from_card": {
"card_brand": "",
"first_six": "",
"last_four": ""
},
"updated_at": "0001-01-01 00:00:00 +0000 UTC",
"method_type": "",
"merchant": {
"store_code": "",
"id": ""
},
"created_at": "0001-01-01 00:00:00 +0000 UTC",
"id": "",
"processor": "",
"customer": {
"email": "",
"id": ""
},
"status": "",
"reason": ""
}
},
"gift_card": [],
"redirect_url": "",
"webhook_urls": {
"notify_order": "https://{url_comercio}.com/notify",
"apply_coupon": "https://{url_comercio}.com/apply_coupon",
"remove_coupon": "https://{url_comercio}.com/remove_coupon",
"get_shipping_methods": "https://{url_comercio}.com/shipping_methods",
"update_shipping_method": "https://{url_comercio}.com/shipping_method/code",
"shipping_rate": "https://{url_comercio}.com/shipping"
},
"total_discount": 0,
"display_total_discount": "USD 0.00",
"shipping": {
"original_amount": 0,
"total_discount": 0,
"discounts": []
},
"cash_change": 0,
"shipping_method": {
"code": "",
"name": "",
"min_delivery_date": "",
"max_delivery_date": "",
"cost": 0,
"display_cost": "",
"tax_amount": 0,
"display_tax_amount": "",
"scheduler": []
},
"shipping_methods": [],
"timezone": "America/Mexico_City",
"scheduled_at": ""
}
}
Updated 10 months ago