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
but....

how... ?
B4X:
public Sub LocalRequestSalesPayment(iptopost As String,  sessionid As String, amount As Int) As ResumableSub
   
   
    Private j As HttpJob
    j.Initialize("viva",Me)
    j.postString(iptopost & "/pos/v1/sale",$"{"sessionId": "${sessionid}", "amount": ${amount.As(String)}}"$)
    '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



ps: sorry Erel for fast json text string and not using the proper way
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Check their documentation. The must be a URL and a port listed somewhere there.

Or in your ACCOUNT. the link you posted is only a link to the example in the docs. The URL must be available somewhere. I can´t help on getting the right URL.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Upvote 0

Magma

Expert
Licensed User
Longtime User
code... using for call sub-routine is

B4X:
Wait For (a.localRequestSalesPayment("https://192.168.168.239:7900","no_of_invoice-try111",30,978,"test...","test...","false",0,0)) complete (success As Boolean)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User

Maybe you have a Port setting in the EFT POS Device?

Use the device IP Address and the Port in the REST Call
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
....there is an option... at softpos... enabling Peer to Peer... enabled that... and gave me different port....

also getting different log error !:

 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Wait For (a.RequestSalesPayment("no_of_invoice-try27",a.terminal_id,"YOURCASHIERSERIAL001",30,978,"test...","test...", False,0,0)) complete (success As Boolean)
I can say this is a bad practice. It is hard to read and you may accidentally passing the wrong argument.
Can you modify it to pass the json as argument?

B4X:
Sub RequestSalesPayment (json As String)

End Sub

Edit: or pass it as a Map.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
ok - i am editing it
 
Upvote 0

Magma

Expert
Licensed User
Longtime User


I know you are not going to sleep if not edit that... so here you are..

B4X:
public Sub LocalRequestSalesPayment(iptopost As String,  sessionid As String, amount As Int) As ResumableSub
    
    
    Private j As HttpJob
    j.Initialize("viva",Me)

    Dim m As Map = CreateMap("sessionId": sessionid, "amount": amount)
    Dim json As String = m.As(JSON).ToString

    j.postString(iptopost & "/pos/v1/sale",json) 

    J.GetRequest.SetContentType("application/json")

    Wait For (j) JobDone(j As HttpJob)

    If j.Success=True Then

        Log(j.GetString)
        j.release

        Return True

    Else
        j.Release
        Return False
    End If

End Sub

but i have the same PKIX error...
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I know you are not going to sleep if not edit that... so here you are..
Hope you would have sweet dream too...

B4X:
Public Sub RequestSalesPayment (Url As String, Data As Map, AccessToken As String) As ResumableSub
    Dim success As Boolean
    Dim j As HttpJob
    j.Initialize("", Me)
    j.PostString(Url & "/pos/v1/sale", Data.As(JSON).ToString)
    j.GetRequest.SetHeader("Authorization", "Bearer " & AccessToken)
    'j.GetRequest.Setheader("Accept", "application/json")
    J.GetRequest.SetContentType("application/json")
    
    ' DonManfred snippet
    J.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")
    
    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("There is an error")
        Log(j.ErrorMessage)
    End If
    j.Release
    Return success
End Sub
 

Attachments

  • VivaEcrApi.zip
    10.1 KB · Views: 25
Upvote 0

aeric

Expert
Licensed User
Longtime User
By using Map, you can easily commented the unnecessary lines of code.

B4X:
Dim pmt As Map
pmt.Initialize
pmt.Put("sessionId", "4bdebe62-c211-4ca0-a994-b2fbea2061c5")
pmt.Put("terminalId", "16000010")
pmt.Put("cashRegisterId", "XDE384678UY")
pmt.Put("amount", 1170)
pmt.Put("currencyCode", "978")
pmt.Put("merchantReference", "some-reference")
pmt.Put("customerTrns", "some-reference")
pmt.Put("preauth", False)
pmt.Put("maxInstalments", 0)
pmt.Put("tipAmount", 0)
'pmt.Put("showTransactionResult", True)
'pmt.Put("showReceipt", True)
'pmt.Put("aadeProviderId", 999)
'pmt.Put("aadeProviderSignatureData", "AD33729F4ED749928AAFA00B90EE4EA91551BAC1;;20231204080313;1051;10000;2400;12400;POS_1")
'pmt.Put("aadeProviderSignature", "o0094r3Yk3KTqASLkW3evlDsnIg/ZAdUUf6UCXDtjqpI/dquzAT4WNX3yzS/GLciVNbT75H4pj8hLOV0EpHtzw==")
'pmt.Put("aadePreloaded", True)
'pmt.Put("aadePreloadedDuration", 13)

Dim a As Utility
a.Initialize
Wait For (a.RequestSalesPayment(usingurl, pmt, access_token)) Complete (Success As Boolean)
Log("RequestSalesPayment: " & Success)
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
well..

the same... access_token not something need for local... but remove or not... nothing different....

 
Upvote 0

aeric

Expert
Licensed User
Longtime User
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).
 
Upvote 0
Solution

Magma

Expert
Licensed User
Longtime User
It WORKEDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD!

needed HU2_ACCEPTALL (this not had it) with https (as i have it) - and worked !!!!!!!!!!!!!!!

not with first... first made clean project... and then worked..
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…