PHP code example of johnpaulmedina / laravel-usps
1. Go to this page and download the library: Download johnpaulmedina/laravel-usps library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
johnpaulmedina / laravel-usps example snippets
Johnpaulmedina\Usps\UspsServiceProvider::class,
'Usps' => Johnpaulmedina\Usps\Facades\Usps::class,
'usps' => [
'username' => "XXXXXXXXXXXX",
'testmode' => false,
],
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Support\Facades\Request;
use Johnpaulmedina\Usps;
class USPSController extends Controller
{
public function index() {
return response()->json(
Usps::validate(
Request::input('Address'),
Request::input('Zip'),
Request::input('Apartment'),
Request::input('City'),
Request::input('State')
)
);
}
public function trackConfirm() {
return response()->json(
Usps::trackConfirm(
Request::input('id')
)
);
}
public function trackConfirmRevision1() {
return response()->json(
Usps::trackConfirm(
Request::input('id'),
'Acme, Inc'
)
);
}
public function rate(Request $request) {
$usps_rate = Usps::rate(
[
'Service' => $request->input('Service', 'PRIORITY COMMERCIAL'),
'FirstClassMailType' => $request->input('FirstClassMailType', ''),
'ZipOrigination' => $request->input('ZipOrigination', '91601'),
'ZipDestination' => $request->input('ZipDestination', $zipcode),
'Pounds' => $request->input('Pounds', $weight),
'Ounces' => $request->input('Ounces', 0),
'Container' => $request->input('Container', 'VARIABLE'),
'Machinable' => $request->input('Machinable', 'True'),
]
);
$usps_return_rate = Arr::get($usps_rate, 'rate.RateV4Response.Package.Postage.Rate');
$usps_return_weight = Arr::get($usps_rate, 'rate.RateV4Response.Package.Pounds');
return response()->json([
'rate' => $usps_return_rate,
'weight'=> $usps_return_weight,
'usps' => $usps_rate
]);
}
}