1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Controllers/PaymentController.php

781 lines
27 KiB
PHP
Raw Normal View History

2019-05-03 08:11:43 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
2019-05-03 08:11:43 +02:00
namespace App\Http\Controllers;
2023-11-26 08:41:42 +01:00
use App\Events\Payment\PaymentWasUpdated;
2019-05-03 10:28:48 +02:00
use App\Factory\PaymentFactory;
2019-05-03 09:57:55 +02:00
use App\Filters\PaymentFilters;
2023-11-26 08:41:42 +01:00
use App\Http\Requests\Payment\BulkActionPaymentRequest;
use App\Http\Requests\Payment\CreatePaymentRequest;
use App\Http\Requests\Payment\DestroyPaymentRequest;
2019-05-03 08:11:43 +02:00
use App\Http\Requests\Payment\EditPaymentRequest;
2023-11-26 08:41:42 +01:00
use App\Http\Requests\Payment\RefundPaymentRequest;
2019-05-03 08:11:43 +02:00
use App\Http\Requests\Payment\ShowPaymentRequest;
use App\Http\Requests\Payment\StorePaymentRequest;
use App\Http\Requests\Payment\UpdatePaymentRequest;
2021-02-15 21:58:19 +01:00
use App\Http\Requests\Payment\UploadPaymentRequest;
2023-11-26 08:41:42 +01:00
use App\Models\Account;
use App\Models\Payment;
use App\Repositories\PaymentRepository;
use App\Services\Template\TemplateAction;
use App\Transformers\PaymentTransformer;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Response;
2019-05-03 08:11:43 +02:00
/**
* Class PaymentController.
2019-05-03 08:11:43 +02:00
*/
class PaymentController extends BaseController
{
use MakesHash;
2021-02-15 21:58:19 +01:00
use SavesDocuments;
2019-05-03 08:11:43 +02:00
protected $entity_type = Payment::class;
2019-05-03 09:57:55 +02:00
protected $entity_transformer = PaymentTransformer::class;
2019-05-03 08:11:43 +02:00
/**
* @var PaymentRepository
*/
protected $payment_repo;
/**
* PaymentController constructor.
*
2020-10-28 11:10:49 +01:00
* @param PaymentRepository $payment_repo The invoice repo
2019-05-03 08:11:43 +02:00
*/
public function __construct(PaymentRepository $payment_repo)
{
parent::__construct();
$this->payment_repo = $payment_repo;
}
/**
* Show the list of Invoices.
2019-05-03 08:11:43 +02:00
*
2020-10-28 11:10:49 +01:00
* @param PaymentFilters $filters The filters
2019-05-03 08:11:43 +02:00
*
2020-10-28 11:10:49 +01:00
* @return Response
2019-10-07 06:19:25 +02:00
*
*
*
2019-10-07 06:19:25 +02:00
* @OA\Get(
* path="/api/v1/payments",
* operationId="getPayments",
* tags={"payments"},
* summary="Gets a list of payments",
* description="Lists payments, search and filters allow fine grained lists to be generated.
Query parameters can be added to performed more fine grained filtering of the payments, these are handled by the PaymentFilters class which defines the methods available",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="A list of payments",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2019-05-03 08:11:43 +02:00
*/
public function index(PaymentFilters $filters)
{
2019-05-03 09:57:55 +02:00
$payments = Payment::filter($filters);
2019-05-03 08:11:43 +02:00
return $this->listResponse($payments);
}
/**
* Show the form for creating a new resource.
*
2020-10-28 11:10:49 +01:00
* @param CreatePaymentRequest $request The request
2019-05-03 08:11:43 +02:00
*
2020-10-28 11:10:49 +01:00
* @return Response
2019-10-07 06:19:25 +02:00
*
*
*
2019-10-07 06:19:25 +02:00
* @OA\Get(
* path="/api/v1/payments/create",
* operationId="getPaymentsCreate",
* tags={"payments"},
* summary="Gets a new blank Payment object",
* description="Returns a blank object with default values",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Response(
* response=200,
* description="A blank Payment object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2019-05-03 08:11:43 +02:00
*/
public function create(CreatePaymentRequest $request)
{
2023-08-04 09:12:21 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
$payment = PaymentFactory::create($user->company()->id, $user->id);
$payment->date = now()->addSeconds($user->company()->utc_offset())->format('Y-m-d');
2019-05-03 08:11:43 +02:00
return $this->itemResponse($payment);
}
/**
* Store a newly created resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param StorePaymentRequest $request The request
2019-05-03 08:11:43 +02:00
*
2020-10-28 11:10:49 +01:00
* @return Response
2019-10-07 06:19:25 +02:00
*
*
*
* @OA\Post(
* path="/api/v1/payments",
* operationId="storePayment",
* tags={"payments"},
* summary="Adds a Payment",
* description="Adds an Payment to the system",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\RequestBody(
* description="The payment request",
* required=true,
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
2019-10-07 06:19:25 +02:00
* @OA\Response(
* response=200,
* description="Returns the saved Payment object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2019-05-03 08:11:43 +02:00
*/
public function store(StorePaymentRequest $request)
{
2023-08-04 09:12:21 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
$payment = $this->payment_repo->save($request->all(), PaymentFactory::create($user->company()->id, $user->id));
2019-05-03 08:11:43 +02:00
2023-02-01 05:00:45 +01:00
event('eloquent.created: App\Models\Payment', $payment);
2019-05-03 08:11:43 +02:00
return $this->itemResponse($payment);
}
/**
* Display the specified resource.
*
2020-10-28 11:10:49 +01:00
* @param ShowPaymentRequest $request The request
* @param Payment $payment The invoice
2019-05-03 08:11:43 +02:00
*
2020-10-28 11:10:49 +01:00
* @return Response
2019-10-07 06:19:25 +02:00
*
*
* @OA\Get(
* path="/api/v1/payments/{id}",
* operationId="showPayment",
* tags={"payments"},
* summary="Shows an Payment",
* description="Displays an Payment by id",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the Payment object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2019-05-03 08:11:43 +02:00
*/
2019-05-03 10:28:48 +02:00
public function show(ShowPaymentRequest $request, Payment $payment)
2019-05-03 08:11:43 +02:00
{
return $this->itemResponse($payment);
}
/**
* Show the form for editing the specified resource.
*
2020-10-28 11:10:49 +01:00
* @param EditPaymentRequest $request The request
* @param Payment $payment The invoice
2019-05-03 08:11:43 +02:00
*
2020-10-28 11:10:49 +01:00
* @return Response
2019-10-07 06:19:25 +02:00
*
*
2019-10-07 06:19:25 +02:00
* @OA\Get(
* path="/api/v1/payments/{id}/edit",
* operationId="editPayment",
* tags={"payments"},
* summary="Shows an Payment for editting",
* description="Displays an Payment by id",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the Payment object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2019-05-03 08:11:43 +02:00
*/
2019-05-03 10:28:48 +02:00
public function edit(EditPaymentRequest $request, Payment $payment)
2019-05-03 08:11:43 +02:00
{
return $this->itemResponse($payment);
}
2019-05-03 08:11:43 +02:00
/**
* Update the specified resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param UpdatePaymentRequest $request The request
* @param Payment $payment The invoice
2019-05-03 08:11:43 +02:00
*
2020-10-28 11:10:49 +01:00
* @return Response
2019-10-07 06:19:25 +02:00
*
*
2019-10-07 06:19:25 +02:00
* @OA\Put(
* path="/api/v1/payments/{id}",
* operationId="updatePayment",
* tags={"payments"},
* summary="Updates an Payment",
* description="Handles the updating of an Payment by id",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the Payment object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2019-05-03 08:11:43 +02:00
*/
2019-05-03 10:28:48 +02:00
public function update(UpdatePaymentRequest $request, Payment $payment)
2019-05-03 08:11:43 +02:00
{
2023-08-04 09:12:21 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
if ($request->entityIsDeleted($payment)) {
return $request->disallowUpdate();
}
$payment = $this->payment_repo->save($request->all(), $payment);
2019-05-03 08:11:43 +02:00
2023-08-04 09:12:21 +02:00
event(new PaymentWasUpdated($payment, $payment->company, Ninja::eventVars($user->id)));
2023-02-01 05:00:45 +01:00
event('eloquent.updated: App\Models\Payment', $payment);
2019-05-03 08:11:43 +02:00
return $this->itemResponse($payment);
}
/**
* Remove the specified resource from storage.
*
2020-10-28 11:10:49 +01:00
* @param DestroyPaymentRequest $request
* @param Payment $payment
2019-05-03 08:11:43 +02:00
*
2020-10-28 11:10:49 +01:00
* @return Response
2019-10-07 06:19:25 +02:00
*
*
2020-10-28 11:10:49 +01:00
* @throws \Exception
2019-10-07 06:19:25 +02:00
* @OA\Delete(
* path="/api/v1/payments/{id}",
* operationId="deletePayment",
* tags={"payments"},
* summary="Deletes a Payment",
* description="Handles the deletion of an Payment by id",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns a HTTP status",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2019-05-03 08:11:43 +02:00
*/
2019-05-03 10:28:48 +02:00
public function destroy(DestroyPaymentRequest $request, Payment $payment)
2019-05-03 08:11:43 +02:00
{
2020-11-15 22:23:20 +01:00
$this->payment_repo->delete($payment);
2019-05-03 08:11:43 +02:00
return $this->itemResponse($payment);
2019-05-03 08:11:43 +02:00
}
/**
* Perform bulk actions on the list view.
*
2023-07-26 04:59:36 +02:00
* @return \Illuminate\Support\Collection
2019-10-07 06:19:25 +02:00
*
*
2019-10-07 06:19:25 +02:00
* @OA\Post(
* path="/api/v1/payments/bulk",
* operationId="bulkPayments",
* tags={"payments"},
* summary="Performs bulk actions on an array of payments",
* description="",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/index"),
* @OA\RequestBody(
* description="User credentials",
* required=true,
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="array",
* @OA\Items(
* type="integer",
* description="Array of hashed IDs to be bulk 'actioned",
* example="[0,1,2,3]",
* ),
* )
* )
* ),
* @OA\Response(
* response=200,
2019-10-07 06:57:14 +02:00
* description="The Payment response",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
2019-10-07 06:57:14 +02:00
* @OA\JsonContent(ref="#/components/schemas/Payment"),
2019-10-07 06:19:25 +02:00
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2019-05-03 08:11:43 +02:00
*/
2023-11-18 02:46:03 +01:00
public function bulk(BulkActionPaymentRequest $request)
2019-05-03 08:11:43 +02:00
{
2023-08-04 09:12:21 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
2023-11-18 02:46:03 +01:00
$action = $request->input('action');
2023-11-18 02:46:03 +01:00
$ids = $request->input('ids');
$payments = Payment::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
if (!$payments) {
return response()->json(['message' => ctrans('texts.record_not_found')]);
}
if($action == 'template' && $user->can('view', $payments->first())) {
$hash_or_response = request()->boolean('send_email') ? 'email sent' : \Illuminate\Support\Str::uuid();
2023-11-26 08:41:42 +01:00
nlog($payments->pluck('hashed_id')->toArray());
2023-11-18 02:46:03 +01:00
TemplateAction::dispatch(
2023-11-18 08:45:26 +01:00
$payments->pluck('hashed_id')->toArray(),
2023-11-18 02:46:03 +01:00
$request->template_id,
2023-11-18 08:28:28 +01:00
Payment::class,
2023-11-18 02:46:03 +01:00
$user->id,
$user->company(),
$user->company()->db,
$hash_or_response,
$request->boolean('send_email')
);
return response()->json(['message' => $hash_or_response], 200);
}
2019-05-03 08:11:43 +02:00
2023-08-04 09:12:21 +02:00
$payments->each(function ($payment, $key) use ($action, $user) {
if ($user->can('edit', $payment)) {
2020-11-02 22:18:02 +01:00
$this->performAction($payment, $action, true);
}
2019-05-03 08:11:43 +02:00
});
return $this->listResponse(Payment::withTrashed()->whereIn('id', $this->transformKeys($ids)));
2019-05-03 08:11:43 +02:00
}
2019-10-07 06:19:25 +02:00
/**
* Payment Actions.
2019-10-07 06:19:25 +02:00
*
*
2019-10-07 06:19:25 +02:00
* @OA\Get(
* path="/api/v1/payments/{id}/{action}",
* operationId="actionPayment",
* tags={"payments"},
* summary="Performs a custom action on an Payment",
* description="Performs a custom action on an Payment.
2020-10-28 11:10:49 +01:00
The current range of actions are as follows
- clone_to_Payment
- clone_to_quote
- history
- delivery_note
- mark_paid
- download
- archive
- delete
- email",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Parameter(
* name="action",
* in="path",
* description="The action string to be performed",
* example="clone_to_quote",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
2019-10-07 06:19:25 +02:00
* @OA\Response(
* response=200,
* description="Returns the Payment object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
2019-10-07 06:19:25 +02:00
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
2019-10-07 06:19:25 +02:00
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
2020-10-28 11:10:49 +01:00
* @param Payment $payment
* @param $action
2019-10-07 06:19:25 +02:00
*/
2020-11-02 22:18:02 +01:00
public function performAction(Payment $payment, $action, $bulk = false)
2019-05-03 08:11:43 +02:00
{
switch ($action) {
2020-11-02 22:18:02 +01:00
case 'restore':
2023-02-16 02:36:09 +01:00
$this->payment_repo->restore($payment);
2020-11-02 22:18:02 +01:00
if (! $bulk) {
return $this->itemResponse($payment);
2020-11-02 22:18:02 +01:00
}
2019-05-03 08:11:43 +02:00
break;
case 'archive':
2023-02-16 02:36:09 +01:00
$this->payment_repo->archive($payment);
2020-11-02 22:18:02 +01:00
if (! $bulk) {
return $this->itemResponse($payment);
2020-11-02 22:18:02 +01:00
}
// code...
2019-05-03 08:11:43 +02:00
break;
case 'delete':
2023-02-16 02:36:09 +01:00
$this->payment_repo->delete($payment);
2020-11-02 22:18:02 +01:00
if (! $bulk) {
return $this->itemResponse($payment);
2020-11-02 22:18:02 +01:00
}
// code...
2019-05-03 08:11:43 +02:00
break;
case 'email':
$payment->service()->sendEmail();
if (! $bulk) {
return $this->itemResponse($payment);
}
2019-05-03 08:11:43 +02:00
break;
case 'email_receipt':
2023-02-21 23:38:27 +01:00
$payment->service()->sendEmail();
2019-05-03 08:11:43 +02:00
if (! $bulk) {
return $this->itemResponse($payment);
}
break;
2019-05-03 08:11:43 +02:00
default:
// code...
2019-05-03 08:11:43 +02:00
break;
}
}
/**
* Store a newly created refund.
*
2020-10-28 11:10:49 +01:00
* @param RefundPaymentRequest $request The request
*
2020-10-28 11:10:49 +01:00
* @return Response
*
*
*
* @OA\Post(
* path="/api/v1/payments/refund",
* operationId="storeRefund",
* tags={"payments"},
* summary="Adds a Refund",
* description="Adds an Refund to the system",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\RequestBody(
* description="The refund request",
* required=true,
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=200,
* description="Returns the saved Payment object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function refund(RefundPaymentRequest $request)
{
$payment = $request->payment();
$payment = $payment->refund($request->all());
return $this->itemResponse($payment);
}
2021-02-15 21:58:19 +01:00
/**
2021-02-15 21:58:19 +01:00
* Update the specified resource in storage.
*
* @param UploadPaymentRequest $request
* @param Payment $payment
* @return Response
*
*
*
* @OA\Put(
* path="/api/v1/payments/{id}/upload",
* operationId="uploadPayment",
* tags={"payments"},
* summary="Uploads a document to a payment",
* description="Handles the uploading of a document to a payment",
2023-02-10 10:21:10 +01:00
* @OA\Parameter(ref="#/components/parameters/X-API-TOKEN"),
2021-02-15 21:58:19 +01:00
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
* @OA\Parameter(ref="#/components/parameters/include"),
* @OA\Parameter(
* name="id",
* in="path",
* description="The Payment Hashed ID",
* example="D2J234DFA",
* required=true,
* @OA\Schema(
* type="string",
* format="string",
* ),
* ),
* @OA\Response(
* response=200,
* description="Returns the Payment object",
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
* @OA\JsonContent(ref="#/components/schemas/Payment"),
* ),
* @OA\Response(
* response=422,
* description="Validation error",
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
*
* ),
* @OA\Response(
* response="default",
* description="Unexpected Error",
* @OA\JsonContent(ref="#/components/schemas/Error"),
* ),
* )
*/
public function upload(UploadPaymentRequest $request, Payment $payment)
{
if (! $this->checkFeature(Account::FEATURE_DOCUMENTS)) {
2021-03-07 22:32:38 +01:00
return $this->featureFailure();
}
2021-03-07 22:32:38 +01:00
if ($request->has('documents')) {
$this->saveDocuments($request->file('documents'), $payment, $request->input('is_public', true));
}
2021-02-15 21:58:19 +01:00
return $this->itemResponse($payment->fresh());
}
2019-05-03 08:11:43 +02:00
}