You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-30Lines changed: 56 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Laravel-Usps
2
2
3
-
This package provides a very simple wrapper for the United States Postal Service API. Currently, this package only provides address verification features, but will soon comprise all features offered by the USPS API. In the meantime, consider using [johnpaulmedina/laravel-usps](https://github.com/johnpaulmedina/laravel-usps), which is a great package.
3
+
This package provides a very simple wrapper for the United States Postal Service API. Currently, this package only provides address validation features, but will soon comprise all features offered by the USPS API. In the meantime, consider using [johnpaulmedina/laravel-usps](https://github.com/johnpaulmedina/laravel-usps), which is a great package.
4
4
5
5
### Prerequisites
6
6
@@ -13,54 +13,80 @@ from the United States Postal Service. This user ID is required to use this pack
13
13
composer require ctwillie/laravel-usps
14
14
```
15
15
16
-
## Setup
17
-
18
-
Starting at Laravel 5.5, this package will be automatically discovered and registered as a service provider.
19
-
For earlier versions of Laravel, you will need to manually register this packages' service provider in `config/app.php`
20
-
by adding this class to the providers array.
21
-
22
-
```php
23
-
'providers' => [
24
-
...
25
-
ctwillie\Usps\UspsServiceProvider::class
26
-
];
27
-
```
28
-
Then add an alias for the class also in `config/app.php` inside the aliases array.
- If you have not received your USPS user ID, follow the link in the [prerequisites](#Prerequisites) section to register with the
42
21
United States Postal Service. It is required to use this package.
43
22
44
23
2. Whether you want SSL verification enabled for API requests:
45
-
- This setting is set to `true` by default for security reasons. You can override this behavior by setting the `verrifyssl` config setting to `false`. Do this at your own risk.
24
+
- This setting is set to `true` by default for security reasons. You can override this behavior by setting the `verrifyssl` config setting to `false`. Do this at your own risk.
25
+
26
+
3. Which environment you are working in:
27
+
- The options are `'local' and 'production'` which tell the package which API url to use, testing or production respectively. If no configuration is found for `env`, it will default to the environment recognized by laravel. This setting takes precedence over `APP_ENV` from your `.env` file.
46
28
47
29
We recommend placing all configuration settings in your `.env` file and use Laravel's `env()` helper function to access these values.
48
30
49
-
In `config/services.php` add these two settings.
31
+
In `config/services.php` add these three settings.
The current features offered by this package are listed below.
63
-
-[Address Verification](#Address)
44
+
The current features offered by this package are:
45
+
-[Address Validation](#Address-Validation)
46
+
47
+
48
+
## Address Validation
49
+
50
+
The `Address` class handles creating and formatting address data. Pass the constructor an associative array of address details. Array keys are case-sensitive.
51
+
Below is an example of creating an address and making an api request for validation.
52
+
53
+
```php
54
+
use ctwillie\Usps\Address;
55
+
56
+
$address = new Address([
57
+
'Address2' => '6406 Ivy Lane',
58
+
'City' => 'Greenbelt',
59
+
'State' => 'MD',
60
+
'Zip5' => 20770
61
+
]);
62
+
63
+
$response = $address->validate();
64
+
```
65
+
The USPS api supports up to 5 address validations per request. If you need to validate more than one address at a time, pass a multi dim array to the `Address` constructor.
66
+
67
+
```php
68
+
use ctwillie\Usps\Address;
69
+
70
+
$address1 = [
71
+
'Address2' => '6406 Ivy Lane',
72
+
'City' => 'Greenbelt',
73
+
'State' => 'MD',
74
+
'Zip5' => 20770
75
+
];
76
+
77
+
$address2 = [
78
+
'Address2' => '6406 Ivy Lane',
79
+
'City' => 'Greenbelt',
80
+
'State' => 'MD',
81
+
'Zip5' => 20770
82
+
];
83
+
84
+
$addresses = new Address([$address1, $address2])
85
+
86
+
$response = $addresses->validate();
87
+
```
88
+
89
+
The response will contain the [corrected address](https://www.usps.com/business/web-tools-apis/address-information-api.pdf), or an error if not enough information was given or the address does not exists.
0 commit comments