Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4085

API is not working Android Kotlin retrofit API for Mobile recharge

$
0
0

There is a API which running in post request. this code is not working:

PHP API query:

query('select mt.translationID,mt.mobile,mt.amount, mt.operatorCodeTimestamp as rechargedate, mt.status from mst_translation mt join agent_users mu on mu.agent_id=mt.userID where mu.mobile="'.$userID.'" and mu.domainName="'.$domain.'"')->result();interface ApiEndPoint {    @POST("api/Recharge/make")    fun rechargeMobile(        @Query("userId") userId: String,        @Query("domain") domain: String,        @Body request: RechargeRequest    ): Call<RechargeResponce?>?}

Main Activity

class MoneyTransfer : AppCompatActivity() {    val binding by lazy{        ActivityMoneyTransferBinding.inflate(layoutInflater)    }    private lateinit var apiEndPoint : ApiEndPoint    override fun onCreate(savedInstanceState: Bundle?) {        super.onCreate(savedInstanceState)        setContentView(binding.root)        initBlock()        binding.proceed.setOnClickListener {            dataSetup()        }    }    fun dataSetup(){        val mobileRechargeRequest = RechargeRequest(            operatorCode = binding.operatorCode.text.toString(),            userID = "2050",            userpin = "1234",            amount = binding.mobileNumber.text.toString(),            servicenumber = binding.mobileNumber.text.toString(),            domain = "www.pay2kart.com",            servicetype = "MOBILE"        )// Create a RechargeRequest object with the user ID and amount// Make the API call        val response = apiEndPoint.rechargeMobile("2050", "www.pay2kart.com",mobileRechargeRequest)// Handle the response        response!!.enqueue(object : Callback<RechargeResponce?> {            override fun onResponse(                call: Call<RechargeResponce?>,                response: Response<RechargeResponce?>            ) {                try {                    if (response != null) {                        Log.e("message", response.message().toString())                        Toast.makeText(                            this@MoneyTransfer,                            response.message().toString(),                            Toast.LENGTH_LONG                        ).show()                    }                } catch (e: Exception) {                    Toast.makeText(                        this@MoneyTransfer,"Some NetWork Error Has been found ... ",                        Toast.LENGTH_LONG                    ).show()                }            }            override fun onFailure(call: Call<RechargeResponce?>, t: Throwable) {                Toast.makeText(this@MoneyTransfer, "Failed ...", Toast.LENGTH_LONG).show()            }        })    }    private fun initBlock() {        var retrofit = ServerConnection.getConnection()        if (retrofit != null) {            apiEndPoint = retrofit.create(ApiEndPoint::class.java)        }    }}

Api

https://www.pay2kart.com/pay2kart_api_testing/Services/index.php/api/Recharge/make

In postman when I test the API and when I put data in body row file then this API show success message:

{"operatorCode":"102","userID":"2050","userpin":"1234","servicenumber":"8878840990", "domain":"www.pay2kart.com","servicetype":"MOBILE"}

I am new in programming where I am making mistake.

I am trying to put some data into this API and call the API for mobile recharge.


Viewing all articles
Browse latest Browse all 4085

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>