B4J Question HttpJob B4X Difference with .NET ?

Magma

Expert
Licensed User
Longtime User
Hi there.....

I have here my code:
B4X:
public Sub RequestSalesPayment(sessionId As String, terminal_id1 As String, cashregister_id As String, amount As Int, currencyCode As Int, merchantnotes As String, customernotes As String, preauthbool As String,maxInstalments As Int, tipamount As Int) As ResumableSub
  
    If gottoken=False Then
        Log($"Sorry, not having "access_token" to continue at RequestSalesPayment..."$)
        Return False
    End If
  
    Private j As HttpJob
    j.Initialize("viva",Me)
  
    j.postString(usingurl & "transactions:sale",$"{"sessionId": "${sessionId}","terminalId": ${terminal_id1},"cashRegisterId": "${cashregister_id}","amount": ${amount.As(String)},"currencyCode": ${currencyCode.as(String)},"merchantReference": "${merchantnotes}","customerTrns": "${customernotes}","preauth": ${preauthbool},"maxInstalments": ${maxInstalments.as(String)},"tipAmount": ${tipamount.as(String)}}"$) 'amount 0.30...
    j.GetRequest.SetHeader("Authorization", "Bearer " & access_token)
    j.GetRequest.Setheader("Accept", "application/json")
    J.GetRequest.SetContentType("application/json")
    Wait For (j) JobDone(j As HttpJob)
    'Log(j.GetString)
    If j.Success=True Then
    If j.GetString.Contains("detail")=True Then
        j.release
        Log("This SessionID already used, use other and try again.")
        Return False
        Else
            Log(j.GetString)          
        j.release
        Log("Now you will probably check your POS after a while (because of cloud) - asking for credit/debit card.")
        Return True
    End If
    Else
        j.Release
        Return False
    End If

End Sub


and this the code of vb .net created from a partner (based ony my code):
B4X:
        Public Async Function RequestSalesPayment(sessionId As String, terminalId1 As String, cashRegisterId As String, amount As Integer, currencyCode As Integer, merchantNotes As String, customerNotes As String, preauthBool As String, maxInstallments As Integer, tipAmount As Integer) As Task(Of Boolean)
            If Not _gotToken Then
                Debug.WriteLine("Sorry, not having access_token to continue at RequestSalesPayment...")
                Return False
            End If

            Dim jsonContent As String = $"{{""sessionId"": ""{sessionId}"",""terminalId"": ""{terminalId1}"",""cashRegisterId"": ""{cashRegisterId}"",""amount"": {amount},""currencyCode"": {currencyCode},""merchantReference"": ""{merchantNotes}"",""customerTrns"": ""{customerNotes}"",""preauth"": {preauthBool},""maxInstallments"": {maxInstallments},""tipAmount"": {tipAmount}}}"
            Dim content As New StringContent(jsonContent, Encoding.UTF8, "application/json")

            httpClient.DefaultRequestHeaders.Authorization = New Headers.AuthenticationHeaderValue("Bearer", AccessToken)

            Dim response = Await httpClient.PostAsync(_usingUrl & "transactions:sale", content)
            Dim result = Await response.Content.ReadAsStringAsync()

            If response.IsSuccessStatusCode Then
                If result.Contains("detail") Then
                    Debug.WriteLine("This SessionID already used, use another and try again.")
                    Return False
                Else
                    Debug.WriteLine("Now you will probably check your POS after a while (because of cloud) - asking for credit/debit card.")
                    Return True
                End If
            Else
                Return False
            End If
        End Function

My code works ok when POS is not having locked keyboard (ticking at EFTPOS Greek IRS AADE) - not working when tick
Code of friend works ok when POS anytime (ticking at EFTPOS Greek IRS AADE) <---that i need to do with my code too...

Running the code taking the same responses... but the value/price going at locked machine when using .NET code... with my code not...
Am i having some encoding problem or something can't found - any idea ?

Going to be crazy !!!

My class is here...
 
Last edited:
Solution
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Maybe related to the certificate or https.
Since you said it is a local device, does it have a secure certificate installed?
Does http work?

If it does have an ssl or https then try adding HU2_ACCEPTALL to Conditional Symbols in Build Configurations (Ctrl+B).

Magma

Expert
Licensed User
Longtime User
What do you mean by locking the keyboard and ticking?
This is from the side of EFT-POS Hardware/Software running on eft-pos - the ticking / enabling the "AADE requirement" (not something from our side)
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
Why create json like this?

It is so simple to create json properly:
B4X:
Dim m As Map = CreateMap("sessionId": sessionId, "terminalId": terminal_id1, ...)
Dim json As String = m.As(JSON).ToString

1. Try it.
2. If it doesn't work then post the error message.

change to what you said... is preety and much readable.. but the same..
B4X:
public Sub RequestSalesPayment(sessionId As String, terminal_id1 As String, cashregister_id As String, amount As Int, currencyCode As Int, merchantnotes As String, customernotes As String, preauthbool As Boolean,maxInstalments As Int, tipamount As Int) As ResumableSub
   
    If gottoken=False Then
        Log($"Sorry, not having "access_token" to continue at RequestSalesPayment..."$)
        Return False
    End If
   
    Private j As HttpJob
    j.Initialize("viva",Me)
   
    Dim m As Map = CreateMap("sessionId": sessionId, "terminalId": terminal_id1, "cashRegisterId": cashregister_id,"amount": amount,"currencyCode": currencyCode.as(String),"merchantReference": merchantnotes,"customerTrns": customernotes,"preauth": preauthbool,"maxInstalments": maxInstalments,"tipAmount": tipamount)
    Dim json As String = m.As(JSON).ToString
   
    Log(json)
   
    j.postString(usingurl & "transactions:sale",json) 'amount 0.30...
    j.GetRequest.SetHeader("Authorization", "Bearer " & access_token)
    j.GetRequest.Setheader("Accept", "application/json")
    J.GetRequest.SetContentType("application/json")
    Wait For (j) JobDone(j As HttpJob)
    'Log(j.GetString)
    If j.Success=True Then
    If j.GetString.Contains("detail")=True Then
        j.release
        Log("This SessionID already used, use other and try again.")
        Return False
        Else
            Log(j.GetString)           
        j.release
        Log("Now you will probably check your POS after a while (because of cloud) - asking for credit/debit card.")
        Return True
    End If
    Else
        j.Release
        Return False
    End If

End Sub

I am not saying that i m getting error - I am saying that i am not having the same result... at EFT-POS (even if demo or production)

Wait For (a.RequestSalesPayment("no_of_invoice-try27",a.terminal_id,"YOURCASHIERSERIAL001",30,978,"test...","test...", False,0,0)) complete (success As Boolean)
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
OK, I've got access_token, ready to use it...
I will auto set the last list item as default terminal_id
16001517
{
"amount": 30,
"preauth": false,
"tipAmount": 0,
"sessionId": "no_of_invoice-try27",
"terminalId": "16001517",
"customerTrns": "test...",
"cashRegisterId": "YOURCASHIERSERIAL001",
"currencyCode": "978",
"merchantReference": "test...",
"maxInstalments": 0
}
Now you will probably check your POS after a while (because of cloud) - asking for credit/debit card.

at B4X: If enabled the "AADE requirement" (IRS) ... will not request sales payment at EFT-POS ... if not enabled - request right...

but in .NET
getting the same result - requesting for paying every time - that is the right...


api:
 
Last edited:
Upvote 0

Magma

Expert
Licensed User
Longtime User
How do you write the code to call RequestSalesPayment?
What are the output of the 2 different results?
I have the code up there...

.Net too...

The result is the same... when all get good.... empty response... if problem the return 404... or various errors... or a detail if the same session (invoice-id perhaps)

The only i can thing is may be

j.GetRequest.Setheader("Accept", "application/json")
J.GetRequest.SetContentType("application/json")
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I try rewrite your sub.

B4X:
Public Sub RequestSalesPayment (sessionId As String, terminal_id1 As String, cashregister_id As String, amount As Int, currencyCode As Int, merchantnotes As String, customernotes As String, preauthbool As String, maxInstalments As Int, tipamount As Int) As ResumableSub
    Dim success As Boolean

    If gottoken = False Then
        Log($"Sorry, not having "access_token" to continue at RequestSalesPayment..."$)
        Return False
    End If
 
    Dim m As Map = CreateMap("sessionId": sessionId, "terminalId": terminal_id1, "cashRegisterId": cashregister_id, "amount": amount, "currencyCode": currencyCode, "merchantReference": merchantnotes, "customerTrns": customernotes, "preauth": preauthbool, "maxInstalments": maxInstalments, "tipAmount": tipamount)
    Dim json As String = m.As(JSON).ToString

    Dim j As HttpJob
    j.Initialize("", Me)
    'j.postString(usingurl & "transactions:sale",$"{"sessionId": "${sessionId}","terminalId": ${terminal_id1},"cashRegisterId": "${cashregister_id}","amount": ${amount.As(String)},"currencyCode": ${currencyCode.as(String)},"merchantReference": "${merchantnotes}","customerTrns": "${customernotes}","preauth": ${preauthbool},"maxInstalments": ${maxInstalments.as(String)},"tipAmount": ${tipamount.as(String)}}"$) 'amount 0.30...
    j.PostString(usingurl & "transactions:sale", json)
    j.GetRequest.SetHeader("Authorization", "Bearer " & access_token)
    'j.GetRequest.Setheader("Accept", "application/json")
    'J.GetRequest.SetContentType("application/json")
    Wait For (j) JobDone (j As HttpJob)
    If j.Success Then
        Log(j.GetString)
        If j.GetString.Contains("detail") Then
            Log("This SessionID already used, use other and try again.")           
        Else
            Log("Now you will probably check your POS after a while (because of cloud) - asking for credit/debit card.")
            success = True
        End If
    Else
        Log(j.ErrorMessage)
    End If
    j.Release
    Return success
End Sub
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
B4X:
            Wait For (a.RequestSalesPayment("no_of_invoice-try27",a.terminal_id,"YOURCASHIERSERIAL001",30,978,"test...","test...", False,0,0)) complete (success As Boolean)

And ofcourse is a success because... not having problem... the command travels... to EFT-POS... but not triggering "lock" keyboard... because of something different...
 
  • Like
Reactions: udg
Upvote 0

Magma

Expert
Licensed User
Longtime User
if remove them...
'j.GetRequest.Setheader("Accept", "application/json")
'J.GetRequest.SetContentType("application/json")

without them..
ResponseError. Reason: , Response: {"detail":[{"loc":["body"],"msg":"value is not a valid dict","type":"type_error.dict"}]}

before... removing was right... is something else the problem..can't find
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Magma

Expert
Licensed User
Longtime User
This is not needed.

I'm not sure that I understood, but if it works the first time and fails on the second then it might be related to a stored cookie that is being sent after the first response.

Try to clear the cookies after each request: https://www.b4x.com/android/forum/threads/httputils-cookie-store.113930/post-711519
No...

not worked too...

I deleted also the data and the cache of app (demo vivapayments) and not "requesting" payment when locked keyboard... if untick AADE (IRS)... requesting payments :-(
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
OkHttp is creating a http request and sending it. There is nothing else that it does and it works with all http servers.

There is a small chance that the error is related to the user agent. You can try to set it.

My guess is that the problem is somewhere else. I don't understand what this means " if untick AADE (IRS)... requesting payments ". You need to check their documentation and find out how exactly the request should be built.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
User agent.. where how ?
B4X:
Job1.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
OkHttp is creating a http request and sending it. There is nothing else that it does and it works with all http servers.

There is a small chance that the error is related to the user agent. You can try to set it.

My guess is that the problem is somewhere else. I don't understand what this means " if untick AADE (IRS)... requesting payments ". You need to check their documentation and find out how exactly the request should be built.
You re right...

I m pretty sure... may be something with demo account... or my accounts...

Also... just now have an answer from them to use other API !!!


This is for Local Area Network...
no need credentials, no token need only direct send json to get response....

but this for me also fails not getting nothing only errors
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
You re right...

I m pretty sure... may be something with demo account... or my accounts...

Also... just now have an answer from them to use other API !!!


This is for Local Area Network...
no need credentials, no token need only direct send json to get response....

but this for me also fails not getting nothing only errors
not explaining how will do the http request... :-(
 
Upvote 0
Top