B4J Question Send Request to Apple server

ajk

Active Member
Licensed User
Longtime User
Follwing instructions
and
I'm trying to communicate with apple's sanbox server from my VPS with code like below
Still gettins 21002 that means: The data in the receipt-data property was malformed or the service experienced a temporary issue. Try again (obwiously request is not-well formed)
Any help appreciated.

B4X:
Private Sub DownloadApple (numer As String)
    
    Dim B64 As Base64
    Dim  url As String = "https://sandbox.itunes.apple.com/verifyReceipt"
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)

    Dim m As Map
    m.Initialize
    
    m.put ("receipt-data", B64.EncodeStoB( numer,"UTF8"))
    m.put("password",  SubskrypcjaSPLKluczAPPLE)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.PostString(url, jg.ToString)
    Job.GetRequest.SetContentType("application/json")
End Sub
 

ajk

Active Member
Licensed User
Longtime User
But it doesn't change Apple's response. I have had
B4X:
Sub JobDone(job As HttpJob)
    Log(">>>2")
    If job.Success Then
        Log(job.GetString)
    End If
    job.Release
End Sub
That gives response:

B4X:
>>>2
{"status":21002}

and if I use:
B4X:
    Wait For (Job) JobDone(j As HttpJob) 'redim
    If Job.Success Then
        Log(">>>3")
        Log(j.GetString)
    End If
    Job.Release

Server answer is the same:
B4X:
>>>3
{"status":21002}
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B64.EncodeStoB( numer,"UTF8"))
I guess here is the problem! You are expected to send a base64 STRING but you are generating a BYTES Array and use this in your Api-Call.

Check


and change the call to use encodestos

Even if the documentation points a

receipt-data
byte

I would try to send the bytes as a string. At least it should be worth the try
 
Last edited:
Upvote 0

ajk

Active Member
Licensed User
Longtime User
Than you for suggestion, I have tested all options including
B4X:
m.put ("receipt-data", B64.EncodeStoS( numer,"UTF8"))
before sending code to forum. Moreover according to apple manual
receipt-data
byte
(Required)
The Base64 encoded receipt data.
password
string
(Required)
Your app's shared secret (a hexadecimal string).
Use this field only for receipts that contain auto-renewable subscriptions.

as stadet in https://developer.apple.com/documentation/appstorereceipts/requestbody

No matter what version I use, the answer is always the same
{"status":21002}
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
is the receipt a auto-renewable subscription?
If so then you are missing the password in your call.

password
string
(Required)
Your app's shared secret (a hexadecimal string).
Use this field only for receipts that contain auto-renewable subscriptions.
 
Upvote 0

ajk

Active Member
Licensed User
Longtime User
auto-renewable subscription
I have tested before sending to forum with
B4X:
m.put("password", key)
m.put ("receipt-data", B64.EncodeStoS( numer,"UTF8"))
in almost all posible configuration including key encoded and as stated in manual non-encoded.
So all fields were included.
 
Upvote 0
Top