Muhtar
Muhtar

Reputation: 1700

Payfast Api integration to Flutter App Http request Errors

I am building an app with Payfast payment gateway. The gateways documentaion only covers php side but I want to make it by requesting https. Trying to resolve the situation but don't understand where I am wrong.

Trying to make simple form integration on this site payfast_developers_docs

I got 404 and 500 error. Can not reach checkout form. Thanks for now.

Below my source code;

     DateTime ax= DateTime.now();
    print(ax);


    String a = "amount=100.00&Content-Type=application/json&item_name=#000001&merchant_id=10000100&merchant_id=10000100&merchant_key=46f0cd694581a&timestamp=$ax&version=v1";
    md5.convert(utf8.encode(a)).toString();
    //String pkistring = v1hashing(requeststr);
    HttpClient httpClient = new HttpClient();
    HttpClientRequest request = await httpClient.postUrl(Uri.https( "sandbox.payfast.co.za", "/eng/process​"));
    request.headers.set('Content-Type' ,  'application/json');
    request.headers.set('merchant-id' ,  '10000100');
    request.headers.set('version' ,  'v1');
    request.headers.set('timestamp' ,  ax);
    request.headers.set('signature' ,   md5.convert(utf8.encode(a)).toString());




//headers
//request.headers.set('Accept' ,  'application/json');
    Map body = { 'merchant_id' : '10000100',
      'merchant_key' : '46f0cd694581a',
      'amount' : '100.00',
      'item_name' : '#000001',
    'signature': '${md5.convert(utf8.encode(a)).toString()}'} ;

//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();
    //Map responseMap = json.decode(reply);
    httpClient.close();
    print("payfast ici odeme");
    print(reply);
    Navigator.push(context, MaterialPageRoute(builder: (context) => new a3dsecure(reply)));

Upvotes: 2

Views: 951

Answers (0)

Related Questions