diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index c1642dede6b0..7dd25d4bcc4a 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -646,6 +646,10 @@ class CreditController extends BaseController { $invitation = $this->credit_repository->getInvitationByKey($invitation_key); + if (! $invitation) { + return response()->json(['message' => 'no record found'], 400); + } + $credit = $invitation->credit; $file = $credit->service()->getCreditPdf($invitation); diff --git a/routes/api.php b/routes/api.php index dcd6cb570de3..dbcfdfbc2da1 100644 --- a/routes/api.php +++ b/routes/api.php @@ -172,6 +172,7 @@ Route::group(['middleware' => ['throttle:300,1', 'api_db', 'token_auth', 'locale Route::put('credits/{credit}/upload', [CreditController::class, 'upload'])->name('credits.upload'); Route::get('credits/{credit}/{action}', [CreditController::class, 'action'])->name('credits.action'); Route::post('credits/bulk', [CreditController::class, 'bulk'])->name('credits.bulk'); + Route::get('credit/{invitation_key}/download', [CreditController::class, 'downloadPdf'])->name('credits.downloadPdf'); Route::resource('designs', DesignController::class); // name = (payments. index / create / show / update / destroy / edit Route::post('designs/bulk', [DesignController::class, 'bulk'])->name('designs.bulk'); diff --git a/tests/Feature/CreditTest.php b/tests/Feature/CreditTest.php index 382a73c49300..d3118c1f089d 100644 --- a/tests/Feature/CreditTest.php +++ b/tests/Feature/CreditTest.php @@ -40,6 +40,23 @@ class CreditTest extends TestCase $this->makeTestData(); } + + + public function testQuoteDownloadPDF() + { + $i = $this->credit->invitations->first(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get("/api/v1/credit/{$i->key}/download"); + + $response->assertStatus(200); + $this->assertTrue($response->headers->get('content-type') == 'application/pdf'); + + } + + public function testBulkActions() {