Add reactivate email paths for PostMark

This commit is contained in:
David Bomba 2023-10-23 09:48:05 +11:00
parent 40b56a7133
commit daf66943d4
6 changed files with 6703 additions and 6496 deletions

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers;
use App\Utils\Ninja;
use App\Models\Client;
use App\Models\Account;
use Postmark\PostmarkClient;
use Illuminate\Http\Response;
use App\Factory\ClientFactory;
use App\Filters\ClientFilters;
@ -36,6 +37,7 @@ use App\Http\Requests\Client\CreateClientRequest;
use App\Http\Requests\Client\UpdateClientRequest;
use App\Http\Requests\Client\UploadClientRequest;
use App\Http\Requests\Client\DestroyClientRequest;
use App\Http\Requests\Client\ReactivateClientEmailRequest;
/**
* Class ClientController.
@ -313,4 +315,31 @@ class ClientController extends BaseController
return $this->itemResponse($client->fresh());
}
/**
* Reactivate a client email
*
* @param ReactivateClientEmailRequest $request
* @param string $bounce_id
* @return \Illuminate\Http\JsonResponse
*/
public function reactivateEmail(ReactivateClientEmailRequest $request, string $bounce_id)
{
$postmark = new PostmarkClient(config('services.postmark.token'));
try {
$response = $postmark->activateBounce((int)$bounce_id);
return response()->json(['message' => 'Success'], 200);
}
catch(\Exception $e){
return response()->json(['message' => $e->getMessage(), 400]);
}
}
}

View File

@ -356,6 +356,7 @@ class ProcessPostmarkWebhook implements ShouldQueue
$events = collect($messageDetail->messageevents)->map(function ($event) {
return [
'bounce_id' => $event?->Details?->BounceID ?? '',
'recipient' => $event->Recipient ?? '',
'status' => $event->Type ?? '',
'delivery_message' => $event->Details->DeliveryMessage ?? $event->Details->Summary ?? '',

View File

@ -306,7 +306,10 @@ class Client extends BaseModel implements HasLocalePreference
return $this->hasMany(ClientContact::class)->where('is_primary', true);
}
public function company() :BelongsTo
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function company()
{
return $this->belongsTo(Company::class);
}

File diff suppressed because it is too large Load Diff

View File

@ -655,3 +655,89 @@
description: 'Server error'
default:
$ref: '#/components/responses/default'
/api/v1/reactivate_email/{bounce_id}:
post:
tags:
- clients
summary: 'Removes email suppression of a user in the system'
description: 'Emails are suppressed by PostMark, when they receive a Hard bounce / Spam Complaint. This endpoint allows you to remove the suppression and send emails to the user again.'
operationId: reactivateEmail
parameters:
- $ref: '#/components/parameters/X-API-TOKEN'
- $ref: '#/components/parameters/X-Requested-With'
- $ref: '#/components/parameters/include'
- name: bounce_id
in: path
description: 'The postmark Bounce ID reference'
required: true
schema:
type: string
format: string
example: 123243
responses:
200:
description: 'Success'
headers:
X-MINIMUM-CLIENT-VERSION:
$ref: '#/components/headers/X-MINIMUM-CLIENT-VERSION'
X-RateLimit-Remaining:
$ref: '#/components/headers/X-RateLimit-Remaining'
X-RateLimit-Limit:
$ref: '#/components/headers/X-RateLimit-Limit'
400:
description: 'Postmark exception - generated if the suppression cannot be removed for any reason'
401:
$ref: '#/components/responses/401'
403:
$ref: '#/components/responses/403'
422:
$ref: '#/components/responses/422'
429:
$ref: '#/components/responses/429'
5XX:
description: 'Server error'
default:
$ref: '#/components/responses/default'
/api/v1/clients/{client}/updateTaxData:
post:
tags:
- clients
summary: 'Update tax data'
description: 'Updates the clients tax data - if their address has changed'
operationId: updateClientTaxData
parameters:
- $ref: '#/components/parameters/X-API-TOKEN'
- $ref: '#/components/parameters/X-Requested-With'
- $ref: '#/components/parameters/include'
- name: client
in: path
description: 'The Client Hashed ID reference'
required: true
schema:
type: string
format: string
example: V2J234DFA
responses:
200:
description: 'Success'
headers:
X-MINIMUM-CLIENT-VERSION:
$ref: '#/components/headers/X-MINIMUM-CLIENT-VERSION'
X-RateLimit-Remaining:
$ref: '#/components/headers/X-RateLimit-Remaining'
X-RateLimit-Limit:
$ref: '#/components/headers/X-RateLimit-Limit'
400:
description: 'Postmark exception - generated if the suppression cannot be removed for any reason'
401:
$ref: '#/components/responses/401'
403:
$ref: '#/components/responses/403'
422:
$ref: '#/components/responses/422'
429:
$ref: '#/components/responses/429'
5XX:
description: 'Server error'
default:
$ref: '#/components/responses/default'

View File

@ -164,6 +164,8 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale']
Route::post('clients/{client}/{mergeable_client}/merge', [ClientController::class, 'merge'])->name('clients.merge')->middleware('password_protected');
Route::post('clients/bulk', [ClientController::class, 'bulk'])->name('clients.bulk');
Route::post('reactivate_email/{bounce_id}', [ClientController::class, 'reactivateEmail'])->name('clients.reactivate_email');
Route::post('filters/{entity}', [FilterController::class, 'index'])->name('filters');
Route::resource('client_gateway_tokens', ClientGatewayTokenController::class);