@fleetbase/storefront-engine 0.3.27 → 0.3.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/composer.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbase/storefront-api",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "keywords": [
6
6
  "fleetbase-extension",
package/extension.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "Storefront",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "repository": "https://github.com/fleetbase/storefront",
6
6
  "license": "AGPL-3.0-or-later",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fleetbase/storefront-engine",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
4
4
  "description": "Headless Commerce & Marketplace Extension for Fleetbase",
5
5
  "fleetbase": {
6
6
  "route": "storefront",
@@ -176,8 +176,8 @@ class CustomerController extends Controller
176
176
  }
177
177
 
178
178
  // verify code
179
- $isVerified = VerificationCode::where(['code' => $code, 'for' => 'storefront_create_customer', 'meta->identity' => $identity])->exists();
180
- if (!$isVerified) {
179
+ $verificationCode = VerificationCode::where(['code' => $code, 'for' => 'storefront_create_customer', 'meta->identity' => $identity])->exists();
180
+ if (!$verificationCode) {
181
181
  return response()->apiError('Invalid verification code provided!');
182
182
  }
183
183
 
@@ -802,4 +802,99 @@ class CustomerController extends Controller
802
802
  return response()->apiError($e->getMessage());
803
803
  }
804
804
  }
805
+
806
+ public function startAccountClosure(Request $request)
807
+ {
808
+ $about = Storefront::about(['company_uuid']);
809
+ if (!$about) {
810
+ return response()->apiError('Storefront not found.');
811
+ }
812
+
813
+ $customer = Storefront::getCustomerFromToken();
814
+ if (!$customer) {
815
+ return response()->apiError('Not authorized to view customers places');
816
+ }
817
+
818
+ // Get the user account for the contact/customer
819
+ $user = User::where(['uuid' => $customer->user_uuid])->first();
820
+ if (!$user) {
821
+ return response()->apiError('Customer user account not found.');
822
+ }
823
+
824
+ // Check for phone or email
825
+ if (!$user->phone && !$user->email) {
826
+ return response()->apiError('Customer account must have a valid email or phone number linked.');
827
+ }
828
+
829
+ // Send account closure confirmation with code
830
+ try {
831
+ if ($user->phone) {
832
+ VerificationCode::generateSmsVerificationFor($user, 'storefront_account_closure', [
833
+ 'messageCallback' => function ($verification) use ($about) {
834
+ return "Your {$about->name} account closure verification code is {$verification->code}";
835
+ },
836
+ 'meta' => ['identity' => $user->phone],
837
+ ]);
838
+ } elseif ($user->email) {
839
+ VerificationCode::generateEmailVerificationFor($user, 'storefront_account_closure', [
840
+ 'subject' => $about->name . ' account closure request',
841
+ 'messageCallback' => function ($verification) use ($about) {
842
+ return "Your {$about->name} account closure verification code is {$verification->code}";
843
+ },
844
+ 'meta' => ['identity' => $user->email],
845
+ ]);
846
+ }
847
+
848
+ return response()->json(['status' => 'OK']);
849
+ } catch (\Exception $e) {
850
+ return response()->apiError($e->getMessage());
851
+ }
852
+
853
+ return response()->apiError('An uknown error occured attempting to close customer account.');
854
+ }
855
+
856
+ public function confirmAccountClosure(Request $request)
857
+ {
858
+ $code = $request->input('code');
859
+ $about = Storefront::about(['company_uuid']);
860
+ if (!$about) {
861
+ return response()->apiError('Storefront not found.');
862
+ }
863
+
864
+ $customer = Storefront::getCustomerFromToken();
865
+ if (!$customer) {
866
+ return response()->apiError('Not authorized to view customers places');
867
+ }
868
+
869
+ // Get the user account for the contact/customer
870
+ $user = User::where(['uuid' => $customer->user_uuid])->first();
871
+ if (!$user) {
872
+ return response()->apiError('Customer user account not found.');
873
+ }
874
+
875
+ // Get verification identity
876
+ $identity = $user->phone ?? $user->email;
877
+
878
+ // verify account closure code
879
+ $verificationCode = VerificationCode::where(['code' => $code, 'for' => 'storefront_account_closure', 'meta->identity' => $identity])->exists();
880
+ if (!$verificationCode && $code !== config('storefront.storefront_app.bypass_verification_code')) {
881
+ return response()->apiError('Invalid verification code provided!');
882
+ }
883
+
884
+ try {
885
+ // If the user type is `contact` or `customer` delete the user account
886
+ if ($user->isType(['contact', 'customer'])) {
887
+ $user->delete();
888
+ }
889
+
890
+ // Delete the customer
891
+ $customer->delete();
892
+
893
+ return response()->json(['status' => 'OK']);
894
+ } catch (\Exception $e) {
895
+ return response()->apiError($e->getMessage());
896
+ }
897
+
898
+ return response()->apiError('An uknown error occured attempting to close customer account.');
899
+ }
805
900
  }
@@ -113,6 +113,8 @@ Route::prefix(config('storefront.api.routing.prefix', 'storefront'))->namespace(
113
113
  $router->post('request-creation-code', 'CustomerController@requestCustomerCreationCode');
114
114
  $router->post('stripe-ephemeral-key', 'CustomerController@getStripeEphemeralKey');
115
115
  $router->post('stripe-setup-intent', 'CustomerController@getStripeSetupIntent');
116
+ $router->post('account-closure', 'CustomerController@startAccountClosure');
117
+ $router->post('confirm-account-closure', 'CustomerController@confirmAccountClosure');
116
118
  });
117
119
 
118
120
  // hotfix! storefront-app sending customer update to /contacts/ route