-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from coralsio/delete-payment-method
delete payment method
- Loading branch information
Showing
9 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Common/Http/Controllers/API/PaymentMethodsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
|
||
namespace Corals\Modules\Payment\Common\Http\Controllers\API; | ||
|
||
use Corals\Foundation\Http\Controllers\APIBaseController; | ||
use Corals\Modules\Payment\Common\Http\Requests\PaymentMethodRequest; | ||
use Corals\Modules\Payment\Common\Models\PaymentMethod; | ||
use Corals\Modules\Payment\Common\Services\PaymentMethodService; | ||
|
||
|
||
class PaymentMethodsController extends APIBaseController | ||
{ | ||
/** | ||
* PaymentMethodsController constructor. | ||
* @param PaymentMethodService $paymentMethodService | ||
*/ | ||
public function __construct(protected PaymentMethodService $paymentMethodService) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @param PaymentMethodRequest $request | ||
* @param PaymentMethod $paymentMethod | ||
* @return mixed | ||
*/ | ||
public function destroy(PaymentMethodRequest $request, PaymentMethod $paymentMethod) | ||
{ | ||
try { | ||
|
||
$this->paymentMethodService->destroy($request, $paymentMethod); | ||
|
||
return apiResponse([], trans('Corals::messages.success.deleted', ['item' => $paymentMethod->last_four])); | ||
} catch (\Exception $e) { | ||
return apiExceptionResponse($e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Corals\Modules\Payment\Common\Http\Requests; | ||
|
||
use Corals\Foundation\Http\Requests\BaseRequest; | ||
use Corals\Modules\Payment\Common\Models\PaymentMethod; | ||
|
||
class PaymentMethodRequest extends BaseRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
$this->setModel(PaymentMethod::class); | ||
|
||
return $this->isAuthorized(); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
$rules = parent::rules(); | ||
|
||
if ($this->isUpdate() || $this->isStore()) { | ||
$rules = array_merge($rules, [ | ||
|
||
]); | ||
} | ||
|
||
if ($this->isStore()) { | ||
$rules = array_merge($rules, []); | ||
} | ||
|
||
if ($this->isUpdate()) { | ||
$paymentMethod = $this->route('payment_method'); | ||
$rules = array_merge($rules, []); | ||
} | ||
|
||
return $rules; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Corals\Modules\Payment\Common\Policies; | ||
|
||
use Corals\Foundation\Policies\BasePolicy; | ||
use Corals\Modules\Payment\Common\Models\PaymentMethod; | ||
use Corals\User\Models\User; | ||
|
||
class PaymentMethodPolicy extends BasePolicy | ||
{ | ||
protected $administrationPermission = 'Administrations::admin.payment'; | ||
|
||
/** | ||
* @param User $user | ||
* @param PaymentMethod|null $paymentMethod | ||
* @return bool | ||
*/ | ||
public function view(User $user, PaymentMethod $paymentMethod = null) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @param User $user | ||
* @return bool | ||
*/ | ||
public function create(User $user) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @param User $user | ||
* @param PaymentMethod $paymentMethod | ||
* @return bool | ||
*/ | ||
public function update(User $user, PaymentMethod $paymentMethod) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @param User $user | ||
* @param PaymentMethod $paymentMethod | ||
* @return bool | ||
*/ | ||
public function destroy(User $user, PaymentMethod $paymentMethod) | ||
{ | ||
return $paymentMethod->parent_id === $user->id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Corals\Modules\Payment\Common\Services; | ||
|
||
use Corals\Foundation\Services\BaseServiceClass; | ||
|
||
class PaymentMethodService extends BaseServiceClass | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters