Skip to content

Commit

Permalink
fix: insurance and parcel create routing, search lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Feb 17, 2023
1 parent b51df39 commit 121ebd2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 42 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## v0.8.1 (2023-02-17)

- Fix create insurance, and parcel routing
- Fix search object lookup that wasn't migrated when we moved from EasyPost PHP lib v5 to v6

## v0.8.0 (2023-02-10)

- Bumps EasyPost library from v5 to v6 which introduces thread-safety and various other improvements
Expand Down
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/InsuranceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function createInsurance()
$response = $insurance;

session()->flash('message', 'INSURANCE CREATED');
return view('app')->with(['response' => $response]);
return redirect('/')->with(['response' => $response]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/ParcelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public function createParcel()
}

session()->flash('message', 'PARCEL CREATED');
return view('app')->with(['json' => $parcel]);
return redirect('/')->with(['json' => $parcel]);
}
}
60 changes: 30 additions & 30 deletions src/app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@

namespace App\Http\Controllers;

use EasyPost;
use EasyPost\Exception\General\EasyPostException;

const OBJECT_ID_PREFIXES = [
'adr' => EasyPost\Address::class,
'ak' => EasyPost\ApiKey::class,
'batch' => EasyPost\Batch::class,
'brd' => EasyPost\Brand::class,
'ca' => EasyPost\CarrierAccount::class,
'cstinfo' => EasyPost\CustomsInfo::class,
'cstitem' => EasyPost\CustomsItem::class,
'es' => EasyPost\EndShipper::class,
'evt' => EasyPost\Event::class,
'fee' => EasyPost\Fee::class,
'hook' => EasyPost\Webhook::class,
'ins' => EasyPost\Insurance::class,
'order' => EasyPost\Order::class,
'pickup' => EasyPost\Pickup::class,
'pl' => EasyPost\PostageLabel::class,
'plrep' => EasyPost\Report::class,
'prcl' => EasyPost\Parcel::class,
'rate' => EasyPost\Rate::class,
'refrep' => EasyPost\Report::class,
'rfnd' => EasyPost\Refund::class,
'sf' => EasyPost\ScanForm::class,
'shp' => EasyPost\Shipment::class,
'shpinvrep' => EasyPost\Report::class,
'shprep' => EasyPost\Report::class,
'trk' => EasyPost\Tracker::class,
'trkrep' => EasyPost\Report::class,
'user' => EasyPost\User::class,
'adr' => 'address',
'ak' => 'apikey',
'batch' => 'batch',
'brd' => 'brand',
'ca' => 'carrierAccount',
'cstinfo' => 'customsInfo',
'cstitem' => 'customsItem',
'es' => 'endShipper',
'evt' => 'event',
'fee' => 'fee',
'hook' => 'webhook',
'ins' => 'insurance',
'order' => 'order',
'pickup' => 'pickup',
'pl' => 'postageLabel',
'plrep' => 'report',
'prcl' => 'parcel',
'rate' => 'rate',
'refrep' => 'report',
'rfnd' => 'refund',
'sf' => 'scanForm',
'shp' => 'shipment',
'shpinvrep' => 'report',
'shprep' => 'report',
'trk' => 'tracker',
'trkrep' => 'report',
'user' => 'user',
];

class SearchController extends Controller
Expand All @@ -46,13 +45,14 @@ public function searchRecord()
{
$id = request()->get('id');
$idPrefix = substr($id, 0, strpos($id, '_'));
$client = request()->get('client');

try {
$response = OBJECT_ID_PREFIXES[$idPrefix]::retrieve($id);
$response = $client->{OBJECT_ID_PREFIXES[$idPrefix]}->retrieve($id);
} catch (EasyPostException $exception) {
return back()->withError($exception->getMessage())->withInput();
}

return to_route('app')->with(['json' => $response]);
return redirect('/')->with(['json' => $response]);
}
}
20 changes: 10 additions & 10 deletions src/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 121ebd2

Please sign in to comment.