Initialisation de la demande de paiement

Lorsque l'acheteur valide sa commande l'application génère une "payload" contenant les données du panier, les coordonnées de l'acheteur, les informations de livraison etc...

L'exemple mis à disposition exploite les données suivantes:

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

L'application mobile transmet la demande de paiement au serveur marchand via une requête POST.

Extrait du code d'exemple pour 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)				
			

Extrait du code d'exemple pour 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
}