I am trying to integrate Payfast api with my app. In WebView I can pass requested data to given https address properly but when ıt came to https request side errors occur. Simply I passed the same data to same path. What is the problem, your help is really appreciated. Thanks for now
Below code when I press the submit button it redirects proper payment page;
WebView(
initialUrl: new Uri.dataFromString(''' <!DOCTYPE html> <html>
<style>
input[type=button], input[type=submit], input[type=reset] {
background-color: #FF0000;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 8px 4px;
cursor: pointer;
}
</style>
<body style="background-color:#ffffff;">
<form action="https://sandbox.payfast.co.za/eng/process" method="post">
<input type="hidden" name="merchant_id" value="10022814">
<input type="hidden" name="merchant_key" value="aemfu0aapxale">
<input type="hidden" name="amount" value="$miktar">
<input type="hidden" name="item_name" value="Test Product">
<input type="submit" value="PAY NOW">
</form>
</body>
</html>
''',
mimeType: 'text/html').toString(),
javascriptMode: JavascriptMode.unrestricted,
gestureNavigationEnabled: true,
),
But 403 error Occur when http request is made.
HttpClient httpClient = new HttpClient();
HttpClientRequest request = await httpClient.postUrl(Uri.parse( "https://sandbox.payfast.co.za/onsite/process"));
request.headers.set('accept' , 'application/json');
request.headers.set('merchant-id' , '10022814');
request.headers.set('merchant_key' , 'aemfu0aapxale');
//sbtu01@payfast.co.za
//headers
//request.headers.set('Accept' , 'application/json');
Map body = { 'merchant_id' : '10022814',
'merchant_key' : 'aemfu0aapxale',
'amount' : '100.00',
'item_name' : '#000001'} ;
//body
request.add(utf8.encode(json.encode(body)));
//response cevap
HttpClientResponse response = await request.close();
print(response.statusCode); // baglanti yapildi mi yapilmadi mi 200 ise yapildi
String reply = await response.transform(utf8.decoder).join();
httpClient.close();
print("payfast ici odeme");
print(reply);
Is the API that you're trying to send the request to valid? It's likely that the payload that's being sent is invalid hence the 4XX error - which is usually caused by unauthenticated requests. If the request is valid, you can try sending the http request as form-data:
sendRequest() async {
final uri = 'https://sandbox.payfast.co.za/onsite/process';
http.Response response = await http.post(
uri, body: {
'merchant_id':'10022814',
'merchant_key':'aemfu0aapxale',
'amount':'100.00',
'item_name':'#000001'
});
debugPrint(response.body);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.