1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Http/Controllers/PaymentApiController.php

152 lines
3.8 KiB
PHP
Raw Normal View History

2015-03-17 02:30:56 +01:00
<?php namespace App\Http\Controllers;
2015-03-16 22:45:25 +01:00
2016-02-03 11:06:49 +01:00
use App\Ninja\Mailers\ContactMailer;
use Input;
2015-04-08 20:19:58 +02:00
use Response;
use App\Models\Payment;
use App\Models\Invoice;
use App\Ninja\Repositories\PaymentRepository;
2016-05-02 10:38:01 +02:00
use App\Http\Requests\UpdatePaymentRequest;
use App\Http\Requests\CreatePaymentAPIRequest;
2015-03-16 22:45:25 +01:00
2015-11-27 13:55:28 +01:00
class PaymentApiController extends BaseAPIController
2015-03-16 22:45:25 +01:00
{
protected $paymentRepo;
2016-05-01 22:55:13 +02:00
protected $entityType = ENTITY_PAYMENT;
2016-02-03 11:06:49 +01:00
public function __construct(PaymentRepository $paymentRepo, ContactMailer $contactMailer)
2015-03-16 22:45:25 +01:00
{
2016-03-02 15:36:46 +01:00
parent::__construct();
2015-11-27 13:55:28 +01:00
2015-03-16 22:45:25 +01:00
$this->paymentRepo = $paymentRepo;
2016-02-03 11:06:49 +01:00
$this->contactMailer = $contactMailer;
2015-03-16 22:45:25 +01:00
}
2015-11-08 22:53:13 +01:00
/**
* @SWG\Get(
* path="/payments",
* tags={"payment"},
* summary="List of payments",
* @SWG\Response(
* response=200,
* description="A list with payments",
* @SWG\Schema(type="array", @SWG\Items(ref="#/definitions/Payment"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2015-11-27 13:55:28 +01:00
public function index()
2015-03-16 22:45:25 +01:00
{
$payments = Payment::scope()
2016-05-01 22:55:13 +02:00
->withTrashed()
2016-05-03 22:02:29 +02:00
->with(['invoice'])
2016-05-01 22:55:13 +02:00
->orderBy('created_at', 'desc');
2015-09-07 11:07:55 +02:00
2016-05-02 10:38:01 +02:00
return $this->listResponse($payments);
2015-03-16 22:45:25 +01:00
}
2016-05-01 22:55:13 +02:00
/**
* @SWG\Put(
* path="/payments/{payment_id",
* summary="Update a payment",
* tags={"payment"},
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Payment")
* ),
* @SWG\Response(
* response=200,
* description="Update payment",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Payment"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2016-05-02 10:38:01 +02:00
public function update(UpdatePaymentRequest $request, $publicId)
2016-05-01 22:55:13 +02:00
{
2016-05-02 10:38:01 +02:00
if ($request->action) {
return $this->handleAction($request);
2016-05-01 22:55:13 +02:00
}
2016-05-02 10:38:01 +02:00
$data = $request->input();
$data['public_id'] = $publicId;
$payment = $this->paymentRepo->save($data, $request->entity());
2016-02-17 11:50:52 +01:00
2016-05-02 10:38:01 +02:00
return $this->itemResponse($payment);
2016-05-01 22:55:13 +02:00
}
2016-02-07 09:30:47 +01:00
2015-11-08 22:53:13 +01:00
/**
* @SWG\Post(
* path="/payments",
* summary="Create a payment",
* tags={"payment"},
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Payment")
* ),
* @SWG\Response(
* response=200,
* description="New payment",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Payment"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2016-05-02 10:38:01 +02:00
public function store(CreatePaymentAPIRequest $request)
{
2016-05-02 10:38:01 +02:00
$payment = $this->paymentRepo->save($request->input());
2015-11-27 13:55:28 +01:00
2016-02-03 11:06:49 +01:00
if (Input::get('email_receipt')) {
$this->contactMailer->sendPaymentConfirmation($payment);
}
2016-05-02 10:38:01 +02:00
return $this->itemResponse($payment);
}
2016-02-07 11:24:21 +01:00
2016-05-01 22:55:13 +02:00
/**
* @SWG\Delete(
* path="/payments/{payment_id}",
* summary="Delete a payment",
* tags={"payment"},
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Payment")
* ),
* @SWG\Response(
* response=200,
* description="Delete payment",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Payment"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
2016-05-03 10:53:00 +02:00
public function destroy(UpdatePaymentRequest $request)
2016-05-01 22:55:13 +02:00
{
2016-05-03 10:53:00 +02:00
$payment = $request->entity();
$this->clientRepo->delete($payment);
2016-02-07 11:24:21 +01:00
2016-05-03 10:53:00 +02:00
return $this->itemResponse($payment);
2016-05-01 22:55:13 +02:00
}
2016-05-03 10:53:00 +02:00
2015-03-16 22:45:25 +01:00
}