Android Question okhttputils2 parameter for Payment gateway

AndroidMadhu

Active Member
Licensed User
Hello,
I got the below sample code from, when I ran the test order id at postman.
B4X:
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n  \"amount\": 1000000,\n  \"currency\": \"INR\",\n  \"receipt\": \"Receipt no. 1\",\n  \"payment_capture\": 1,\n  \"notes\": {\n    \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n    \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n  }\n}");
Request request = new Request.Builder()
  .url("https://api.razorpay.com/v1/orders")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  .build();
Response response = client.newCall(request).execute();

But I am not sure about how to implement the above code in B4A with okhttputils2.

Please advice

Thanks
 

aeric

Expert
Licensed User
Longtime User
B4X:
Sub GetOrders
    Dim Notes As Map = CreateMap("notes_key_1": "Tea, Earl Grey, Hot", "notes_key_2": "Tea, Earl Grey… decaf.")
    Dim Map As Map = CreateMap("amount": 1000000, "currency": "INR", "receipt": "Receipt no. 1", "payment_capture": 1, "notes": Notes)
    
    Dim gen As JSONGenerator
    gen.Initialize(Map)
    
    Dim j As HttpJob
    j.Initialize("", Me)
    j.PostString("https://api.razorpay.com/v1/orders", gen.ToString)
    j.GetRequest.SetContentType("application/json")
    j.GetRequest.SetHeader("Authorization", "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
    Wait For (j) JobDone (j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    j.Release
End Sub
 
Upvote 0
Top