You need to sign in to do that
Don't have an account?
Mahesh Tandan 6
test captcha
Hii developers.
I'm using google v2 captcha on my vf extensions class
Now problem is I'm not able to test the captcha
this is the extension coce
Somebody please help
I'm using google v2 captcha on my vf extensions class
Now problem is I'm not able to test the captcha
this is the extension coce
public class addContactExtension { @TestVisible private static String baseUrl = 'https://www.google.com/recaptcha/api/siteverify';//captcha API endpoint. @TestVisible private static String secret = '6LcaHdMAEqDE4TTL****';//captcha API secret key. public String sitekey { //Captcha site key get { return '6LcaHdMUAAAAAKNwNDoR0RD8SXffM3JlwBSGKy6p';//Here, use my site key. }set; } public String response { get { return ApexPages.currentPage().getParameters().get('g-recaptcha-response'); }set; } Public pageReference paymentSave(){ String responseBody = makeRequest(baseUrl,'secret=' + secret +'&response='+ response); String success = getValueFromJson(responseBody, 'success'); if(success.equalsIgnoreCase('true')) { //execute code. } } TestVisible private static String makeRequest(string url, string body) { //Captcha api request start here HttpResponse response = null; HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('POST'); req.setBody (body); try{ Http http = new Http(); response = http.send(req); return response.getBody(); }catch(System.Exception e) { //System.debug('ERROR: ' + e); } return '{"success":false}'; }//Captcha api request Ends here public static string getValueFromJson ( String strJson, String field ) { JSONParser parser = JSON.createParser(strJson); while (parser.nextToken() != null){ if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) { if(parser.getText() == field){ // Get the value. parser.nextToken(); return parser.getText(); } } } return null; } }How to test this method .
Somebody please help