From 0e3c6e286e5ad3d7912a5493a968c9d2ff2d6ef7 Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Wed, 24 Mar 2021 08:19:52 +0100 Subject: [PATCH] - extend setup:dev script - Stripe taxes refactoring - billing subscription fixes --- app/Console/Commands/SetupDevEnvironment.php | 32 ++++++++ .../User/SubscriptionController.php | 27 +++---- app/Models/User.php | 2 +- app/Services/StripeService.php | 4 +- resources/js/views/Upgrade/UpgradeBilling.vue | 79 +++++++++++++------ .../js/views/User/CreatePaymentMethod.vue | 2 +- .../views/vuefilemanager/invoice.blade.php | 4 +- routes/user.php | 2 +- tests/Feature/External/SubscriptionTest.php | 2 +- 9 files changed, 106 insertions(+), 48 deletions(-) diff --git a/app/Console/Commands/SetupDevEnvironment.php b/app/Console/Commands/SetupDevEnvironment.php index 7c2fd2bb..f036e0a4 100644 --- a/app/Console/Commands/SetupDevEnvironment.php +++ b/app/Console/Commands/SetupDevEnvironment.php @@ -824,6 +824,38 @@ class SetupDevEnvironment extends Command [ 'name' => 'purchase_code', 'value' => '26b889eb-3602-4bf2-beb3-3sc378fcf484', + ], + [ + 'name' => 'billing_address', + 'value' => 'Palo Alto 20', + ], + [ + 'name' => 'billing_city', + 'value' => 'Palo Alto', + ], + [ + 'name' => 'billing_country', + 'value' => 'US', + ], + [ + 'name' => 'billing_name', + 'value' => 'VueFileManager Inc.', + ], + [ + 'name' => 'billing_phone_number', + 'value' => '312343141243214', + ], + [ + 'name' => 'billing_postal_code', + 'value' => '43213', + ], + [ + 'name' => 'billing_state', + 'value' => 'California', + ], + [ + 'name' => 'billing_vat_number', + 'value' => '41241241234', ] ])->each(function ($col) { Setting::forceCreate([ diff --git a/app/Http/Controllers/User/SubscriptionController.php b/app/Http/Controllers/User/SubscriptionController.php index 67e1e3d6..c7c94771 100644 --- a/app/Http/Controllers/User/SubscriptionController.php +++ b/app/Http/Controllers/User/SubscriptionController.php @@ -9,34 +9,33 @@ use App\Services\DemoService; use App\Models\User; use App\Services\StripeService; use Auth; +use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Routing\ResponseFactory; +use Illuminate\Http\Response; use Illuminate\Support\Facades\Cache; +use Stripe\SetupIntent; class SubscriptionController extends Controller { private $stripe; + private $demo; - /** - * SubscriptionController constructor. - * @param $payment - */ - public function __construct(StripeService $stripe) + public function __construct() { - $this->stripe = $stripe; + $this->stripe = resolve(StripeService::class); $this->demo = DemoService::class; } /** * Generate setup intent * - * @return \Stripe\SetupIntent + * @return Application|ResponseFactory|Response|SetupIntent */ public function setup_intent() { - return $this->stripe - ->getSetupIntent( - Auth::user() - ); + return response( + $this->stripe->getSetupIntent(Auth::user()), 201 + ); } /** @@ -69,7 +68,7 @@ class SubscriptionController extends Controller * Upgrade account to subscription * * @param StoreUpgradeAccountRequest $request - * @return ResponseFactory|\Illuminate\Http\Response + * @return ResponseFactory|Response */ public function upgrade(StoreUpgradeAccountRequest $request) { @@ -107,7 +106,7 @@ class SubscriptionController extends Controller /** * Cancel Subscription * - * @return ResponseFactory|\Illuminate\Http\Response + * @return ResponseFactory|Response */ public function cancel() { @@ -130,7 +129,7 @@ class SubscriptionController extends Controller /** * Resume Subscription * - * @return ResponseFactory|\Illuminate\Http\Response + * @return ResponseFactory|Response */ public function resume() { diff --git a/app/Models/User.php b/app/Models/User.php index c3a8c014..a48955ea 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -67,7 +67,7 @@ class User extends Authenticatable // Find tax rate $user_tax_rate = $rates->first(function ($item) { - return $item['jurisdiction'] === $this->settings->billing_country && $item['active']; + return $item['country'] === $this->settings->country && $item['active']; }); return $user_tax_rate ? [$user_tax_rate['id']] : []; diff --git a/app/Services/StripeService.php b/app/Services/StripeService.php index 73c1b005..199a7992 100644 --- a/app/Services/StripeService.php +++ b/app/Services/StripeService.php @@ -70,7 +70,7 @@ class StripeService array_push($rates_public, [ 'id' => $rate['id'], 'active' => $rate['active'], - 'jurisdiction' => $rate['jurisdiction'], + 'country' => $rate['country'], 'percentage' => $rate['percentage'], 'plan_price_formatted' => Cashier::formatAmount(round($amount + $tax)), ]); @@ -283,7 +283,7 @@ class StripeService $product = $this->stripe->products()->find($plan['product']); return [ - 'plan' => $plan, + 'plan' => $plan, 'product' => $product, ]; }); diff --git a/resources/js/views/Upgrade/UpgradeBilling.vue b/resources/js/views/Upgrade/UpgradeBilling.vue index e79b3517..8d37789c 100644 --- a/resources/js/views/Upgrade/UpgradeBilling.vue +++ b/resources/js/views/Upgrade/UpgradeBilling.vue @@ -1,7 +1,7 @@