Skip to content

Commit 8ba6ff2

Browse files
committed
added comments
1 parent 64b06ec commit 8ba6ff2

File tree

5 files changed

+121
-29
lines changed

5 files changed

+121
-29
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ This package requires the following dependencies:
2626

2727
Via Composer
2828

29-
``` bash
29+
``` sh
3030
$ composer require ryandeng/googlerecaptcha
3131
```
3232

3333
If your Laravel framework version <= 5.4, please register the service provider in your config file: /config/app.php, otherwise please go to step 3.
3434

35-
```sh
35+
```
3636
Ryandadeng\Securepayframe\SecurePayFrameServiceProvider::class
3737
```
3838

3939
If your Laravel framework version is >= 5.5, just run the following command to publish views and config.
4040
```sh
41-
php artisan vendor:publish --provider="RyanDeng\GoogleReCaptcha\GoogleReCaptchaServiceProvider"
41+
$ php artisan vendor:publish --provider="RyanDeng\GoogleReCaptcha\GoogleReCaptchaServiceProvider"
4242
```
4343

4444
After installation, you should see a googlerecaptcha/googlerecaptcha.blade file in your views folder and googlerecaptchav3.php in your app/config folder.
@@ -47,7 +47,7 @@ If you want to change the default template, please check Advanced Usage.
4747

4848

4949
## Basic Usage
50-
#### Setting up your Google reCAPTCHA details
50+
#### Setting up your Google reCAPTCHA details in config file
5151

5252
Please register all details on host_name, site_key, secret_key and site_verify_url.
5353

@@ -70,14 +70,14 @@ For more details please check comments in config file.
7070

7171
You can use provided Validation object to verify your reCAPTCHA.
7272

73-
``` php
73+
```
7474
use RyanDeng\GoogleReCaptcha\Validations\GoogleReCaptchaValidationRule
7575
$rule = [
7676
'g-recaptcha-response' => [new GoogleReCaptchaValidationRule('action_name',$ip)]
7777
];
7878
```
7979

80-
'g-recaptcha-response' is the name of your <input> field, which is currently hard-coded.
80+
'g-recaptcha-response' is the name of your input field, which is currently hard-coded.
8181

8282
GoogleReCaptchaValidationRule($actionName, $ip) which accepts two optional parameters:
8383
- $actionName: if its NULL, the package won't verify action with google response.
@@ -87,14 +87,17 @@ For more details please check comments in config file.
8787

8888
#### Facade Class
8989

90+
91+
```
92+
GoogleReCaptcha::setAction($action)->verifyResponse($response, $ip);
93+
```
94+
9095
$action: Google reCAPTCHA definition
9196

9297
$response: which is a value comes from g-recaptcha-response
9398

9499
$ip: optional
95100

96-
GoogleReCaptcha::setAction($action)->verifyResponse($response, $ip);
97-
98101
## Advanced Usage
99102

100103
#### Custom implementation on Config

config/googlerecaptcha.php

Lines changed: 88 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,100 @@
11
<?php
22

33
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Enable/Disable Service
8+
|--------------------------------------------------------------------------
9+
| Type: bool
10+
|
11+
| This option is used to disable/enable the service
12+
|
13+
| Supported: true, false
14+
|
15+
*/
416
'is_service_enabled' => true,
17+
/*
18+
|--------------------------------------------------------------------------
19+
| Host Name
20+
|--------------------------------------------------------------------------
21+
| Type: string
22+
| Google reCAPTCHA host name, https://www.google.com/recaptcha/admin
23+
|
24+
*/
525
'host_name' => 'ryandeng.test',
6-
'secret_key' => '6Lez2HcUAAAAAIvmnukbhNLUAighVP6AuPcOFXT2',
7-
'curl_timeout' => 1,
8-
'curl_verify' => false,
9-
'template' => 'GoogleReCaptcha::googlerecaptcha.googlerecaptcha',
10-
'site_key' => '6Lez2HcUAAAAAJPDe-qVi5H8G5FB049E5mrljqt4',
11-
'options' => [
12-
'curl_timeout' => 1,
13-
'curl_verify' => 1,
14-
],
26+
/*
27+
|--------------------------------------------------------------------------
28+
| Secret Key
29+
|--------------------------------------------------------------------------
30+
| Type: string
31+
| Google reCAPTCHA credentials, https://www.google.com/recaptcha/admin
32+
|
33+
*/
34+
'secret_key' => '',
35+
/*
36+
|--------------------------------------------------------------------------
37+
| Site Key
38+
|--------------------------------------------------------------------------
39+
| Type: string
40+
| Google reCAPTCHA credentials, https://www.google.com/recaptcha/admin
41+
|
42+
*/
43+
'site_key' => '',
44+
/*
45+
|--------------------------------------------------------------------------
46+
| Template
47+
|--------------------------------------------------------------------------
48+
| Type: string
49+
| Template path, if your template locate at resources/views/template/test.blade.php
50+
| your value should be template.test
51+
|
52+
*/
53+
'template' => 'googlerecaptcha.googlerecaptcha',
54+
/*
55+
|--------------------------------------------------------------------------
56+
| Score Comparision
57+
|--------------------------------------------------------------------------
58+
| Type: bool
59+
| If you enable it, the package will do score comparision from your score_setting
60+
*/
1561
'is_score_enabled' => true,
62+
/*
63+
|--------------------------------------------------------------------------
64+
| Score Setting
65+
|--------------------------------------------------------------------------
66+
| Type: array
67+
| Define your score threshold
68+
| action: Google reCAPTCHA required paramater
69+
| id: <input> id
70+
| threshold: score threshold
71+
| is_enabled: true/false, if this is true, the system will do score comparsion against your threshold for the action
72+
*/
1673
'score_setting' => [
1774
[
18-
'action' => 'a',
19-
'id' => 'cccc',
20-
'threshold' => 0.2,
75+
'action' => 'contact_us',
76+
'id' => 'contact_us_id',
77+
'threshold' => 0,
2178
'is_enabled' => false
22-
],
23-
[
24-
'action' => 'c',
25-
'id' => 'ddd',
26-
'threshold' => 0.1,
27-
'is_enabled' => true
28-
],
79+
]
80+
],
81+
/*
82+
|--------------------------------------------------------------------------
83+
| Options
84+
|--------------------------------------------------------------------------
85+
| Used for request
86+
|
87+
*/
88+
'options' => [
89+
'curl_timeout' => 1,
90+
'curl_verify' => 1,
2991
],
92+
/*
93+
|--------------------------------------------------------------------------
94+
| Site Verify Url
95+
|--------------------------------------------------------------------------
96+
| Type: string
97+
| Google reCAPTCHA API
98+
*/
3099
'site_verify_url' => 'https://www.google.com/recaptcha/api/siteverify',
31100
];

src/Configurations/ReCaptchaConfig.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,33 @@
77

88
class ReCaptchaConfig implements ReCaptchaConfigInterface
99
{
10+
/**
11+
* @return string
12+
*/
1013
public function isServiceEnabled()
1114
{
1215
return config('googlerecaptcha.site_key');
1316
}
1417

18+
/**
19+
* @return string
20+
*/
1521
public function getSiteVerifyUrl()
1622
{
1723
return config('googlerecaptcha.site_verify_url');
1824
}
1925

26+
/**
27+
* @return string
28+
*/
2029
public function getHostName()
2130
{
2231
return config('googlerecaptcha.host_name');
2332
}
2433

34+
/**
35+
* @return bool
36+
*/
2537
public function isScoreEnabled()
2638
{
2739
return config('googlerecaptcha.is_score_enabled');

src/Interfaces/ReCaptchaConfigInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
interface ReCaptchaConfigInterface
1313
{
1414

15+
/**
16+
* @return bool
17+
*/
1518
public function isServiceEnabled();
19+
1620
/**
1721
* @return bool
1822
*/
@@ -43,7 +47,6 @@ public function getTemplate();
4347
*/
4448
public function getSiteKey();
4549

46-
4750
/**
4851
* @return array
4952
*/

src/Interfaces/RequestClientInterface.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
interface RequestClientInterface
1313
{
1414

15-
15+
/**
16+
* @param $url
17+
* @param $body
18+
* @param array $options
19+
* @return mixed
20+
*/
1621
public function post($url, $body, $options = []);
1722

1823
}

0 commit comments

Comments
 (0)