Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Send POST to Bradesco Platform with Billing Ticket for Registration

Sends a POST request to the Bradesco platform containing the JSON data of the Billing Ticket for registration.

Note: This example requires updates that are in Chilkat v9.5.0.77 and later.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoJson
    Variant vCert
    Handle hoCert
    Handle hoCrypt
    String sSigBase64
    String sUrl
    Variant vReq
    Handle hoReq
    Handle hoHttp
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    // First build the JSON containing the data to be sent.

    // {
    // "nuCPFCNPJ":"12668",
    // "filialCPFCNPJ":"1",
    // "ctrlCPFCNPJ":"59",
    // "cdTipoAcesso":"2",
    // "idProduto":"9",
    // "nuNegociacao":"262200000000005577",
    // "nuCliente":"SEU_NUM_CLIENTE",
    // "dtEmissaoTitulo":"21.09.2016",
    // "dtVencimentoTitulo":"21.09.2016",
    // "vlNominalTitulo":"888888",
    // "cdEspecieTitulo":"2",
    // "nomePagador":"NOME DO PAGADOR",
    // "logradouroPagador":"ENDERECO DO PAGADOR",
    // "nuLogradouroPagador":"1145",
    // "complementoLogradouroPagador":"APTO 34",
    // "cepPagador":"5588",
    // "complementoCepPagador":"1",
    // "bairroPagador":"BAIRRO PAGADOR",
    // "municipioPagador":"MUNICIPIO PAGADOR",
    // "ufPagador":"SP",
    // "cdIndCpfcnpjPagador":"2",
    // "nuCpfcnpjPagador":"12668000159",
    // "endEletronicoPagador":"PAGADOR@BRADESCO.COM.BR",
    // "nomeSacadorAvalista":"NOME SACADOR AVALISTA",
    // "logradouroSacadorAvalista":"ENDERECO SACADOR AVALISTA",
    // "nuLogradouroSacadorAvalista":"5555",
    // "complementoLogradouroSacadorAvalista":"BLOCO 23",
    // "cepSacadorAvalista":"6182",
    // "complementoCepSacadorAvalista":"160",
    // "bairroSacadorAvalista":"BAIRRO SACADOR AVALISTA",
    // "municipioSacadorAvalista":"MUNICIPIO SACADOR AVALISTA",
    // "ufSacadorAvalista":"SP",
    // "cdIndCpfcnpjSacadorAvalista":"2",
    // "nuCpfcnpjSacadorAvalista":"12668000159",
    // "endEletronicoSacadorAvalista":"SACADOR@BRADESCO.COM.BR",
    // }
    // 

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "nuCPFCNPJ" "12668" To iSuccess
    Get ComUpdateString Of hoJson "filialCPFCNPJ" "1" To iSuccess
    Get ComUpdateString Of hoJson "ctrlCPFCNPJ" "59" To iSuccess
    Get ComUpdateString Of hoJson "cdTipoAcesso" "2" To iSuccess
    Get ComUpdateString Of hoJson "idProduto" "9" To iSuccess
    Get ComUpdateString Of hoJson "nuNegociacao" "262200000000005577" To iSuccess
    Get ComUpdateString Of hoJson "nuCliente" "SEU_NUM_CLIENTE" To iSuccess
    Get ComUpdateString Of hoJson "dtEmissaoTitulo" "21.09.2016" To iSuccess
    Get ComUpdateString Of hoJson "dtVencimentoTitulo" "21.09.2016" To iSuccess
    Get ComUpdateString Of hoJson "vlNominalTitulo" "888888" To iSuccess
    Get ComUpdateString Of hoJson "cdEspecieTitulo" "2" To iSuccess
    Get ComUpdateString Of hoJson "nomePagador" "NOME DO PAGADOR" To iSuccess
    Get ComUpdateString Of hoJson "logradouroPagador" "ENDERECO DO PAGADOR" To iSuccess
    Get ComUpdateString Of hoJson "nuLogradouroPagador" "1145" To iSuccess
    Get ComUpdateString Of hoJson "complementoLogradouroPagador" "APTO 34" To iSuccess
    Get ComUpdateString Of hoJson "cepPagador" "5588" To iSuccess
    Get ComUpdateString Of hoJson "complementoCepPagador" "1" To iSuccess
    Get ComUpdateString Of hoJson "bairroPagador" "BAIRRO PAGADOR" To iSuccess
    Get ComUpdateString Of hoJson "municipioPagador" "MUNICIPIO PAGADOR" To iSuccess
    Get ComUpdateString Of hoJson "ufPagador" "SP" To iSuccess
    Get ComUpdateString Of hoJson "cdIndCpfcnpjPagador" "2" To iSuccess
    Get ComUpdateString Of hoJson "nuCpfcnpjPagador" "12668000159" To iSuccess
    Get ComUpdateString Of hoJson "endEletronicoPagador" "PAGADOR@BRADESCO.COM.BR" To iSuccess
    Get ComUpdateString Of hoJson "nomeSacadorAvalista" "NOME SACADOR AVALISTA" To iSuccess
    Get ComUpdateString Of hoJson "logradouroSacadorAvalista" "ENDERECO SACADOR AVALISTA" To iSuccess
    Get ComUpdateString Of hoJson "nuLogradouroSacadorAvalista" "5555" To iSuccess
    Get ComUpdateString Of hoJson "complementoLogradouroSacadorAvalista" "BLOCO 23" To iSuccess
    Get ComUpdateString Of hoJson "cepSacadorAvalista" "6182" To iSuccess
    Get ComUpdateString Of hoJson "complementoCepSacadorAvalista" "160" To iSuccess
    Get ComUpdateString Of hoJson "bairroSacadorAvalista" "BAIRRO SACADOR AVALISTA" To iSuccess
    Get ComUpdateString Of hoJson "municipioSacadorAvalista" "MUNICIPIO SACADOR AVALISTA" To iSuccess
    Get ComUpdateString Of hoJson "ufSacadorAvalista" "SP" To iSuccess
    Get ComUpdateString Of hoJson "cdIndCpfcnpjSacadorAvalista" "2" To iSuccess
    Get ComUpdateString Of hoJson "nuCpfcnpjSacadorAvalista" "12668000159" To iSuccess
    Get ComUpdateString Of hoJson "endEletronicoSacadorAvalista" "SACADOR@BRADESCO.COM.BR" To iSuccess

    // Load out PFX file 
    Get Create (RefClass(cComChilkatCert)) To hoCert
    If (Not(IsComObjectCreated(hoCert))) Begin
        Send CreateComObject of hoCert
    End
    Get ComLoadPfxFile Of hoCert "qa_data/pfx/cert_test123.pfx" "test123" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
    If (Not(IsComObjectCreated(hoCrypt))) Begin
        Send CreateComObject of hoCrypt
    End
    Get pvComObject of hoCert to vCert
    Get ComSetSigningCert Of hoCrypt vCert To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoCrypt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Use SHA-256 within the signing..
    Set ComHashAlgorithm Of hoCrypt To "sha256"

    // IMPORTANT: This example requires Chilkat v9.5.0.77 or later.
    // Use no authenticated attributes
    Set ComSigningAttributes Of hoCrypt To "{}"

    Set ComEmitCompact Of hoJson To True
    Get ComEmit Of hoJson To sTemp1
    Get ComOpaqueSignStringENC Of hoCrypt sTemp1 To sSigBase64
    Get ComLastMethodSuccess Of hoCrypt To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoCrypt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Next, we need to send a POST to the following URL where the body of the POST
    // contains the binary PKCS7 signature (which embeds the JSON).
    Move "https://cobranca.bradesconetempresa.b.br/ibpjregistrotitulows/registrotitulohomologacao" To sUrl

    Get Create (RefClass(cComChilkatHttpRequest)) To hoReq
    If (Not(IsComObjectCreated(hoReq))) Begin
        Send CreateComObject of hoReq
    End
    Set ComHttpVerb Of hoReq To "POST"
    // This is strange because apparently the server wants a "text/xml" Content-Type,
    // but the content in the body is not actually XML, it's binary PKCS7.
    Set ComContentType Of hoReq To "text/xml"
    Get ComLoadBodyFromString Of hoReq sSigBase64 "utf-8" To iSuccess

    // We don't actually pass the URL, we set the path here, and the domain is passed below..
    Set ComPath Of hoReq To "/ibpjregistrotitulows/registrotitulohomologacao"

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Get pvComObject of hoReq to vReq
    Get ComSynchronousRequest Of hoHttp "cobranca.bradesconetempresa.b.br" 443 True vReq To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln "Response status code: " iTemp1
    Showln "Response body:"
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1

    Send Destroy of hoResp


End_Procedure

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.