Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_BdSignedXml
oleobject loo_Json
oleobject loo_JsonToken
oleobject loo_Resp

li_Success = 0

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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.
loo_BdSignedXml = create oleobject
li_rc = loo_BdSignedXml.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_BdSignedXml.LoadFile("someDir/signed.xml")
if li_Success = 0 then
    Write-Debug "Failed to load the XAdES signed XML."
    destroy loo_Http
    destroy loo_BdSignedXml
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("clave","50601011600310112345600100010100000000011999999999")
loo_Json.UpdateString("fecha","2016-01-01T00:00:00-0600")
loo_Json.UpdateString("emisor.tipoIdentificacion","02")
loo_Json.UpdateString("emisor.numeroIdentificacion","003101123456")
loo_Json.UpdateString("receptor.tipoIdentificacion","02")
loo_Json.UpdateString("receptor.numeroIdentificacion","003101123456")
// Add the base64 encoded representation of the signed XML.
loo_Json.UpdateString("comprobanteXml",loo_BdSignedXml.GetEncoded("base64"))

// Load our previously obtained OAuth2 access token.
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_JsonToken.LoadFile("qa_data/tokens/hacienda_cr.json")
if li_Success <> 1 then
    Write-Debug "Failed to load constantContact.json"
    destroy loo_Http
    destroy loo_BdSignedXml
    destroy loo_Json
    destroy loo_JsonToken
    return
end if

// Adds the "Authorization: Bearer {access_token}" header.
loo_Http.AuthToken = loo_JsonToken.StringOf("access_token")

loo_Http.SetRequestHeader("Content-Type","application / json")

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://api.comprobanteselectronicos.go.cr/recepcion/v1/recepcion",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_BdSignedXml
    destroy loo_Json
    destroy loo_JsonToken
    destroy loo_Resp
    return
end if

// A 201 status code indicates success.
Write-Debug "Response status code: " + string(loo_Resp.StatusCode)

Write-Debug "Response body:"
Write-Debug loo_Resp.BodyStr


destroy loo_Http
destroy loo_BdSignedXml
destroy loo_Json
destroy loo_JsonToken
destroy loo_Resp