Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(PowerBuilder) Send ZATCA Invoice for Clearance

See more ZATCA Examples

Demonstrates how to send a ZATCA invoice for clearance, which is to send the HTTP POST with invoice hash and the signed invoice in base64 format.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
string ls_SignedXmlFilePath
oleobject loo_SignedXml
integer li_Success
string ls_InvoiceHash
string ls_Cbc_UUID
oleobject loo_Bd
string ls_Base64Invoice
oleobject loo_Json
oleobject loo_Http
oleobject loo_Resp
integer li_StatusCode
oleobject loo_JsonResp

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

// This example will send a POST with HTTP Basic Authentication to 
// https://gw-fatoora.zatca.sa/e-invoicing/simulation/invoices/clearance/single

// NOTE: At the time of this writing, I don't know for sure if the above URL is correct.
// 
// The body of the POST will contain JSON formatted as such:

// {
//   "summary": "Standard Invoice",
//   "value": {
//     "invoiceHash": "PEx8bNFcEMEpHzUVvQntQI6ot8eFqTT/l59b+H1HqX4=",
//     "uuid": "16e78469-64af-406d-9cfd-895e724198f0",
//     "invoice": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPEl....."
//   }
// }

// The above JSON is created from the signed XML invoice, such as the following:

// *** Look at the above base64 data for the invoiceHash and uuid.  These values are found in the invoice as shown below.
// *** We'll write code to load the signed invoice into a Chilkat XML object, grab the invoice hash and the uuid,
// *** and then construct the above JSON, which will then be sent in a POST.  (See below...)

// <?xml version="1.0" encoding="UTF-8"?>
// <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"><ext:UBLExtensions>
//     <ext:UBLExtension>
//         <ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
//         <ext:ExtensionContent>
//             <!-- Please note that the signature values are sample values only -->
//             <sig:UBLDocumentSignatures xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2" xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2">
//                 <sac:SignatureInformation>
//                     <cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID>
//                     <sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID>
//                     <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="signature">
//                         <ds:SignedInfo>
//                             <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2006/12/xml-c14n11"/>
//                             <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/>
//                             <ds:Reference Id="invoiceSignedData" URI="">
//                                 <ds:Transforms>
//                                     <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
//                                         <ds:XPath>not(//ancestor-or-self::ext:UBLExtensions)</ds:XPath>
//                                     </ds:Transform>
//                                     <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
//                                         <ds:XPath>not(//ancestor-or-self::cac:Signature)</ds:XPath>
//                                     </ds:Transform>
//                                     <ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
//                                         <ds:XPath>not(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID='QR'])</ds:XPath>
//                                     </ds:Transform>
//                                     <ds:Transform Algorithm="http://www.w3.org/2006/12/xml-c14n11"/>
//                                 </ds:Transforms>
//                                 <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
//                                 <ds:DigestValue>PEx8bNFcEMEpHzUVvQntQI6ot8eFqTT/l59b+H1HqX4=</ds:DigestValue>
//                             </ds:Reference>
//                             <ds:Reference Type="http://www.w3.org/2000/09/xmldsig#SignatureProperties" URI="#xadesSignedProperties">
//                                 <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
//                                 <ds:DigestValue>ZDEyMDUyODJjYzk4MGViNTJhNmYzMGIyZTgxODhkY2JlOWEzNmRiMTFlZTVhMDAxNjk5OTRkYTg3ODhlY2ZiMw==</ds:DigestValue>
//                             </ds:Reference>
//                         </ds:SignedInfo>
// ...
// ...
// ...
//         </ext:ExtensionContent>
//     </ext:UBLExtension>
// </ext:UBLExtensions>
//     
//     <cbc:ProfileID>reporting:1.0</cbc:ProfileID>
//     <cbc:ID>SME00062</cbc:ID>
//     <cbc:UUID>16e78469-64af-406d-9cfd-895e724198f0</cbc:UUID>
//     <cbc:IssueDate>2022-03-13</cbc:IssueDate>
//     <cbc:IssueTime>14:40:40</cbc:IssueTime>
//     <cbc:InvoiceTypeCode name="0111010">388</cbc:InvoiceTypeCode>
// ...
// ...
// ...
//     </cac:InvoiceLine>
// </Invoice>

// -------------------------------------------------------------------
// First, let's load our signed XML into a Chilkat XML object so we can get the uuid and invoice hash.
ls_SignedXmlFilePath = "qa_data/zatca/http_post_clearance/sample_signed_invoice.xml"

loo_SignedXml = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_SignedXml.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
    destroy loo_SignedXml
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_SignedXml.LoadXmlFile(ls_SignedXmlFilePath)
if li_Success = 0 then
    Write-Debug loo_SignedXml.LastErrorText
    destroy loo_SignedXml
    return
end if

ls_InvoiceHash = loo_SignedXml.GetChildContent("ext:UBLExtensions|ext:UBLExtension|ext:ExtensionContent|sig:UBLDocumentSignatures|sac:SignatureInformation|ds:Signature|ds:SignedInfo|ds:Reference[0]|ds:DigestValue")
Write-Debug "invoiceHash: " + ls_InvoiceHash

ls_Cbc_UUID = loo_SignedXml.GetChildContent("cbc:UUID")
Write-Debug "UUID: " + ls_Cbc_UUID

// The Chilkat XML object was used purely for getting the above 2 values.
// We must send the EXACT signed XML in base64 format.  Therefore, we should load the signed XML into a Chilkat BinData and get it in base64 single-line format.

loo_Bd = create oleobject
// Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_Bd.LoadFile(ls_SignedXmlFilePath)
ls_Base64Invoice = loo_Bd.GetEncoded("base64")

// OK, let's build the JSON that will be in the HTTP POST body.
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("summary","Standard Invoice")
loo_Json.UpdateString("value.invoiceHash",ls_InvoiceHash)
loo_Json.UpdateString("value.uuid",ls_Cbc_UUID)
loo_Json.UpdateString("value.invoice",ls_Base64Invoice)

// Now create the HTTP object and send the POST.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

// We'll want HTTP basic authentication.
loo_Http.BasicAuth = 1
loo_Http.Login = "your login"
loo_Http.Password = "your password"

loo_Resp = loo_Http.PostJson3("https://gw-fatoora.zatca.sa/e-invoicing/simulation/invoices/clearance/single","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_SignedXml
    destroy loo_Bd
    destroy loo_Json
    destroy loo_Http
    return
end if

// Check the response status code.  A 200 or 202 indicates success..
li_StatusCode = loo_Resp.StatusCode
Write-Debug "Response status code = " + string(li_StatusCode)

// Examine the response, which is JSON.
loo_JsonResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonResp.ConnectToNewObject("Chilkat.JsonObject")

loo_Resp.GetBodyJson(loo_JsonResp)
loo_JsonResp.EmitCompact = 0
Write-Debug "JSON Response:"
Write-Debug loo_JsonResp.Emit()

// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON


destroy loo_SignedXml
destroy loo_Bd
destroy loo_Json
destroy loo_Http
destroy loo_JsonResp

 

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