Lua
Lua
hacienda.go.cr Recepción de comprobantes electrónicos y respuestas del receptor.
See more hacienda.go.cr Examples
Comprobantes Electrónicos API version v1 -- Recepción de comprobantes electrónicos y respuestas del receptor.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Implements the following CURL command:
-- curl -X POST -H "Content-Type: application / json" \
-- -H 'authorization: Bearer {access_token}' \
-- -d '{
-- "clave": "50601011600310112345600100010100000000011999999999",
-- "fecha": "2016-01-01T00:00:00-0600",
-- "emisor": {
-- "tipoIdentificacion": "02",
-- "numeroIdentificacion": "003101123456"
-- },
-- "receptor": {
-- "tipoIdentificacion": "02",
-- "numeroIdentificacion": "003101123456"
-- },
-- "comprobanteXml": "PD94..."
-- }' https://api.comprobanteselectronicos.go.cr/recepcion/v1/recepcion
-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code
-- Use this online tool to generate code from sample JSON:
-- Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "clave": "50601011600310112345600100010100000000011999999999",
-- "fecha": "2016-01-01T00:00:00-0600",
-- "emisor": {
-- "tipoIdentificacion": "02",
-- "numeroIdentificacion": "003101123456"
-- },
-- "receptor": {
-- "tipoIdentificacion": "02",
-- "numeroIdentificacion": "003101123456"
-- },
-- "comprobanteXml": "PD94b..."
-- }
-- Load the previously signed XML.
local bdSignedXml = chilkat.BinData.new()
local success = bdSignedXml:load_file("someDir/signed.xml")
if not success then
print("Failed to load the XAdES signed XML.")
return
end
local json = chilkat.JsonObject.new()
json:update_string("clave", "50601011600310112345600100010100000000011999999999")
json:update_string("fecha", "2016-01-01T00:00:00-0600")
json:update_string("emisor.tipoIdentificacion", "02")
json:update_string("emisor.numeroIdentificacion", "003101123456")
json:update_string("receptor.tipoIdentificacion", "02")
json:update_string("receptor.numeroIdentificacion", "003101123456")
-- Add the base64 encoded representation of the signed XML.
json:update_string("comprobanteXml", bdSignedXml:get_encoded("base64"))
-- Load our previously obtained OAuth2 access token.
local jsonToken = chilkat.JsonObject.new()
success = jsonToken:load_file("qa_data/tokens/hacienda_cr.json")
if not success then
print("Failed to load constantContact.json")
return
end
-- Adds the "Authorization: Bearer {access_token}" header.
http.auth_token = jsonToken:string_of("access_token")
http:set_request_header("Content-Type", "application / json")
local resp = chilkat.HttpResponse.new()
success = http:http_json("POST", "https://api.comprobanteselectronicos.go.cr/recepcion/v1/recepcion", json, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
-- A 201 status code indicates success.
print("Response status code: " .. resp.status_code)
print("Response body:")
print(resp.body_str)