Inicialización de la solicitud de pago

Cuando el comprador valida su pedido, la aplicación genera una “payload” que contiene los datos del carrito, los datos de contacto del comprador, la información sobre la entrega, etc.

El ejemplo proporcionado utiliza los siguientes datos:

{
	"email": "example@email.com",
	"orderId": "myOrderId-1",
	"amount": "200",
	"currency": "978",
	"mode": "TEST",
	"language": "fr",
	"cardType": ""
}				

La aplicación móvil transmite la solicitud de pago al servidor del vendedor mediante una solicitud POST.

Extracto del código de ejemplo para Android:

val conn = URL(serverUrl).openConnection() as HttpURLConnection
conn.requestMethod = "POST"
conn.setRequestProperty("Content-type", "application/json")
conn.setRequestProperty("Accept", "*/*")
conn.doInput = true
conn.doOutput = true
conn.connectTimeout = 15000
	
val os = conn.outputStream
val writer = BufferedWriter(OutputStreamWriter(os, "UTF-8"))
writer.write(payload.toString())
writer.flush()
writer.close()
os.close()
	
conn.connect()
	
val out = OutputStreamWriter(conn.outputStream)				
			

Extracto del código de ejemplo para iOS:

/// Build an URLRequest according required payment information : server url, email, amount, mode, lang
///
/// - Returns: URLRequest object
func buildRequest() -> URLRequest? {
	let serverUrl: NSURL = NSURL(string: PayZenPayment.SERVER_URL)!
	var urlRequest = URLRequest(url:serverUrl as URL)
	urlRequest.httpMethod = "POST"
	var params: [String: String] = ["amount": paymentInfo.amount, "currency": paymentInfo.currency, "mode": paymentInfo.mode, "language": paymentInfo.lang]
	if !paymentInfo.email.isEmpty{
		params["email"] = paymentInfo.email
	}
	if !paymentInfo.cardType.isEmpty{
		params["cardType"] = paymentInfo.cardType
	}
	do{
		let jsonParam = try JSONSerialization.data(withJSONObject: params, options: [])
		urlRequest.httpBody = jsonParam
	}
	catch{
		return nil
	}
	
	return urlRequest
}