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

757 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
*
* @copyright Copyright (c) 2021. 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;
2020-11-25 15:19:52 +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;
2019-05-03 08:11:43 +02:00
use App\Http\Requests\Payment\ActionPaymentRequest;
use App\Http\Requests\Payment\CreatePaymentRequest;
use App\Http\Requests\Payment\DestroyPaymentRequest;
use App\Http\Requests\Payment\EditPaymentRequest;
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;
2021-03-07 22:32:38 +01:00
use App\Models\Account;
2020-10-28 11:10:49 +01:00
use App\Models\Invoice;
2019-05-03 08:11:43 +02:00
use App\Models\Payment;
2019-05-03 10:28:48 +02:00
use App\Repositories\PaymentRepository;
2019-05-03 09:57:55 +02:00
use App\Transformers\PaymentTransformer;
2020-11-25 15:19:52 +01:00
use App\Utils\Ninja;
2019-05-03 08:11:43 +02:00
use App\Utils\Traits\MakesHash;
2021-02-15 21:58:19 +01:00
use App\Utils\Traits\SavesDocuments;
2019-05-03 08:11:43 +02:00
use Illuminate\Http\Request;
2020-10-28 11:10:49 +01:00
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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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)
{
$payment = PaymentFactory::create(auth()->user()->company()->id, auth()->user()->id);
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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @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 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)
{
$payment = $this->payment_repo->save($request->all(), PaymentFactory::create(auth()->user()->company()->id, auth()->user()->id));
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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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
{
if ($request->entityIsDeleted($payment)) {
return $request->disallowUpdate();
}
$payment = $this->payment_repo->save($request->all(), $payment);
2019-05-03 08:11:43 +02:00
2021-05-06 23:12:07 +02:00
event(new PaymentWasUpdated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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.
*
2019-05-03 08:11:43 +02:00
* @return 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="",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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
*/
public function bulk()
{
$action = request()->input('action');
2019-05-03 08:11:43 +02:00
$ids = request()->input('ids');
$payments = Payment::withTrashed()->find($this->transformKeys($ids));
2019-05-03 08:11:43 +02:00
$payments->each(function ($payment, $key) use ($action) {
if (auth()->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",
2019-10-07 06:19:25 +02:00
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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 ActionPaymentRequest $request
* @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':
$this->payment_repo->restore($payment);
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':
2020-11-02 22:18:02 +01:00
$this->payment_repo->archive($payment);
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':
2020-11-02 22:18:02 +01:00
$this->payment_repo->delete($payment);
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':
//dispatch email to queue
$payment->service()->sendEmail();
if (! $bulk) {
return $this->itemResponse($payment);
}
2019-05-03 08:11:43 +02:00
break;
case 'email_receipt':
$this->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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @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();
// nlog($request->all());
$payment = $payment->refund($request->all());
return $this->itemResponse($payment);
}
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",
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
* @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)
{
2021-03-07 22:32:38 +01:00
if(!$this->checkFeature(Account::FEATURE_DOCUMENTS))
return $this->featureFailure();
2021-02-15 21:58:19 +01:00
if ($request->has('documents'))
$this->saveDocuments($request->file('documents'), $payment);
return $this->itemResponse($payment->fresh());
}
2019-05-03 08:11:43 +02:00
}