I am trying to use RoyalPay SDK to create order and make Alipay payment. The response code is 200, but I cannot parse JSON in response.
How do I solve this problem?
The code I create api request with:
interface RoyalPayApi {
@FormUrlEncoded
@Headers("Accept: application/json", "Content-Type: application/json")
@PUT("/api/v1.0/gateway/partners/{partner_code}/app_orders/{order_id}")
fun createRoyalPaySDKOrder(@Path(value = "partner_code", encoded = true) partner_code: String, @Path(value = "order_id", encoded = true) order_id: String,
@Query("time") time: Long, @Query("nonce_str") nonce_str: String, @Query("sign") sign: String,
@Field("description") description: String,
@Field("price") price: Int,
@Field("currency") currency: String,
@Field("channel") channel: String,
@Field("operator") operator: String,
@Field("system") system: String): Call<JSONObject> // com.alibaba.fastjson.JSONObject
}
The code I get retrofit service:
fun createService(): RoyalPayApi {
val retrofit = Retrofit.Builder()
.baseUrl(ROYAL_PAY_ADDRESS)
.addConverterFactory(FastJsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
return retrofit.create(RoyalPayApi::class.java)
}
The code I send request and receive response:
var api = createService()
var call = api.createRoyalPaySDKOrder(ROYAL_PAY_PARTNER_CODE, order_id, time, ROYAL_PAY_NONCE_STR, sign,
description, price, "AUD", channel, "kate", "android")
call.enqueue(object : Callback<JSONObject>{
override fun onResponse(call: Call<JSONObject>, response: Response<JSONObject>) {
val str = ""
}
override fun onFailure(call: Call<JSONObject>, t: Throwable) {
val str = ""
}
})
This is the response I received:
This is the response body (Chinese here should not affect understanding):
This includes raw response (using com.google.gson.JsonObject):
Raw response using com.alibaba.fastjson.JSONObject
if change JSONObject to String, it just return the String version of error :(: