diff --git a/src/Classes/Currency.php b/src/Classes/Currency.php index 8fbecfd..6d8761d 100644 --- a/src/Classes/Currency.php +++ b/src/Classes/Currency.php @@ -121,7 +121,7 @@ public function getMoneyISOCurrency($amount, $currencyCode = null) $number = Number::fromString($amount); - $money = $moneyParser->parse((string)$number, $currency->getCode()); + $money = $moneyParser->parse((string)$number, $currency); // Check for a negative amount. if (! $this->negativeAmountAllowed && $money->isNegative()) { diff --git a/src/Common/Http/Controllers/API/PaymentMethodsController.php b/src/Common/Http/Controllers/API/PaymentMethodsController.php new file mode 100644 index 0000000..da41111 --- /dev/null +++ b/src/Common/Http/Controllers/API/PaymentMethodsController.php @@ -0,0 +1,39 @@ +paymentMethodService->destroy($request, $paymentMethod); + + return apiResponse([], trans('Corals::messages.success.deleted', ['item' => $paymentMethod->last_four])); + } catch (\Exception $e) { + return apiExceptionResponse($e); + } + } +} diff --git a/src/Common/Http/Requests/PaymentMethodRequest.php b/src/Common/Http/Requests/PaymentMethodRequest.php new file mode 100644 index 0000000..e19d72e --- /dev/null +++ b/src/Common/Http/Requests/PaymentMethodRequest.php @@ -0,0 +1,49 @@ +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; + } + +} diff --git a/src/Common/Models/PaymentMethod.php b/src/Common/Models/PaymentMethod.php index 8c841f7..2346221 100644 --- a/src/Common/Models/PaymentMethod.php +++ b/src/Common/Models/PaymentMethod.php @@ -5,11 +5,12 @@ use Corals\Foundation\Models\BaseModel; use Corals\Foundation\Traits\ModelPropertiesTrait; use Corals\Foundation\Transformers\PresentableTrait; +use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Activitylog\Traits\LogsActivity; class PaymentMethod extends BaseModel { - use PresentableTrait, LogsActivity, ModelPropertiesTrait; + use PresentableTrait, LogsActivity, ModelPropertiesTrait, SoftDeletes; protected $casts = [ 'properties' => 'json', diff --git a/src/Common/Policies/PaymentMethodPolicy.php b/src/Common/Policies/PaymentMethodPolicy.php new file mode 100644 index 0000000..7699e15 --- /dev/null +++ b/src/Common/Policies/PaymentMethodPolicy.php @@ -0,0 +1,51 @@ +parent_id === $user->id; + } +} diff --git a/src/Common/Services/PaymentMethodService.php b/src/Common/Services/PaymentMethodService.php new file mode 100644 index 0000000..c35041e --- /dev/null +++ b/src/Common/Services/PaymentMethodService.php @@ -0,0 +1,9 @@ +hasProperty('billing_address')) { - $billing_details = $invoice->getProperty('billing_address'); + $billing_details = $invoice->getProperty('billing_address'); + + if ($invoice->hasProperty('billing_address') && $billing_details) { $customer = $billing_details['first_name'] . ' ' . $billing_details['last_name']; $email = $billing_details['email']; $billing_address = $invoice->display_address($billing_details); diff --git a/src/Common/routes/api.php b/src/Common/routes/api.php index c67e4a5..fff54e1 100644 --- a/src/Common/routes/api.php +++ b/src/Common/routes/api.php @@ -12,3 +12,4 @@ Route::apiResource('tax-classes', 'TaxClassesController', ['as' => 'api.payment', 'only' => ['index']]); Route::apiResource('tax-classes.taxes', 'TaxesController', ['as' => 'api.payment', 'only' => ['index']]); +Route::apiResource('payment-methods', 'PaymentMethodsController')->only('destroy'); diff --git a/src/Providers/PaymentAuthServiceProvider.php b/src/Providers/PaymentAuthServiceProvider.php index 1046712..21731a4 100644 --- a/src/Providers/PaymentAuthServiceProvider.php +++ b/src/Providers/PaymentAuthServiceProvider.php @@ -4,11 +4,13 @@ use Corals\Modules\Payment\Common\Models\Currency; use Corals\Modules\Payment\Common\Models\Invoice; +use Corals\Modules\Payment\Common\Models\PaymentMethod; use Corals\Modules\Payment\Common\Models\Tax; use Corals\Modules\Payment\Common\Models\TaxClass; use Corals\Modules\Payment\Common\Models\Transaction; use Corals\Modules\Payment\Common\Policies\CurrencyPolicy; use Corals\Modules\Payment\Common\Policies\InvoicePolicy; +use Corals\Modules\Payment\Common\Policies\PaymentMethodPolicy; use Corals\Modules\Payment\Common\Policies\TaxClassPolicy; use Corals\Modules\Payment\Common\Policies\TaxPolicy; use Corals\Modules\Payment\Common\Policies\TransactionPolicy; @@ -28,6 +30,7 @@ class PaymentAuthServiceProvider extends ServiceProvider Currency::class => CurrencyPolicy::class, TaxClass::class => TaxClassPolicy::class, Tax::class => TaxPolicy::class, + PaymentMethod::class => PaymentMethodPolicy::class ]; /**