Kotlin can`t recognize values for parameters like merchant_id , amount , description , callback_uri.
I tried to fill all keys by proper values but I got this error :
{"data":[],"errors":{"code":-9,"message":"The input params invalid, validation error.","validations":[{"merchant_id":"The merchant id field is required."},{"amount":"The amount field is required."},{"callback_url":"The callback url field is required."},{"description":"The description field is required."}]}}
here is my code :
import java.net.HttpURLConnection import java.net.URL fun main() { val url = URL("https://api.zarinpal.com/pg/v4/payment/request.json") val connection = url.openConnection() as HttpURLConnection connection.requestMethod = "POST" connection.setRequestProperty("Content-Type", "application/json") connection.setRequestProperty("Accept", "application/json") connection.doOutput = true val postData : String = """ { "amount": 1100, "callback_url": "https://ali568865.ir/", "merchant_id": "1344b5d4-0048-11e8-94db-005056a205be", "back_uri": "Transaction description.", "metadata": { "mobile": "09106869409", "email": "[email protected]", "card_pan": "5022291083818920", } } """.trimIndent() connection.outputStream.use { outputStream -> outputStream.write(postData.toByteArray()) } val responseCode = connection.responseCode if (responseCode == HttpURLConnection.HTTP_OK) { val response = connection.inputStream.bufferedReader().use { it.readText() } println(response) } else { println("Failed to make the request. Response code: $responseCode") } connection.disconnect() }