Android Question CURL translation in B4A - Stripe -

cirollo

Active Member
Licensed User
Longtime User
Hi!

I'm trying to translate in B4A my CURL call to Stripe Payment API, this is the basic call in CURL:

B4X:
curl https://api.stripe.com/v1/charges \
   -u sk_test_4eC39HqLyjWDarjtT1zdp7dc

Stripe docs say that


now I'm trying to do this in B4A:

B4X:
Dim job1 As HttpJob
       job1.Initialize("JobStripe",Me)
       job1.Download("https://api.stripe.com/v1/charges")
       job1.GetRequest.SetHeader("Authorization","Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc")

and also this
B4X:
    job1.Initialize("JobStripe",Me)
       job1.PostString("https://api.stripe.com/v1/charges","amount=5")
       job1.GetRequest.SetHeader("Authorization","sk_test_8schl5Ig2ZuQe5XIpjnNjKQH")



but when compiling I get:


where's the problem?

regards,
ciro
 
Last edited:

cirollo

Active Member
Licensed User
Longtime User
mybe I found the problem.....

I was using the following libraries:

okhttp
okhttputils2
httputils2

removing httputils2 solved the problems...

just a simple question: the code that was using httputils2 will still work now?
 
Last edited:
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
Hi! I succedeed with curl translation to call Stripe API but I'm having some problems on the returned JSON, this is the server response:

B4X:
{
  "id": "tok_1DePTxENBiByw1eYkUZaGFpj",
  "object": "token",
  "card": {
    "id": "card_1DePTxENBiByw1eYstyEqGfG",
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "Visa",
    "country": "US",
    "cvc_check": "unchecked",
    "dynamic_last4": null,
    "exp_month": 12,
    "exp_year": 2020,
    "fingerprint": "XauSvjvOfRW1kGeS",
    "funding": "credit",
    "last4": "4242",
    "metadata": {
    },
    "name": null,
    "tokenization_method": null
  },
  "client_ip": "151.84.255.212",
  "created": 1544112825,
  "livemode": false,
  "type": "card",
  "used": false
}

I'm getting an

java.lang.RuntimeException: JSON Array expected

when reading it like I do with others JSON, this way:

B4X:
       Dim root As List = parser.NextArray
           For Each colroot As Map In root
               StripeToken = colroot.Get("id")
           Next

why???
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
Isn't your root a map instead of a list (using nextObject instead of nextArray)?

I get this:

B4X:
Error occurred on line: 283 (Studenti)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.util.List
   at anywheresoftware.b4a.objects.collections.List.getSize(List.java:129)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:352)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
   at anywheresoftware.b4a.BA$2.run(BA.java:365)
   at android.os.Handler.handleCallback(Handler.java:808)
   at android.os.Handler.dispatchMessage(Handler.java:101)
   at android.os.Looper.loop(Looper.java:166)
   at android.app.ActivityThread.main(ActivityThread.java:7425)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
UPDATE

solved using ABM hint and the amazing JsonTree online tool !!!

B4X:
       Dim root2 As Map = parser.NextObject
           StripeToken = root2.Get("id")
           root2.Clear
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…