From c872a712a7b0798eeabc13e79dca280357bc6e7f Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 19 Jun 2024 22:44:49 -0400 Subject: [PATCH 01/67] refact: entity interactions --- .../EntityInteractionsBuilder.php | 26 ++++++++++ graphql/schemas/Guild/people.graphql | 5 ++ graphql/schemas/Social/interactions.graphql | 11 ++++- .../schemas/Social/usersInteractions.graphql | 4 +- src/Domains/Guild/Customers/Models/People.php | 2 + .../Actions/CreateEntityInteraction.php | 3 ++ .../Actions/CreateEntityInteractionAction.php | 48 +++++++++++++++++++ .../Actions/CreateInteraction.php | 2 - .../DataTransferObject/EntityInteraction.php | 19 ++++++++ .../Models/EntityInteractions.php | 3 +- .../Interactions/Traits/LikableTrait.php | 4 +- .../Traits/SocialInteractionsTrait.php | 45 +++++++++++++++++ tests/Social/Integration/InteractionsTest.php | 12 +++++ 13 files changed, 176 insertions(+), 8 deletions(-) create mode 100644 app/GraphQL/Social/Builders/Interactions/EntityInteractionsBuilder.php create mode 100644 src/Domains/Social/Interactions/Actions/CreateEntityInteractionAction.php create mode 100644 src/Domains/Social/Interactions/DataTransferObject/EntityInteraction.php diff --git a/app/GraphQL/Social/Builders/Interactions/EntityInteractionsBuilder.php b/app/GraphQL/Social/Builders/Interactions/EntityInteractionsBuilder.php new file mode 100644 index 000000000..a240d57c5 --- /dev/null +++ b/app/GraphQL/Social/Builders/Interactions/EntityInteractionsBuilder.php @@ -0,0 +1,26 @@ +uuid) + ->where('entity_namespace', '=', $root::class) + ->where('is_deleted', '=', StateEnums::NO->getValue()); + } +} diff --git a/graphql/schemas/Guild/people.graphql b/graphql/schemas/Guild/people.graphql index 5c0f972ed..656ad62e8 100644 --- a/graphql/schemas/Guild/people.graphql +++ b/graphql/schemas/Guild/people.graphql @@ -25,6 +25,11 @@ type People { defaultCount: 25 builder: "App\\GraphQL\\Ecosystem\\Queries\\CustomFields\\CustomFieldQuery@getAllByGraphType" ) + interactions: [EntityInteraction!]! + @paginate( + defaultCount: 25 + builder: "App\\GraphQL\\Social\\Builders\\Interactions\\EntityInteractionsBuilder@getAll" + ) tags: [Tag!] @paginate( defaultCount: 25 diff --git a/graphql/schemas/Social/interactions.graphql b/graphql/schemas/Social/interactions.graphql index a9f3d985d..a3d586420 100644 --- a/graphql/schemas/Social/interactions.graphql +++ b/graphql/schemas/Social/interactions.graphql @@ -11,7 +11,7 @@ type Interactions { dislike: Boolean } -type InteractionType { +type AooInteractionType { name: String! title: String! description: String @@ -26,6 +26,15 @@ type EntityInteractions { entity: Mixed @method(name: "interactedEntityData") } +type EntityInteraction { + interacted_entity_id: Mixed! + interacted_entity_namespace: String! + entity: Mixed! @method(name: "interactedEntityData") + interaction: AooInteractionType! + notes: Mixed + created_at: Date! +} + extend type Mutation @guardByAuthOrCompany { likeEntity(input: LikeEntityInput!): Boolean! @field( diff --git a/graphql/schemas/Social/usersInteractions.graphql b/graphql/schemas/Social/usersInteractions.graphql index 5b4f8bf3d..cf88ce92a 100644 --- a/graphql/schemas/Social/usersInteractions.graphql +++ b/graphql/schemas/Social/usersInteractions.graphql @@ -18,7 +18,7 @@ type Interaction { count: Int } -type EntityInteraction { +type UserEntityInteraction { entity_id: ID! entity_namespace: String! interactions: JSON @@ -61,7 +61,7 @@ extend type Query { getUserInteraction( entity_id: ID! entity_namespace: String! - ): EntityInteraction + ): UserEntityInteraction @field( resolver: "App\\GraphQL\\Social\\Queries\\UsersInteractions\\GetUserInteraction" ) diff --git a/src/Domains/Guild/Customers/Models/People.php b/src/Domains/Guild/Customers/Models/People.php index 225f60a78..6d6f332a4 100644 --- a/src/Domains/Guild/Customers/Models/People.php +++ b/src/Domains/Guild/Customers/Models/People.php @@ -10,6 +10,7 @@ use Kanvas\Guild\Customers\Factories\PeopleFactory; use Kanvas\Guild\Models\BaseModel; use Kanvas\Guild\Organizations\Models\Organization; +use Kanvas\Social\Interactions\Traits\SocialInteractionsTrait; use Kanvas\Social\Tags\Traits\HasTagsTrait; use Kanvas\Workflow\Traits\CanUseWorkflow; use Laravel\Scout\Searchable; @@ -40,6 +41,7 @@ class People extends BaseModel use Searchable; use HasTagsTrait; use CanUseWorkflow; + use SocialInteractionsTrait; protected $table = 'peoples'; protected $guarded = []; diff --git a/src/Domains/Social/Interactions/Actions/CreateEntityInteraction.php b/src/Domains/Social/Interactions/Actions/CreateEntityInteraction.php index f5e843b6d..addf387c5 100644 --- a/src/Domains/Social/Interactions/Actions/CreateEntityInteraction.php +++ b/src/Domains/Social/Interactions/Actions/CreateEntityInteraction.php @@ -10,6 +10,9 @@ use Kanvas\Social\Interactions\DataTransferObject\LikeEntityInput; use Kanvas\Social\Interactions\Models\EntityInteractions; +/** + * @deprecated v1.0 + */ class CreateEntityInteraction { public function __construct( diff --git a/src/Domains/Social/Interactions/Actions/CreateEntityInteractionAction.php b/src/Domains/Social/Interactions/Actions/CreateEntityInteractionAction.php new file mode 100644 index 000000000..45197fcf7 --- /dev/null +++ b/src/Domains/Social/Interactions/Actions/CreateEntityInteractionAction.php @@ -0,0 +1,48 @@ +entityInteractionData->interaction, + $this->app, + ucfirst($this->entityInteractionData->interaction), + ) + ); + + $interaction = $createInteractions->execute(); + + return EntityInteractions::updateOrCreate( + [ + 'entity_id' => $this->entityInteractionData->entity->uuid, + 'entity_namespace' => get_class($this->entityInteractionData->entity), + 'interactions_id' => $interaction->getId(), + 'interacted_entity_id' => $this->entityInteractionData->interactedEntity->uuid, + 'interacted_entity_namespace' => get_class($this->entityInteractionData->interactedEntity), + ], + [ + 'notes' => $this->entityInteractionData->note, + 'is_deleted' => StateEnums::NO->getValue(), + ] + ); + } +} diff --git a/src/Domains/Social/Interactions/Actions/CreateInteraction.php b/src/Domains/Social/Interactions/Actions/CreateInteraction.php index 8d14f0cb0..59bdfb011 100644 --- a/src/Domains/Social/Interactions/Actions/CreateInteraction.php +++ b/src/Domains/Social/Interactions/Actions/CreateInteraction.php @@ -16,8 +16,6 @@ public function __construct( /** * execute. - * - * @return Interactions */ public function execute(): Interactions { diff --git a/src/Domains/Social/Interactions/DataTransferObject/EntityInteraction.php b/src/Domains/Social/Interactions/DataTransferObject/EntityInteraction.php new file mode 100644 index 000000000..4893a1d42 --- /dev/null +++ b/src/Domains/Social/Interactions/DataTransferObject/EntityInteraction.php @@ -0,0 +1,19 @@ +interacted_entity_namespace::notDeleted() - ->where('uuid', $this->interacted_entity_id)->first(); + ->where('uuid', $this->interacted_entity_id) + ->first(); } /** diff --git a/src/Domains/Social/Interactions/Traits/LikableTrait.php b/src/Domains/Social/Interactions/Traits/LikableTrait.php index fdb0db133..6aa6b9686 100644 --- a/src/Domains/Social/Interactions/Traits/LikableTrait.php +++ b/src/Domains/Social/Interactions/Traits/LikableTrait.php @@ -24,7 +24,7 @@ public function like(Model $entity, ?string $note = null): UsersInteractions|Ent 'interactions_id' => $interaction->getId(), 'entity_id' => $entity->getId(), 'entity_namespace' => $entity::class, - 'is_deleted' => 0 + 'is_deleted' => 0, ], [ 'notes' => $note, ]); @@ -36,7 +36,7 @@ public function like(Model $entity, ?string $note = null): UsersInteractions|Ent 'interactions_id' => $interaction->getId(), 'interacted_entity_id' => $entity->getId(), 'interacted_entity_namespace' => $entity::class, - 'is_deleted' => 0 + 'is_deleted' => 0, ], [ 'notes' => $note, ]); diff --git a/src/Domains/Social/Interactions/Traits/SocialInteractionsTrait.php b/src/Domains/Social/Interactions/Traits/SocialInteractionsTrait.php index 43a3801b5..6c9abe24b 100644 --- a/src/Domains/Social/Interactions/Traits/SocialInteractionsTrait.php +++ b/src/Domains/Social/Interactions/Traits/SocialInteractionsTrait.php @@ -4,13 +4,58 @@ namespace Kanvas\Social\Interactions\Traits; +use Illuminate\Database\Eloquent\Model; +use Kanvas\Social\Interactions\Actions\CreateEntityInteractionAction; +use Kanvas\Social\Interactions\Actions\CreateInteraction; +use Kanvas\Social\Interactions\DataTransferObject\EntityInteraction; +use Kanvas\Social\Interactions\DataTransferObject\Interaction; use Kanvas\Social\Interactions\DataTransferObject\LikeEntityInput; +use Kanvas\Social\Interactions\Models\EntityInteractions; use Kanvas\Social\Interactions\Models\Interactions; +use Kanvas\Social\Interactions\Models\UsersInteractions; use Kanvas\Social\Interactions\Repositories\EntityInteractionsRepository; use Kanvas\Users\Enums\UserConfigEnum; +use Kanvas\Users\Models\Users; trait SocialInteractionsTrait { + use LikableTrait; + + public function addInteraction(Model $entity, string $interaction, ?string $note = null): UsersInteractions|EntityInteractions + { + if ($this instanceof Users) { + $interaction = ( + new CreateInteraction( + new Interaction( + $interaction, + $this->app, + $interaction + ) + ))->execute(); + + return UsersInteractions::firstOrCreate([ + 'users_id' => $this->getId(), + 'interactions_id' => $interaction->getId(), + 'entity_id' => $entity->getId(), + 'entity_namespace' => $entity::class, + 'is_deleted' => 0, + ], [ + 'notes' => $note, + ]); + } + + return ( + new CreateEntityInteractionAction( + (new EntityInteraction( + $this, + $entity, + $interaction, + $note + )), + $this->app + ))->execute(); + } + /** * Given a visitorInput get the social interactions for the entity. * diff --git a/tests/Social/Integration/InteractionsTest.php b/tests/Social/Integration/InteractionsTest.php index 5e7617b2b..89ed29a53 100644 --- a/tests/Social/Integration/InteractionsTest.php +++ b/tests/Social/Integration/InteractionsTest.php @@ -5,6 +5,7 @@ namespace Tests\Social\Integration; use Kanvas\Apps\Models\Apps; +use Kanvas\Guild\Customers\Models\People; use Kanvas\Inventory\Products\Models\Products; use Kanvas\Inventory\Warehouses\Models\Warehouses; use Kanvas\Social\Interactions\Models\EntityInteractions; @@ -64,4 +65,15 @@ public function testEntityUnLikeOtherEntity(): void $product->unLike($warehouse) ); } + + public function testEntityNewInteraction() + { + $people = People::firstOrFail(); + $product = Products::firstOrFail(); + + $this->assertInstanceOf( + EntityInteractions::class, + $people->addInteraction($product, 'view', 'This is a test note') + ); + } } From 4dfb50e7f669441b8b075f4e0a7d64ee11e0f63c Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 19 Jun 2024 22:46:02 -0400 Subject: [PATCH 02/67] Refact: style --- .../Social/Builders/Interactions/EntityInteractionsBuilder.php | 1 - .../Interactions/Actions/CreateEntityInteractionAction.php | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/GraphQL/Social/Builders/Interactions/EntityInteractionsBuilder.php b/app/GraphQL/Social/Builders/Interactions/EntityInteractionsBuilder.php index a240d57c5..977cf8b05 100644 --- a/app/GraphQL/Social/Builders/Interactions/EntityInteractionsBuilder.php +++ b/app/GraphQL/Social/Builders/Interactions/EntityInteractionsBuilder.php @@ -18,7 +18,6 @@ public function getAll( GraphQLContext $context, ResolveInfo $resolveInfo ): Builder { - return EntityInteractions::where('entity_id', '=', $root->uuid) ->where('entity_namespace', '=', $root::class) ->where('is_deleted', '=', StateEnums::NO->getValue()); diff --git a/src/Domains/Social/Interactions/Actions/CreateEntityInteractionAction.php b/src/Domains/Social/Interactions/Actions/CreateEntityInteractionAction.php index 45197fcf7..9400ae413 100644 --- a/src/Domains/Social/Interactions/Actions/CreateEntityInteractionAction.php +++ b/src/Domains/Social/Interactions/Actions/CreateEntityInteractionAction.php @@ -5,7 +5,6 @@ namespace Kanvas\Social\Interactions\Actions; use Baka\Enums\StateEnums; -use Baka\Support\Str; use Kanvas\Apps\Models\Apps; use Kanvas\Social\Interactions\DataTransferObject\EntityInteraction; use Kanvas\Social\Interactions\DataTransferObject\Interaction; @@ -30,7 +29,7 @@ public function execute(): EntityInteractions ); $interaction = $createInteractions->execute(); - + return EntityInteractions::updateOrCreate( [ 'entity_id' => $this->entityInteractionData->entity->uuid, From 6b4cb0ceaab62294da1a78d2ce0e620dd58e585b Mon Sep 17 00:00:00 2001 From: FredPeal Date: Sat, 29 Jun 2024 22:36:22 -0400 Subject: [PATCH 03/67] feat: update people subscription --- app/Http/Controllers/ReceiverController.php | 20 ++++++ composer.json | 1 + composer.lock | 61 ++++++++++++++++++- ...024_06_25_032857_peoples_subscriptions.php | 36 +++++++++++ .../Actions/UpdatePeopleSubscription.php | 59 ++++++++++++++++++ .../Customers/Models/PeopleSubscription.php | 24 ++++++++ 6 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php create mode 100644 src/Domains/Connectors/Stripe/Actions/UpdatePeopleSubscription.php create mode 100644 src/Domains/Guild/Customers/Models/PeopleSubscription.php diff --git a/app/Http/Controllers/ReceiverController.php b/app/Http/Controllers/ReceiverController.php index e36ea7d6e..f94179b55 100644 --- a/app/Http/Controllers/ReceiverController.php +++ b/app/Http/Controllers/ReceiverController.php @@ -4,12 +4,14 @@ namespace App\Http\Controllers; +use Illuminate\Support\Facades\Log; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Auth; use Kanvas\Apps\Models\Apps; +use Kanvas\Connectors\Stripe\Actions\UpdatePeopleSubscription; use Kanvas\Connectors\Zoho\Actions\SyncZohoAgentAction; use Kanvas\Connectors\Zoho\Actions\SyncZohoLeadAction; use Kanvas\Connectors\Zoho\Workflows\ZohoLeadOwnerWorkflow; @@ -25,6 +27,24 @@ class ReceiverController extends BaseController */ public function store(string $uuid, Request $request): JsonResponse { + $stripeUuids = [ + '5f5abdb9-55ed-4080-a1cb-00823dad3edb' => UpdatePeopleSubscription::class, + 'c92ca8f1-3bac-4598-a4ef-68b7bf5aacb7' => UpdatePeopleSubscription::class, + ]; + + if (array_key_exists($uuid, $stripeUuids)) { + if (! in_array( + $request->type, + ['customer.subscription.created', 'customer.subscription.updated', 'customer.subscription.deleted'] + )) { + return response()->json(['message' => 'Receiver not found']); + } + $action = new $stripeUuids[$uuid]($request->all()); + $action->execute(); + Log::info('Receiver processed'); + return response()->json(['message' => 'Receiver processed']); + } + $app = app(Apps::class); $receiver = LeadReceiver::fromApp($app)->where('uuid', $uuid)->first(); diff --git a/composer.json b/composer.json index ac883ea1e..be82c2e19 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "spatie/laravel-health": "^1.27", "spatie/laravel-queueable-action": "^2.15", "spatie/laravel-webhook-server": "^3.8", + "stripe/stripe-php": "^15.0", "symfony/expression-language": "^7.0", "symfony/http-client": "^7.0", "symfony/mailgun-mailer": "^7.0", diff --git a/composer.lock b/composer.lock index 3999b6a8e..2173691e4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2939262e81b0fe33577c46164f677afb", + "content-hash": "5164d1f23c9953e8831a92982782e17f", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -9728,6 +9728,65 @@ ], "time": "2023-12-25T11:46:58+00:00" }, + { + "name": "stripe/stripe-php", + "version": "v15.0.0", + "source": { + "type": "git", + "url": "https://github.com/stripe/stripe-php.git", + "reference": "96f0dbe9c2b5365d716f86d92a27feecca2cbaee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stripe/stripe-php/zipball/96f0dbe9c2b5365d716f86d92a27feecca2cbaee", + "reference": "96f0dbe9c2b5365d716f86d92a27feecca2cbaee", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=5.6.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.5.0", + "phpstan/phpstan": "^1.2", + "phpunit/phpunit": "^5.7 || ^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Stripe\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stripe and contributors", + "homepage": "https://github.com/stripe/stripe-php/contributors" + } + ], + "description": "Stripe PHP Library", + "homepage": "https://stripe.com/", + "keywords": [ + "api", + "payment processing", + "stripe" + ], + "support": { + "issues": "https://github.com/stripe/stripe-php/issues", + "source": "https://github.com/stripe/stripe-php/tree/v15.0.0" + }, + "time": "2024-06-24T23:05:11+00:00" + }, { "name": "symfony/cache", "version": "v7.1.1", diff --git a/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php b/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php new file mode 100644 index 000000000..776305d50 --- /dev/null +++ b/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php @@ -0,0 +1,36 @@ +id(); + $table->integer('peoples_id'); + $table->string('subscription_type'); + $table->string('status'); + $table->date('first_date'); + $table->date('start_date'); + $table->date('end_date')->nullable(); + $table->date('next_renewal')->nullable(); + $table->text('metadata')->nullable(); + $table->boolean('is_deleted')->default(0); + $table->dateTime('created_at')->index('created_at'); + $table->dateTime('updated_at')->nullable()->index('updated_at'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('peoples_subscription'); + } +}; diff --git a/src/Domains/Connectors/Stripe/Actions/UpdatePeopleSubscription.php b/src/Domains/Connectors/Stripe/Actions/UpdatePeopleSubscription.php new file mode 100644 index 000000000..95f751d96 --- /dev/null +++ b/src/Domains/Connectors/Stripe/Actions/UpdatePeopleSubscription.php @@ -0,0 +1,59 @@ +app = $app ?? app(Apps::class); + } + + public function execute() + { + $webhookSub = $this->data['data']['object']; + + $stripe = new StripeClient($this->app->get('stripe_secret_key')); + // Log::info($webhookSub); + // die; + $customer = $stripe->customers->retrieve( + $webhookSub['customer'], + ['expand' => ['subscriptions']] + ); + $company = $this->app->companies->sortByDesc('id')->first(); + if (! $customer->email) { + Log::info('Customer email not found'); + + return; + } + $people = PeoplesRepository::getByEmail($customer->email, $company); + if (! $people) { + Log::info('People not found'); + + return; + } + PeopleSubscription::updateOrCreate( + [ + 'subscription_type' => $customer->subscription->plan->nickname, + 'status' => '1', + 'first_date' => date('Y-m-d H:i:s', $customer->subscription->created), + 'start_date' => date('Y-m-d H:i:s', $customer->subscription->current_period_start), + 'end_date' => date('Y-m-d H:i:s', $customer->subscription->ended_at), + 'next_renewal' => date('Y-m-d H:i:s', $customer->subscription->current_period_end), + 'metadata' => json_encode($this->data), + ], + [ + 'peoples_id' => $people->id, + ] + ); + } +} diff --git a/src/Domains/Guild/Customers/Models/PeopleSubscription.php b/src/Domains/Guild/Customers/Models/PeopleSubscription.php new file mode 100644 index 000000000..3e18ebab1 --- /dev/null +++ b/src/Domains/Guild/Customers/Models/PeopleSubscription.php @@ -0,0 +1,24 @@ + Date: Mon, 1 Jul 2024 00:10:38 -0400 Subject: [PATCH 04/67] feat: add people subscription --- .../Commands/KanvasCreateReceiverCommand.php | 57 +++++++++++++++ app/Http/Controllers/ReceiverController.php | 12 ---- ...024_06_25_032857_peoples_subscriptions.php | 7 +- .../Actions/UpdatePeopleSubscription.php | 59 ---------------- .../Stripe/Jobs/UpdatePeopleSubscription.php | 70 +++++++++++++++++++ .../Customers/Models/PeopleSubscription.php | 2 +- 6 files changed, 132 insertions(+), 75 deletions(-) create mode 100644 app/Console/Commands/KanvasCreateReceiverCommand.php delete mode 100644 src/Domains/Connectors/Stripe/Actions/UpdatePeopleSubscription.php create mode 100644 src/Domains/Connectors/Stripe/Jobs/UpdatePeopleSubscription.php diff --git a/app/Console/Commands/KanvasCreateReceiverCommand.php b/app/Console/Commands/KanvasCreateReceiverCommand.php new file mode 100644 index 000000000..8a91dd933 --- /dev/null +++ b/app/Console/Commands/KanvasCreateReceiverCommand.php @@ -0,0 +1,57 @@ +info('Creating Receiver...'); + $app = select( + label: 'Select the app for the receiver: ', + options: Apps::pluck('name', 'id'), + ); + $action = select( + label: 'Select the action for the receiver: ', + options: WorkflowAction::pluck('name', 'id'), + ); + $userId = $this->ask('Enter the user ID for the receiver: '); + $companyId = $this->ask('Enter the company ID for the receiver: '); + $name = $this->ask('Enter the name for the receiver: '); + $description = $this->ask('Enter the description for the receiver: '); + $company = Companies::getById($companyId); + $user = UsersRepository::getUserOfCompanyById($company, (int)$userId); + + $receiver = ReceiverWebhook::create([ + 'apps_id' => $app, + 'action_id' => $action, + 'companies_id' => $company->getId(), + 'users_id' => $user->getId(), + 'name' => $name, + 'description' => $description, + 'is_active' => true, + 'is_deleted' => false, + ]); + + $this->info('Receiver created successfully!'); + $url = config('app.url') . '/receiver/' . $receiver->uuid; + $this->info('Webhook URL: ' . $url); + } +} diff --git a/app/Http/Controllers/ReceiverController.php b/app/Http/Controllers/ReceiverController.php index 8db769b68..d53763caa 100644 --- a/app/Http/Controllers/ReceiverController.php +++ b/app/Http/Controllers/ReceiverController.php @@ -35,18 +35,6 @@ public function store(string $uuid, Request $request): JsonResponse 'c92ca8f1-3bac-4598-a4ef-68b7bf5aacb7' => UpdatePeopleSubscription::class, ]; - if (array_key_exists($uuid, $stripeUuids)) { - if (! in_array( - $request->type, - ['customer.subscription.created', 'customer.subscription.updated', 'customer.subscription.deleted'] - )) { - return response()->json(['message' => 'Receiver not found']); - } - $action = new $stripeUuids[$uuid]($request->all()); - $action->execute(); - Log::info('Receiver processed'); - return response()->json(['message' => 'Receiver processed']); - } $app = app(Apps::class); $receiver = ReceiverWebhook::where('uuid', $uuid)->notDeleted()->first(); diff --git a/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php b/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php index 776305d50..84419a8e7 100644 --- a/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php +++ b/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php @@ -10,9 +10,10 @@ */ public function up(): void { - Schema::create('peoples_subscription', function (Blueprint $table) { + Schema::create('peoples_subscriptions', function (Blueprint $table) { $table->id(); - $table->integer('peoples_id'); + $table->bigInteger('apps_id')->unsigned(); + $table->bigInteger('peoples_id')->unsigned(); $table->string('subscription_type'); $table->string('status'); $table->date('first_date'); @@ -31,6 +32,6 @@ public function up(): void */ public function down(): void { - Schema::dropIfExists('peoples_subscription'); + Schema::dropIfExists('peoples_subscriptions'); } }; diff --git a/src/Domains/Connectors/Stripe/Actions/UpdatePeopleSubscription.php b/src/Domains/Connectors/Stripe/Actions/UpdatePeopleSubscription.php deleted file mode 100644 index 95f751d96..000000000 --- a/src/Domains/Connectors/Stripe/Actions/UpdatePeopleSubscription.php +++ /dev/null @@ -1,59 +0,0 @@ -app = $app ?? app(Apps::class); - } - - public function execute() - { - $webhookSub = $this->data['data']['object']; - - $stripe = new StripeClient($this->app->get('stripe_secret_key')); - // Log::info($webhookSub); - // die; - $customer = $stripe->customers->retrieve( - $webhookSub['customer'], - ['expand' => ['subscriptions']] - ); - $company = $this->app->companies->sortByDesc('id')->first(); - if (! $customer->email) { - Log::info('Customer email not found'); - - return; - } - $people = PeoplesRepository::getByEmail($customer->email, $company); - if (! $people) { - Log::info('People not found'); - - return; - } - PeopleSubscription::updateOrCreate( - [ - 'subscription_type' => $customer->subscription->plan->nickname, - 'status' => '1', - 'first_date' => date('Y-m-d H:i:s', $customer->subscription->created), - 'start_date' => date('Y-m-d H:i:s', $customer->subscription->current_period_start), - 'end_date' => date('Y-m-d H:i:s', $customer->subscription->ended_at), - 'next_renewal' => date('Y-m-d H:i:s', $customer->subscription->current_period_end), - 'metadata' => json_encode($this->data), - ], - [ - 'peoples_id' => $people->id, - ] - ); - } -} diff --git a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleSubscription.php b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleSubscription.php new file mode 100644 index 000000000..13548c058 --- /dev/null +++ b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleSubscription.php @@ -0,0 +1,70 @@ +webhookRequest->payload['type'], ['customer.subscription.updated', 'customer.subscription.created', 'customer.subscription.deleted'])) { + Log::error('Webhook type not found', ['type' => $this->webhookRequest->payload['type']]); + + return []; + } + $this->data = $this->webhookRequest->payload; + $webhookSub = $this->data['data']['object']; + $app = $this->webhookRequest->receiverWebhook->app; + $company = $this->webhookRequest->receiverWebhook->company; + $user = $this->webhookRequest->receiverWebhook->user; + + $stripe = new StripeClient($app->get('stripe_secret_key')); + $customer = $stripe->customers->retrieve( + $webhookSub['customer'], + ['expand' => ['subscriptions']] + ); + + if (! $customer->email) { + Log::error('Customer email not found'); + + return []; + } + $people = PeoplesRepository::getByEmail($customer->email, $company); + if (! $people) { + Log::error('People not found'); + + return []; + } + $subscriptions = $customer->subscriptions->data[0]; + $dataPeopleSub = [ + 'subscription_type' => $subscriptions['plan']['nickname'], + 'status' => '1', + 'first_date' => date('Y-m-d H:i:s', $subscriptions['created']), + 'start_date' => date('Y-m-d H:i:s', $subscriptions['current_period_start']), + 'end_date' => date('Y-m-d H:i:s', $subscriptions['ended_at']), + 'next_renewal' => date('Y-m-d H:i:s', $subscriptions['current_period_end']), + 'metadata' => json_encode($this->data), + 'apps_id' => $app->getId(), + ]; + PeopleSubscription::updateOrCreate( + $dataPeopleSub, + [ + 'peoples_id' => $people->id, + ] + ); + return [ + 'message' => 'People Subscription updated', + 'data' => $dataPeopleSub, + ]; + } +} diff --git a/src/Domains/Guild/Customers/Models/PeopleSubscription.php b/src/Domains/Guild/Customers/Models/PeopleSubscription.php index 3e18ebab1..c8dfa2d0f 100644 --- a/src/Domains/Guild/Customers/Models/PeopleSubscription.php +++ b/src/Domains/Guild/Customers/Models/PeopleSubscription.php @@ -18,7 +18,7 @@ */ class PeopleSubscription extends BaseModel { - protected $table = 'people_subscriptions'; + protected $table = 'peoples_subscriptions'; protected $guarded = []; } From 1d2aac634ca807e65c225c050eae92a2c3d1a9dd Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 1 Jul 2024 04:11:24 +0000 Subject: [PATCH 05/67] Apply fixes from StyleCI --- app/Console/Commands/KanvasCreateReceiverCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Console/Commands/KanvasCreateReceiverCommand.php b/app/Console/Commands/KanvasCreateReceiverCommand.php index 8a91dd933..2736e4d16 100644 --- a/app/Console/Commands/KanvasCreateReceiverCommand.php +++ b/app/Console/Commands/KanvasCreateReceiverCommand.php @@ -10,6 +10,7 @@ use Kanvas\Users\Repositories\UsersRepository; use Kanvas\Workflow\Models\WorkflowAction; use Kanvas\Workflow\Models\ReceiverWebhook; + use function Laravel\Prompts\select; class KanvasCreateReceiverCommand extends Command From aad2ab61f57440b386fcb514a83f8ab830024581 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Mon, 1 Jul 2024 00:13:29 -0400 Subject: [PATCH 06/67] refactor: delete fixed uuid stripe --- app/Http/Controllers/ReceiverController.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/Http/Controllers/ReceiverController.php b/app/Http/Controllers/ReceiverController.php index d53763caa..dc2c4ecad 100644 --- a/app/Http/Controllers/ReceiverController.php +++ b/app/Http/Controllers/ReceiverController.php @@ -30,12 +30,6 @@ class ReceiverController extends BaseController */ public function store(string $uuid, Request $request): JsonResponse { - $stripeUuids = [ - '5f5abdb9-55ed-4080-a1cb-00823dad3edb' => UpdatePeopleSubscription::class, - 'c92ca8f1-3bac-4598-a4ef-68b7bf5aacb7' => UpdatePeopleSubscription::class, - ]; - - $app = app(Apps::class); $receiver = ReceiverWebhook::where('uuid', $uuid)->notDeleted()->first(); From f30368d0a1a07c19f340b802f4cf5cc252bd32c1 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Mon, 1 Jul 2024 14:41:21 -0400 Subject: [PATCH 07/67] refactor: move kanvas create receiver command --- .../Commands/{ => Workflows}/KanvasCreateReceiverCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename app/Console/Commands/{ => Workflows}/KanvasCreateReceiverCommand.php (97%) diff --git a/app/Console/Commands/KanvasCreateReceiverCommand.php b/app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php similarity index 97% rename from app/Console/Commands/KanvasCreateReceiverCommand.php rename to app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php index 2736e4d16..551c24c11 100644 --- a/app/Console/Commands/KanvasCreateReceiverCommand.php +++ b/app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace App\Console\Commands; +namespace App\Console\Commands\Workflows; use Illuminate\Console\Command; use Kanvas\Apps\Models\Apps; use Kanvas\Companies\Models\Companies; use Kanvas\Users\Repositories\UsersRepository; -use Kanvas\Workflow\Models\WorkflowAction; use Kanvas\Workflow\Models\ReceiverWebhook; +use Kanvas\Workflow\Models\WorkflowAction; use function Laravel\Prompts\select; From 4b40bc61e4c7138825c124490a911efc5d92c1eb Mon Sep 17 00:00:00 2001 From: FredPeal Date: Tue, 2 Jul 2024 01:02:01 -0400 Subject: [PATCH 08/67] refactor: JSON cast --- src/Domains/Guild/Customers/Models/PeopleSubscription.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Domains/Guild/Customers/Models/PeopleSubscription.php b/src/Domains/Guild/Customers/Models/PeopleSubscription.php index c8dfa2d0f..7b213801a 100644 --- a/src/Domains/Guild/Customers/Models/PeopleSubscription.php +++ b/src/Domains/Guild/Customers/Models/PeopleSubscription.php @@ -4,6 +4,7 @@ namespace Kanvas\Guild\Customers\Models; +use Baka\Casts\Json; use Kanvas\Guild\Models\BaseModel; /** @@ -21,4 +22,8 @@ class PeopleSubscription extends BaseModel protected $table = 'peoples_subscriptions'; protected $guarded = []; + + protected $casts = [ + 'metadata' => Json::class, + ]; } From f0118e9acbd31872c5c16d6ae072868c5f559daf Mon Sep 17 00:00:00 2001 From: FredPeal Date: Tue, 2 Jul 2024 02:24:17 -0400 Subject: [PATCH 09/67] refactor: receiver for ghosts --- app/Http/Controllers/ReceiverController.php | 4 +- .../Jobs/UpdatePeopleGhostSubscription.php | 46 +++++++++++++++++++ ...php => UpdatePeopleStripeSubscription.php} | 35 +++++++------- .../CreateOrUpdatePeopleSubscription.php | 38 +++++++++++++++ .../DataTransferObject/PeopleSubscription.php | 24 ++++++++++ 5 files changed, 127 insertions(+), 20 deletions(-) create mode 100644 src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php rename src/Domains/Connectors/Stripe/Jobs/{UpdatePeopleSubscription.php => UpdatePeopleStripeSubscription.php} (64%) create mode 100644 src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php create mode 100644 src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php diff --git a/app/Http/Controllers/ReceiverController.php b/app/Http/Controllers/ReceiverController.php index dc2c4ecad..c5640a51b 100644 --- a/app/Http/Controllers/ReceiverController.php +++ b/app/Http/Controllers/ReceiverController.php @@ -4,15 +4,14 @@ namespace App\Http\Controllers; -use Illuminate\Support\Facades\Log; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; use Kanvas\Apps\Models\Apps; -use Kanvas\Connectors\Stripe\Actions\UpdatePeopleSubscription; use Kanvas\Connectors\Zoho\Actions\SyncZohoAgentAction; use Kanvas\Connectors\Zoho\Actions\SyncZohoLeadAction; use Kanvas\Connectors\Zoho\Workflows\ZohoLeadOwnerWorkflow; @@ -32,7 +31,6 @@ public function store(string $uuid, Request $request): JsonResponse { $app = app(Apps::class); $receiver = ReceiverWebhook::where('uuid', $uuid)->notDeleted()->first(); - if ($receiver) { // return response()->json(['message' => 'Receiver not found'], 404); if ($app->getId() != $receiver->apps_id) { diff --git a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php new file mode 100644 index 000000000..473fead66 --- /dev/null +++ b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php @@ -0,0 +1,46 @@ +webhookRequest->payload; + $app = $this->webhookRequest->receiverWebhook->app; + $company = $this->webhookRequest->receiverWebhook->company; + + $people = PeoplesRepository::getByEmail($member['email'], $company); + if (! $people) { + throw new Exception('People not found'); + } + $dto = new PeopleSubscriptionDTO( + app: $app, + peoples_id: $people->id, + subscription_type: 'Free', + status: '1', + first_date: date('Y-m-d H:i:s', $member['created_at']), + start_date: date('Y-m-d H:i:s', $member['created_at']), + metadata: $this->webhookRequest->payload + ); + $action = new CreateOrUpdatePeopleSubscription($dto); + $peopleSub = $action->handle(); + return [ + 'success' => true, + 'data' => $peopleSub + ]; + } +} \ No newline at end of file diff --git a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleSubscription.php b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php similarity index 64% rename from src/Domains/Connectors/Stripe/Jobs/UpdatePeopleSubscription.php rename to src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php index 13548c058..b039ab230 100644 --- a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleSubscription.php +++ b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php @@ -9,9 +9,11 @@ use Kanvas\Guild\Customers\Repositories\PeoplesRepository; use Kanvas\Workflow\Jobs\ProcessWebhookJob; use Stripe\StripeClient; +use Kanvas\Guild\Customers\DataTransferObject\PeopleSubscription as PeopleSubscriptionDTO; +use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscription; // Maybe add action at the of the class name -class UpdatePeopleSubscription extends ProcessWebhookJob +class UpdatePeopleStripeSubscription extends ProcessWebhookJob { public $data; @@ -46,25 +48,24 @@ public function execute(): array return []; } $subscriptions = $customer->subscriptions->data[0]; - $dataPeopleSub = [ - 'subscription_type' => $subscriptions['plan']['nickname'], - 'status' => '1', - 'first_date' => date('Y-m-d H:i:s', $subscriptions['created']), - 'start_date' => date('Y-m-d H:i:s', $subscriptions['current_period_start']), - 'end_date' => date('Y-m-d H:i:s', $subscriptions['ended_at']), - 'next_renewal' => date('Y-m-d H:i:s', $subscriptions['current_period_end']), - 'metadata' => json_encode($this->data), - 'apps_id' => $app->getId(), - ]; - PeopleSubscription::updateOrCreate( - $dataPeopleSub, - [ - 'peoples_id' => $people->id, - ] + + $dto = new PeopleSubscriptionDTO( + app: $app, + peoples_id: $people->id, + subscription_type: $subscriptions['plan']['nickname'], + status: '1', + first_date: date('Y-m-d H:i:s', $subscriptions['created']), + start_date: date('Y-m-d H:i:s', $subscriptions['current_period_start']), + end_date: date('Y-m-d H:i:s', $subscriptions['ended_at']), + next_renewal: date('Y-m-d H:i:s', $subscriptions['current_period_end']), + metadata: json_encode($this->data), ); + $action = new CreateOrUpdatePeopleSubscription($dto); + $peopleSub = $action->handle(); + return [ 'message' => 'People Subscription updated', - 'data' => $dataPeopleSub, + 'data' => $peopleSub, ]; } } diff --git a/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php b/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php new file mode 100644 index 000000000..23d41d4ad --- /dev/null +++ b/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php @@ -0,0 +1,38 @@ + $this->peopleSubscriptionDTO->subscription_type, + 'status' => '1', + 'first_date' => $this->peopleSubscriptionDTO->first_date, + 'start_date' => $this->peopleSubscriptionDTO->start_date, + 'end_date' => $this->peopleSubscriptionDTO->end_date, + 'next_renewal' => $this->peopleSubscriptionDTO->next_renewal, + 'metadata' => json_encode($this->peopleSubscriptionDTO->metadata), + 'apps_id' => $this->peopleSubscriptionDTO->app->getId(), + ]; + + return PeopleSubscription::updateOrCreate( + $dataPeopleSub, + [ + 'peoples_id' => $this->peopleSubscriptionDTO->peoples_id, + 'subscription_type' => $this->peopleSubscriptionDTO->subscription_type, + ] + ); + } +} diff --git a/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php b/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php new file mode 100644 index 000000000..fdcc05621 --- /dev/null +++ b/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php @@ -0,0 +1,24 @@ + Date: Thu, 4 Jul 2024 15:18:58 -0400 Subject: [PATCH 10/67] refactor: add test to receiver ghost and stripe --- .../Jobs/UpdatePeopleGhostSubscription.php | 21 ++-- .../Jobs/UpdatePeopleStripeSubscription.php | 13 +-- .../CreateOrUpdatePeopleSubscription.php | 2 +- .../DataTransferObject/PeopleSubscription.php | 4 +- .../Customers/Factories/ContactFactory.php | 25 +++++ .../Guild/Customers/Models/Contact.php | 7 +- .../Workflow/Models/WorkflowAction.php | 2 + .../Ghosts/CreatePeopleSubscriptionTest.php | 64 +++++++++++ .../Stripe/UpdateSubscriptionTest.php | 101 ++++++++++++++++++ 9 files changed, 217 insertions(+), 22 deletions(-) create mode 100644 src/Domains/Guild/Customers/Factories/ContactFactory.php create mode 100644 tests/Connectors/Integration/Ghosts/CreatePeopleSubscriptionTest.php create mode 100644 tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php diff --git a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php index 473fead66..73d289479 100644 --- a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php +++ b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php @@ -4,43 +4,40 @@ namespace Kanvas\Connectors\Ghost\Jobs; -use Illuminate\Support\Facades\Log; -use Kanvas\Guild\Customers\Models\PeopleSubscription; +use Exception; +use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscription; +use Kanvas\Guild\Customers\DataTransferObject\PeopleSubscription as PeopleSubscriptionDTO; use Kanvas\Guild\Customers\Repositories\PeoplesRepository; use Kanvas\Workflow\Jobs\ProcessWebhookJob; -use Stripe\StripeClient; -use Kanvas\Guild\Customers\DataTransferObject\PeopleSubscription as PeopleSubscriptionDTO; -use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscription; -use Exception; // Maybe add action at the of the class name class UpdatePeopleGhostSubscription extends ProcessWebhookJob { - public function execute(): array { $member = $this->webhookRequest->payload; $app = $this->webhookRequest->receiverWebhook->app; $company = $this->webhookRequest->receiverWebhook->company; - + $people = PeoplesRepository::getByEmail($member['email'], $company); if (! $people) { throw new Exception('People not found'); } $dto = new PeopleSubscriptionDTO( app: $app, - peoples_id: $people->id, + people: $people, subscription_type: 'Free', status: '1', first_date: date('Y-m-d H:i:s', $member['created_at']), start_date: date('Y-m-d H:i:s', $member['created_at']), - metadata: $this->webhookRequest->payload + metadata: json_encode($this->webhookRequest->payload) ); $action = new CreateOrUpdatePeopleSubscription($dto); $peopleSub = $action->handle(); + return [ 'success' => true, - 'data' => $peopleSub + 'data' => $peopleSub, ]; } -} \ No newline at end of file +} diff --git a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php index b039ab230..7825a83e0 100644 --- a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php +++ b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php @@ -5,12 +5,11 @@ namespace Kanvas\Connectors\Stripe\Jobs; use Illuminate\Support\Facades\Log; -use Kanvas\Guild\Customers\Models\PeopleSubscription; +use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscription; +use Kanvas\Guild\Customers\DataTransferObject\PeopleSubscription as PeopleSubscriptionDTO; use Kanvas\Guild\Customers\Repositories\PeoplesRepository; use Kanvas\Workflow\Jobs\ProcessWebhookJob; use Stripe\StripeClient; -use Kanvas\Guild\Customers\DataTransferObject\PeopleSubscription as PeopleSubscriptionDTO; -use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscription; // Maybe add action at the of the class name class UpdatePeopleStripeSubscription extends ProcessWebhookJob @@ -39,19 +38,21 @@ public function execute(): array if (! $customer->email) { Log::error('Customer email not found'); - return []; + return ['error' => 'Customer email not found ' . $customer->id]; } $people = PeoplesRepository::getByEmail($customer->email, $company); if (! $people) { Log::error('People not found'); + return ['error' => 'People not found' . $customer->email]; + return []; } $subscriptions = $customer->subscriptions->data[0]; $dto = new PeopleSubscriptionDTO( app: $app, - peoples_id: $people->id, + people: $people, subscription_type: $subscriptions['plan']['nickname'], status: '1', first_date: date('Y-m-d H:i:s', $subscriptions['created']), @@ -62,7 +63,7 @@ public function execute(): array ); $action = new CreateOrUpdatePeopleSubscription($dto); $peopleSub = $action->handle(); - + return [ 'message' => 'People Subscription updated', 'data' => $peopleSub, diff --git a/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php b/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php index 23d41d4ad..b48685e9c 100644 --- a/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php +++ b/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php @@ -30,7 +30,7 @@ public function handle(): PeopleSubscription return PeopleSubscription::updateOrCreate( $dataPeopleSub, [ - 'peoples_id' => $this->peopleSubscriptionDTO->peoples_id, + 'peoples_id' => $this->peopleSubscriptionDTO->people->getId(), 'subscription_type' => $this->peopleSubscriptionDTO->subscription_type, ] ); diff --git a/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php b/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php index fdcc05621..6b2038ac3 100644 --- a/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php +++ b/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php @@ -6,12 +6,12 @@ use Spatie\LaravelData\Data; use Kanvas\Apps\Models\Apps; - +use Kanvas\Guild\Customers\Models\People; class PeopleSubscription extends Data { public function __construct( public Apps $app, - public int $peoples_id, + public People $people, public string $subscription_type, public string $status, public string $first_date, diff --git a/src/Domains/Guild/Customers/Factories/ContactFactory.php b/src/Domains/Guild/Customers/Factories/ContactFactory.php new file mode 100644 index 000000000..d09b53f83 --- /dev/null +++ b/src/Domains/Guild/Customers/Factories/ContactFactory.php @@ -0,0 +1,25 @@ + $contactType->id, + 'value' => fake()->email, + 'weight' => 1, + ]; + } +} diff --git a/src/Domains/Guild/Customers/Models/Contact.php b/src/Domains/Guild/Customers/Models/Contact.php index 4f45fff14..29d7ddc92 100644 --- a/src/Domains/Guild/Customers/Models/Contact.php +++ b/src/Domains/Guild/Customers/Models/Contact.php @@ -7,6 +7,7 @@ use Baka\Traits\NoAppRelationshipTrait; use Baka\Traits\NoCompanyRelationshipTrait; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Kanvas\Guild\Customers\Factories\ContactFactory; use Kanvas\Guild\Models\BaseModel; /** @@ -17,7 +18,6 @@ * @property int $peoples_id * @property string $value * @property int $weight - * */ class Contact extends BaseModel { @@ -44,4 +44,9 @@ public function type(): BelongsTo 'id' ); } + + protected static function newFactory() + { + return new ContactFactory(); + } } diff --git a/src/Domains/Workflow/Models/WorkflowAction.php b/src/Domains/Workflow/Models/WorkflowAction.php index c721f452d..82d4dc762 100644 --- a/src/Domains/Workflow/Models/WorkflowAction.php +++ b/src/Domains/Workflow/Models/WorkflowAction.php @@ -14,6 +14,8 @@ class WorkflowAction extends BaseModel protected $table = 'actions'; + protected $guarded = []; + protected static function newFactory(): Factory { return ActionFactory::new(); diff --git a/tests/Connectors/Integration/Ghosts/CreatePeopleSubscriptionTest.php b/tests/Connectors/Integration/Ghosts/CreatePeopleSubscriptionTest.php new file mode 100644 index 000000000..19b927681 --- /dev/null +++ b/tests/Connectors/Integration/Ghosts/CreatePeopleSubscriptionTest.php @@ -0,0 +1,64 @@ +user(); + $company = $user->getCurrentCompany(); + + $people = People::factory() + ->withAppId($app->getId()) + ->withCompanyId($company->getId()) + ->has(Contact::factory()->count(1), 'contacts') + ->create(); + + $payload = [ + 'email' => $people->getEmails()[0]->value, + 'created_at' => time(), + 'current_period_start' => time(), + ]; + + $workflowAction = WorkflowAction::firstOrCreate([ + 'name' => 'Update People Subscription', + 'model_name' => UpdatePeopleGhostSubscription::class, + ]); + + $receiverWebhook = ReceiverWebhook::factory() + ->app($app->getId()) + ->user($user->getId()) + ->company($company->getId()) + ->create([ + 'action_id' => $workflowAction->getId(), + ]); + + $request = Request::create('https://localhost/ghosttest', 'POST', $payload); + + // Execute the action and get the webhook request + $webhookRequest = (new ProcessWebhookAttemptAction($receiverWebhook, $request))->execute(); + + // Fake the queue + Queue::fake(); + $job = new UpdatePeopleGhostSubscription($webhookRequest); + $result = $job->handle(); + $this->assertArrayHasKey('success', $result); + $this->assertArrayHasKey('data', $result); + $this->assertTrue($result['success']); + } +} diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php new file mode 100644 index 000000000..9f719eb58 --- /dev/null +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -0,0 +1,101 @@ +user(); + $company = $user->getCurrentCompany(); + + $people = People::factory() + ->withAppId($app->getId()) + ->withCompanyId($company->getId()) + ->has(Contact::factory()->count(1), 'contacts') + ->create(); + $stripeKey = $app->get('stripe_secret_key'); + if (! $stripeKey) { + $app->set('stripe_secret_key', getenv('STRIPE_SECRET_KEY')); + } + $stripe = new StripeClient($stripeKey); + $customer = $stripe->customers->create([ + 'email' => $people->getEmails()[0]->value, + 'name' => $people->getName(), + ]); + $paymentMethod = $stripe->paymentMethods->create([ + 'type' => 'card', + 'card' => [ + 'number' => '4242424242424242', + 'exp_month' => 8, + 'exp_year' => 2026, + 'cvc' => '314', + ], + ]); + + $stripe->paymentMethods->attach( + $paymentMethod->id, + ['customer' => $customer->id] + ); + $stripe->customers->update( + $customer->id, + ['invoice_settings' => ['default_payment_method' => $paymentMethod->id]] + ); + + $prices = $stripe->prices->all(); + $stripe->subscriptions->create([ + 'customer' => $customer->id, + 'items' => [ + ['price' => $prices->data[0]->id], + ], + ]); + $payload = [ + 'type' => 'customer.subscription.updated', + 'data' => [ + 'object' => [ + 'customer' => $customer->id, + ], + ], + ]; + + $workflowAction = WorkflowAction::firstOrCreate([ + 'name' => 'Update People Subscription', + 'model_name' => UpdatePeopleStripeSubscription::class, + ]); + + $receiverWebhook = ReceiverWebhook::factory() + ->app($app->getId()) + ->user($user->getId()) + ->company($company->getId()) + ->create([ + 'action_id' => $workflowAction->getId(), + ]); + + $request = Request::create('https://localhost/shopifytest', 'POST', $payload); + + // Execute the action and get the webhook request + $webhookRequest = (new ProcessWebhookAttemptAction($receiverWebhook, $request))->execute(); + + // Fake the queue + Queue::fake(); + $job = new UpdatePeopleStripeSubscription($webhookRequest); + $result = $job->handle(); + $this->assertArrayHasKey('message', $result); + $this->assertEquals('People Subscription updated', $result['message']); + } +} From 3cb5426042dd039fdbd260ac3dbb7fa614ef8f2c Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 4 Jul 2024 22:21:13 +0000 Subject: [PATCH 11/67] Apply fixes from StyleCI --- .../Guild/Customers/DataTransferObject/PeopleSubscription.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php b/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php index 6b2038ac3..048ed51cd 100644 --- a/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php +++ b/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php @@ -7,6 +7,7 @@ use Spatie\LaravelData\Data; use Kanvas\Apps\Models\Apps; use Kanvas\Guild\Customers\Models\People; + class PeopleSubscription extends Data { public function __construct( From 25b18c637c3c336c255e7bfd0039abd64a229c52 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Mon, 8 Jul 2024 11:04:57 -0400 Subject: [PATCH 12/67] refactor: add stripe key --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 381222f0e..968c1df20 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -66,6 +66,7 @@ jobs: TEST_SHOPIFY_SHOP_URL: ${{ secrets.TEST_SHOPIFY_SHOP_URL }} TEST_APPLE_LOGIN_TOKEN: ${{ secrets.TEST_APPLE_LOGIN_TOKEN }} TEST_APOLLO_KEY: ${{ secrets.TEST_APOLLO_KEY }} + STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }} strategy: fail-fast: false matrix: From 0046e3167feb7b654e64485e7d59656c54c4f5dd Mon Sep 17 00:00:00 2001 From: FredPeal Date: Mon, 8 Jul 2024 11:44:35 -0400 Subject: [PATCH 13/67] refactor: use environment key --- .../Integration/Stripe/UpdateSubscriptionTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php index 9f719eb58..4d62944c7 100644 --- a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -29,11 +29,8 @@ public function testUpdateSubscription() ->withCompanyId($company->getId()) ->has(Contact::factory()->count(1), 'contacts') ->create(); - $stripeKey = $app->get('stripe_secret_key'); - if (! $stripeKey) { - $app->set('stripe_secret_key', getenv('STRIPE_SECRET_KEY')); - } - $stripe = new StripeClient($stripeKey); + + $stripe = new StripeClient(getenv('STRIPE_SECRET_KEY')); $customer = $stripe->customers->create([ 'email' => $people->getEmails()[0]->value, 'name' => $people->getName(), From 52bbaf5f39bf19dd1e8722faab6975734027c02c Mon Sep 17 00:00:00 2001 From: FredPeal Date: Mon, 8 Jul 2024 12:19:58 -0400 Subject: [PATCH 14/67] refactor: add stripe key to env example --- .env.example | 3 ++- .github/workflows/static-analysis.yml | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 7493df5b5..a4b43187f 100644 --- a/.env.example +++ b/.env.example @@ -134,4 +134,5 @@ TEST_ZOHO_CLIENT_REFRESH_TOKEN= TEST_SHOPIFY_API_KEY= TEST_SHOPIFY_API_SECRET= -TEST_SHOPIFY_SHOP_URL= \ No newline at end of file +TEST_SHOPIFY_SHOP_URL= +STRIPE_SECRET_KEY= \ No newline at end of file diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 73797611a..53f7b1177 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -58,6 +58,8 @@ jobs: TEST_SHOPIFY_SHOP_URL: ${{ secrets.TEST_SHOPIFY_SHOP_URL }} TEST_APPLE_LOGIN_TOKEN: ${{ secrets.TEST_APPLE_LOGIN_TOKEN }} TEST_APOLLO_KEY: ${{ secrets.TEST_APOLLO_KEY }} + STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }} + strategy: fail-fast: false matrix: From 514d6b903c6268dbb21c18fbf7ecc74a91ede8a1 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Mon, 8 Jul 2024 13:05:27 -0400 Subject: [PATCH 15/67] fix: contact factory --- .../Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php | 1 - src/Domains/Guild/Customers/Factories/ContactFactory.php | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php index 73d289479..a55a09ab0 100644 --- a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php +++ b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php @@ -18,7 +18,6 @@ public function execute(): array $member = $this->webhookRequest->payload; $app = $this->webhookRequest->receiverWebhook->app; $company = $this->webhookRequest->receiverWebhook->company; - $people = PeoplesRepository::getByEmail($member['email'], $company); if (! $people) { throw new Exception('People not found'); diff --git a/src/Domains/Guild/Customers/Factories/ContactFactory.php b/src/Domains/Guild/Customers/Factories/ContactFactory.php index d09b53f83..9187862c7 100644 --- a/src/Domains/Guild/Customers/Factories/ContactFactory.php +++ b/src/Domains/Guild/Customers/Factories/ContactFactory.php @@ -5,8 +5,8 @@ namespace Kanvas\Guild\Customers\Factories; use Illuminate\Database\Eloquent\Factories\Factory; +use Kanvas\Guild\Customers\Enums\ContactTypeEnum; use Kanvas\Guild\Customers\Models\Contact; -use Kanvas\Guild\Customers\Models\ContactType; class ContactFactory extends Factory { @@ -14,10 +14,8 @@ class ContactFactory extends Factory public function definition() { - $contactType = ContactType::getByName('Email'); - return [ - 'contacts_types_id' => $contactType->id, + 'contacts_types_id' => ContactTypeEnum::EMAIL->value, 'value' => fake()->email, 'weight' => 1, ]; From e0f95661a5db97d760c25e2e581cfca4ef2c7e97 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Tue, 9 Jul 2024 11:03:01 -0400 Subject: [PATCH 16/67] dumped result --- tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php index 4d62944c7..c2aceb1c9 100644 --- a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -92,6 +92,7 @@ public function testUpdateSubscription() Queue::fake(); $job = new UpdatePeopleStripeSubscription($webhookRequest); $result = $job->handle(); + dump($result); $this->assertArrayHasKey('message', $result); $this->assertEquals('People Subscription updated', $result['message']); } From f4d5d2d15f807885db30a2792896650b5568deaa Mon Sep 17 00:00:00 2001 From: FredPeal Date: Tue, 9 Jul 2024 11:57:09 -0400 Subject: [PATCH 17/67] refactor: dump subscription --- .../Connectors/Integration/Stripe/UpdateSubscriptionTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php index c2aceb1c9..11eff18c1 100644 --- a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -93,7 +93,7 @@ public function testUpdateSubscription() $job = new UpdatePeopleStripeSubscription($webhookRequest); $result = $job->handle(); dump($result); - $this->assertArrayHasKey('message', $result); - $this->assertEquals('People Subscription updated', $result['message']); + // $this->assertArrayHasKey('message', $result); + // $this->assertEquals('People Subscription updated', $result['message']); } } From 9726dfad426598652a6ae69b7d30e854f37d4171 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Tue, 9 Jul 2024 12:26:21 -0400 Subject: [PATCH 18/67] refactor: debug action pr --- .../Integration/Stripe/UpdateSubscriptionTest.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php index 11eff18c1..33d3fa45b 100644 --- a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -15,7 +15,7 @@ use Kanvas\Workflow\Models\WorkflowAction; use Stripe\StripeClient; use Tests\TestCase; - +use Throwable; final class UpdateSubscriptionTest extends TestCase { public function testUpdateSubscription() @@ -91,9 +91,14 @@ public function testUpdateSubscription() // Fake the queue Queue::fake(); $job = new UpdatePeopleStripeSubscription($webhookRequest); + try { + $job->handle(); + } catch (Throwable $e) { + $this->fail($e->getMessage()); + + } $result = $job->handle(); - dump($result); - // $this->assertArrayHasKey('message', $result); - // $this->assertEquals('People Subscription updated', $result['message']); + $this->assertArrayHasKey('message', $result); + $this->assertEquals('People Subscription updated', $result['message']); } } From 828be9f4f4ba4c38ee9fc5c3ad74fe30721ca9b9 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Tue, 9 Jul 2024 16:51:15 -0400 Subject: [PATCH 19/67] feat: count by tag --- graphql/schemas/Guild/people.graphql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/graphql/schemas/Guild/people.graphql b/graphql/schemas/Guild/people.graphql index 29ba17bb6..6ba9ff219 100644 --- a/graphql/schemas/Guild/people.graphql +++ b/graphql/schemas/Guild/people.graphql @@ -133,7 +133,12 @@ extend type Query @guard { model: "Kanvas\\Guild\\Customers\\Models\\People" scopes: ["fromApp", "fromCompany", "notDeleted"] ) - + peopleCountByTag(tag: String!): Int @cache(maxAge: 300) + @count( + model: "Kanvas\\Guild\\Customers\\Models\\People" + scopes: ["fromApp", "fromCompany", "notDeleted"] + where: [["tags", "name", "=", "$tag"]] + ) } extend type Mutation @guard { From 9d39114ac2c57551655bd8749ccba636efa2a01f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:46:04 +0000 Subject: [PATCH 20/67] build(deps): bump laravel/framework from 11.14.0 to 11.15.0 Bumps [laravel/framework](https://github.com/laravel/framework) from 11.14.0 to 11.15.0. - [Release notes](https://github.com/laravel/framework/releases) - [Changelog](https://github.com/laravel/framework/blob/11.x/CHANGELOG.md) - [Commits](https://github.com/laravel/framework/compare/v11.14.0...v11.15.0) --- updated-dependencies: - dependency-name: laravel/framework dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 959fc8b30..bc33bbc86 100644 --- a/composer.lock +++ b/composer.lock @@ -3906,16 +3906,16 @@ }, { "name": "laravel/framework", - "version": "v11.14.0", + "version": "v11.15.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "657e8464e13147d56bc3a399115c8c26f38d4821" + "reference": "ba85f1c019bed59b3c736c9c4502805efd0ba84b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/657e8464e13147d56bc3a399115c8c26f38d4821", - "reference": "657e8464e13147d56bc3a399115c8c26f38d4821", + "url": "https://api.github.com/repos/laravel/framework/zipball/ba85f1c019bed59b3c736c9c4502805efd0ba84b", + "reference": "ba85f1c019bed59b3c736c9c4502805efd0ba84b", "shasum": "" }, "require": { @@ -4021,7 +4021,7 @@ "nyholm/psr7": "^1.2", "orchestra/testbench-core": "^9.1.5", "pda/pheanstalk": "^5.0", - "phpstan/phpstan": "^1.4.7", + "phpstan/phpstan": "^1.11.5", "phpunit/phpunit": "^10.5|^11.0", "predis/predis": "^2.0.2", "resend/resend-php": "^0.10.0", @@ -4108,7 +4108,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-02T17:23:58+00:00" + "time": "2024-07-09T15:38:12+00:00" }, { "name": "laravel/octane", From 0b673994031a75bdc70d060a8132d52a1c1fc685 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:46:15 +0000 Subject: [PATCH 21/67] build(deps): bump laravel/octane from 2.5.1 to 2.5.2 Bumps [laravel/octane](https://github.com/laravel/octane) from 2.5.1 to 2.5.2. - [Release notes](https://github.com/laravel/octane/releases) - [Changelog](https://github.com/laravel/octane/blob/2.x/CHANGELOG.md) - [Commits](https://github.com/laravel/octane/compare/v2.5.1...v2.5.2) --- updated-dependencies: - dependency-name: laravel/octane dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 959fc8b30..584c378e0 100644 --- a/composer.lock +++ b/composer.lock @@ -3906,16 +3906,16 @@ }, { "name": "laravel/framework", - "version": "v11.14.0", + "version": "v11.15.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "657e8464e13147d56bc3a399115c8c26f38d4821" + "reference": "ba85f1c019bed59b3c736c9c4502805efd0ba84b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/657e8464e13147d56bc3a399115c8c26f38d4821", - "reference": "657e8464e13147d56bc3a399115c8c26f38d4821", + "url": "https://api.github.com/repos/laravel/framework/zipball/ba85f1c019bed59b3c736c9c4502805efd0ba84b", + "reference": "ba85f1c019bed59b3c736c9c4502805efd0ba84b", "shasum": "" }, "require": { @@ -4021,7 +4021,7 @@ "nyholm/psr7": "^1.2", "orchestra/testbench-core": "^9.1.5", "pda/pheanstalk": "^5.0", - "phpstan/phpstan": "^1.4.7", + "phpstan/phpstan": "^1.11.5", "phpunit/phpunit": "^10.5|^11.0", "predis/predis": "^2.0.2", "resend/resend-php": "^0.10.0", @@ -4108,20 +4108,20 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-07-02T17:23:58+00:00" + "time": "2024-07-09T15:38:12+00:00" }, { "name": "laravel/octane", - "version": "v2.5.1", + "version": "v2.5.2", "source": { "type": "git", "url": "https://github.com/laravel/octane.git", - "reference": "21b319dd699c20821554a8f806c2487c6cb2cf59" + "reference": "ba9b7fffc3551eb8ba6d9e708866463e42f27511" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/octane/zipball/21b319dd699c20821554a8f806c2487c6cb2cf59", - "reference": "21b319dd699c20821554a8f806c2487c6cb2cf59", + "url": "https://api.github.com/repos/laravel/octane/zipball/ba9b7fffc3551eb8ba6d9e708866463e42f27511", + "reference": "ba9b7fffc3551eb8ba6d9e708866463e42f27511", "shasum": "" }, "require": { @@ -4198,7 +4198,7 @@ "issues": "https://github.com/laravel/octane/issues", "source": "https://github.com/laravel/octane" }, - "time": "2024-07-01T20:50:27+00:00" + "time": "2024-07-08T14:44:19+00:00" }, { "name": "laravel/prompts", From 9fe1debbe8a237d16a1af0ccb54cf62350b83ccc Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 9 Jul 2024 18:50:01 -0400 Subject: [PATCH 22/67] fix: to array --- .../Connectors/Zoho/DataTransferObject/ZohoLead.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php b/src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php index f66681f9a..53153a77c 100644 --- a/src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php +++ b/src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php @@ -58,10 +58,11 @@ public static function fromLead(Lead $lead): self public function toArray(): array { - $data = parent::toArray(); - //unset($data['additionalFields']); + $data = array_merge(parent::toArray(), $this->additionalFields); + unset($data['additionalFields']); - return $data; + // Remove empty values + return array_filter($data, fn ($value) => ! empty($value)); } /** From febf96e084905ca13aed672bb006d3c42c7c5f86 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 9 Jul 2024 23:35:27 -0400 Subject: [PATCH 23/67] refact: fix close leads --- .../Zoho/Workflows/ZohoLeadActivity.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php index 41641c370..b5261837e 100644 --- a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php +++ b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php @@ -55,10 +55,21 @@ public function execute(Model $lead, AppInterface $app, array $params): array $zohoLeadId ); } else { - $zohoLead = $zohoCrm->leads->update( - (string) $zohoLeadId, - $zohoData - ); + $zohoLeadInfo = $zohoCrm->leads->get((string) $zohoLeadId)->getData(); + if (! empty($zohoLeadInfo)) { + $zohoLead = $zohoCrm->leads->update( + (string) $zohoLeadId, + $zohoData + ); + } else { + + $lead->close(); + return [ + 'zohoLeadId' => $zohoLeadId, + 'zohoRequest' => 'Lead not found in Zoho', + 'leadId' => $lead->getId(), + ]; + } } $this->uploadAttachments($zohoCrm->leads, $lead); From 1f71d458b6bd77485ef6d098fee91ac5d9467763 Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 9 Jul 2024 23:36:22 -0400 Subject: [PATCH 24/67] refact: fix close leads --- src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php index b5261837e..85906f0cb 100644 --- a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php +++ b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php @@ -62,8 +62,8 @@ public function execute(Model $lead, AppInterface $app, array $params): array $zohoData ); } else { - $lead->close(); + return [ 'zohoLeadId' => $zohoLeadId, 'zohoRequest' => 'Lead not found in Zoho', From 166356a9f60cb987819d33a99d8791d9bffa653f Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 10 Jul 2024 12:21:41 -0400 Subject: [PATCH 25/67] fix: fixes with shopify and zoho --- .../Actions/SyncShopifyOrderAction.php | 11 +++++++- .../Zoho/Actions/SyncZohoLeadAction.php | 1 + .../Zoho/Workflows/ZohoLeadActivity.php | 12 ++++++--- .../Souk/Orders/Actions/CreateOrderAction.php | 1 + .../Souk/Orders/DataTransferObject/Order.php | 10 ++++++++ src/Domains/Souk/Orders/Models/Order.php | 25 +++++++++++++++++++ 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php b/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php index de1bae7fa..1e7501f3c 100644 --- a/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php +++ b/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php @@ -76,10 +76,11 @@ public function execute(): ModelsOrder taxes: (float) $this->orderData['current_total_tax'], totalDiscount: (float) $this->orderData['total_discounts'], totalShipping: (float) $this->orderData['total_shipping_price_set']['shop_money']['amount'], - status: 'completed', + status: !empty($this->orderData['cancelled_at']) ? 'cancelled' : 'completed', orderNumber: (string) $this->orderData['order_number'], shippingMethod: $this->orderData['shipping_lines'][0]['title'] ?? null, currency: Currencies::getByCode($this->orderData['currency']), + fulfillmentStatus: $this->orderData['fulfillment_status'] ?? null, items: $this->getOrderItems(), metadata: json_encode($this->orderData), weight: $this->orderData['total_weight'], @@ -95,6 +96,14 @@ public function execute(): ModelsOrder ); if ($orderExist) { + if ($order->fulfill()) { + $orderExist->fulfill(); + } + + if ($order->isCancelled()) { + $orderExist->cancel(); + } + return $orderExist; } diff --git a/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php b/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php index b7609cac1..08685fd16 100644 --- a/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php +++ b/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php @@ -68,6 +68,7 @@ public function execute(): ?Lead $leadStatus = match (true) { Str::contains($status, 'close') => LeadStatus::getByName('bad'), Str::contains($status, 'won') => LeadStatus::getByName('complete'), + Str::contains($status, 'duplicate') => LeadStatus::getByName('complete'), default => LeadStatus::getByName('active'), }; diff --git a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php index 85906f0cb..973cf5c1c 100644 --- a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php +++ b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php @@ -39,12 +39,13 @@ public function execute(Model $lead, AppInterface $app, array $params): array $usesAgentsModule = $company->get(CustomFieldEnum::ZOHO_HAS_AGENTS_MODULE->value); $zohoCrm = Client::getInstance($app, $company); - - if ($usesAgentsModule) { - $this->assignAgent($app, $zohoLead, $lead, $company, $zohoData); - } + $status = 'created'; if (! $zohoLeadId = $lead->get(CustomFieldEnum::ZOHO_LEAD_ID->value)) { + if ($usesAgentsModule) { + $this->assignAgent($app, $zohoLead, $lead, $company, $zohoData); + } + $zohoLead = $zohoCrm->leads->create($zohoData); $zohoLeadId = $zohoLead->getId(); @@ -57,6 +58,7 @@ public function execute(Model $lead, AppInterface $app, array $params): array } else { $zohoLeadInfo = $zohoCrm->leads->get((string) $zohoLeadId)->getData(); if (! empty($zohoLeadInfo)) { + $status = 'updated'; $zohoLead = $zohoCrm->leads->update( (string) $zohoLeadId, $zohoData @@ -68,6 +70,7 @@ public function execute(Model $lead, AppInterface $app, array $params): array 'zohoLeadId' => $zohoLeadId, 'zohoRequest' => 'Lead not found in Zoho', 'leadId' => $lead->getId(), + 'status' => 'closed', ]; } } @@ -78,6 +81,7 @@ public function execute(Model $lead, AppInterface $app, array $params): array 'zohoLeadId' => $zohoLeadId, 'zohoRequest' => $zohoData, 'leadId' => $lead->getId(), + 'status' => $status, ]; } diff --git a/src/Domains/Souk/Orders/Actions/CreateOrderAction.php b/src/Domains/Souk/Orders/Actions/CreateOrderAction.php index d1e746631..72683e614 100644 --- a/src/Domains/Souk/Orders/Actions/CreateOrderAction.php +++ b/src/Domains/Souk/Orders/Actions/CreateOrderAction.php @@ -50,6 +50,7 @@ public function execute(): ModelsOrder $order->discount_amount = $this->orderData->totalDiscount; $order->status = $this->orderData->status; $order->shipping_method_name = $this->orderData->shippingMethod; + $order->fulfillment_status = $this->orderData->fulfillmentStatus; $order->weight = $this->orderData->weight; $order->checkout_token = $this->orderData->checkoutToken; $order->currency = $this->orderData->currency->code; diff --git a/src/Domains/Souk/Orders/DataTransferObject/Order.php b/src/Domains/Souk/Orders/DataTransferObject/Order.php index 5ce0a2695..3b681d423 100644 --- a/src/Domains/Souk/Orders/DataTransferObject/Order.php +++ b/src/Domains/Souk/Orders/DataTransferObject/Order.php @@ -49,4 +49,14 @@ public function __construct( public readonly array $paymentGatewayName = [], ) { } + + public function fulfill(): bool + { + return $this->fulfillmentStatus === 'fulfilled'; + } + + public function isCancelled(): bool + { + return $this->status === 'cancelled'; + } } diff --git a/src/Domains/Souk/Orders/Models/Order.php b/src/Domains/Souk/Orders/Models/Order.php index 4f9e6b88f..3c6d84723 100644 --- a/src/Domains/Souk/Orders/Models/Order.php +++ b/src/Domains/Souk/Orders/Models/Order.php @@ -48,6 +48,7 @@ * @property string $status * @property string|null $fulfillment_status * @property string|null $shipping_method_name + * @property string|null $fulfillment_status * @property int|null $shipping_method_id * @property bool $display_gross_prices * @property string|null $translated_discount_name @@ -147,4 +148,28 @@ public function addItem(OrderItemDto $item): OrderItem return $orderItem; } + + public function fulfill(): void + { + $this->fulfillment_status = 'fulfilled'; + $this->saveOrFail(); + } + + public function fulfillCancelled(): void + { + $this->fulfillment_status = 'cancelled'; + $this->saveOrFail(); + } + + public function completed(): void + { + $this->status = 'completed'; + $this->saveOrFail(); + } + + public function cancel(): void + { + $this->status = 'cancelled'; + $this->saveOrFail(); + } } From c418d2320cc14a5a378bf3dc0568aa7539575d76 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 10 Jul 2024 12:22:17 -0400 Subject: [PATCH 26/67] fix: fixes with shopify and zoho --- .../Connectors/Shopify/Actions/SyncShopifyOrderAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php b/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php index 1e7501f3c..a65aa948d 100644 --- a/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php +++ b/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php @@ -76,7 +76,7 @@ public function execute(): ModelsOrder taxes: (float) $this->orderData['current_total_tax'], totalDiscount: (float) $this->orderData['total_discounts'], totalShipping: (float) $this->orderData['total_shipping_price_set']['shop_money']['amount'], - status: !empty($this->orderData['cancelled_at']) ? 'cancelled' : 'completed', + status: ! empty($this->orderData['cancelled_at']) ? 'cancelled' : 'completed', orderNumber: (string) $this->orderData['order_number'], shippingMethod: $this->orderData['shipping_lines'][0]['title'] ?? null, currency: Currencies::getByCode($this->orderData['currency']), From 1a82be8b9abdbb9f06da9889bf1b1d4a24df1be3 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 10 Jul 2024 12:27:42 -0400 Subject: [PATCH 27/67] fix: fixes with shopify and zoho --- .../Shopify/Actions/SyncShopifyOrderAction.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php b/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php index a65aa948d..df942e8df 100644 --- a/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php +++ b/src/Domains/Connectors/Shopify/Actions/SyncShopifyOrderAction.php @@ -96,13 +96,11 @@ public function execute(): ModelsOrder ); if ($orderExist) { - if ($order->fulfill()) { - $orderExist->fulfill(); - } - - if ($order->isCancelled()) { - $orderExist->cancel(); - } + match (true) { + $order->fulfill() => $orderExist->fulfill(), + $order->isCancelled() => $orderExist->cancel(), + default => null, + }; return $orderExist; } From b8a44cbe0369e13e28a0feb959bada04d726b9b3 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 10 Jul 2024 13:30:44 -0400 Subject: [PATCH 28/67] fix: fixes with shopify and zoho --- database/migrations/Souk/2024_05_06_015856_add_order_table.php | 2 +- src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/database/migrations/Souk/2024_05_06_015856_add_order_table.php b/database/migrations/Souk/2024_05_06_015856_add_order_table.php index ed905b3d0..383fa58f2 100644 --- a/database/migrations/Souk/2024_05_06_015856_add_order_table.php +++ b/database/migrations/Souk/2024_05_06_015856_add_order_table.php @@ -33,7 +33,7 @@ public function up() $table->string('discount_name', 255)->nullable(); $table->unsignedBigInteger('voucher_id')->nullable()->index(); $table->string('language_code', 10)->nullable()->index(); - $table->enum('status', ['draft', 'completed', 'canceled'])->nullable()->index(); + $table->enum('status', ['draft', 'completed', 'canceled', 'cancelled'])->nullable()->index(); $table->string('shipping_method_name', 255)->nullable(); $table->unsignedBigInteger('shipping_method_id')->nullable()->index(); $table->boolean('display_gross_prices')->default(false); diff --git a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php index 973cf5c1c..25f3ecd5a 100644 --- a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php +++ b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php @@ -136,6 +136,7 @@ protected function assignAgent( if ($agentInfo && $agentInfo->get('over_write_owner')) { $zohoData['Owner'] = (int) $agentInfo->get('over_write_owner'); } + $zohoData['Lead_Source'] = $agent->name; } elseif ($agentInfo instanceof Agent) { $zohoData['Owner'] = (int) $agentInfo->owner_linked_source_id; if (empty($defaultLeadSource)) { From 4437d086d5e34ddd988673cc3aea1c903b46b1f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:30:48 +0000 Subject: [PATCH 29/67] build(deps-dev): bump phpunit/phpunit from 11.2.6 to 11.2.7 Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 11.2.6 to 11.2.7. - [Release notes](https://github.com/sebastianbergmann/phpunit/releases) - [Changelog](https://github.com/sebastianbergmann/phpunit/blob/11.2.7/ChangeLog-11.2.md) - [Commits](https://github.com/sebastianbergmann/phpunit/compare/11.2.6...11.2.7) --- updated-dependencies: - dependency-name: phpunit/phpunit dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- composer.lock | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/composer.lock b/composer.lock index 584c378e0..1e5e99a22 100644 --- a/composer.lock +++ b/composer.lock @@ -14461,16 +14461,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.2.6", + "version": "11.2.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1dc0fedac703199e8704de085e47dd46bac0dde4" + "reference": "15c7e69dec4a8f246840859e6b430bd2abeb5039" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1dc0fedac703199e8704de085e47dd46bac0dde4", - "reference": "1dc0fedac703199e8704de085e47dd46bac0dde4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/15c7e69dec4a8f246840859e6b430bd2abeb5039", + "reference": "15c7e69dec4a8f246840859e6b430bd2abeb5039", "shasum": "" }, "require": { @@ -14480,25 +14480,25 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", + "myclabs/deep-copy": "^1.12.0", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", "php": ">=8.2", - "phpunit/php-code-coverage": "^11.0", - "phpunit/php-file-iterator": "^5.0", - "phpunit/php-invoker": "^5.0", - "phpunit/php-text-template": "^4.0", - "phpunit/php-timer": "^7.0", - "sebastian/cli-parser": "^3.0", - "sebastian/code-unit": "^3.0", - "sebastian/comparator": "^6.0", - "sebastian/diff": "^6.0", - "sebastian/environment": "^7.0", - "sebastian/exporter": "^6.1.2", - "sebastian/global-state": "^7.0", - "sebastian/object-enumerator": "^6.0", - "sebastian/type": "^5.0", - "sebastian/version": "^5.0" + "phpunit/php-code-coverage": "^11.0.5", + "phpunit/php-file-iterator": "^5.0.1", + "phpunit/php-invoker": "^5.0.1", + "phpunit/php-text-template": "^4.0.1", + "phpunit/php-timer": "^7.0.1", + "sebastian/cli-parser": "^3.0.2", + "sebastian/code-unit": "^3.0.1", + "sebastian/comparator": "^6.0.1", + "sebastian/diff": "^6.0.2", + "sebastian/environment": "^7.2.0", + "sebastian/exporter": "^6.1.3", + "sebastian/global-state": "^7.0.2", + "sebastian/object-enumerator": "^6.0.1", + "sebastian/type": "^5.0.1", + "sebastian/version": "^5.0.1" }, "suggest": { "ext-soap": "To be able to generate mocks based on WSDL files" @@ -14541,7 +14541,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.6" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.2.7" }, "funding": [ { @@ -14557,7 +14557,7 @@ "type": "tidelift" } ], - "time": "2024-07-03T05:51:49+00:00" + "time": "2024-07-10T11:50:09+00:00" }, { "name": "sebastian/cli-parser", From 272ca7246a821ee72a1527f94e0cdd2f2d946771 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:30:53 +0000 Subject: [PATCH 30/67] build(deps): bump google/apiclient from 2.16.0 to 2.17.0 Bumps [google/apiclient](https://github.com/googleapis/google-api-php-client) from 2.16.0 to 2.17.0. - [Release notes](https://github.com/googleapis/google-api-php-client/releases) - [Changelog](https://github.com/googleapis/google-api-php-client/blob/main/CHANGELOG.md) - [Commits](https://github.com/googleapis/google-api-php-client/compare/v2.16.0...v2.17.0) --- updated-dependencies: - dependency-name: google/apiclient dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/composer.lock b/composer.lock index 584c378e0..948765e16 100644 --- a/composer.lock +++ b/composer.lock @@ -2434,34 +2434,34 @@ }, { "name": "google/apiclient", - "version": "v2.16.0", + "version": "v2.17.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-api-php-client.git", - "reference": "017400f609c1fb71ab5ad824c50eabd4c3eaf779" + "reference": "b1f63d72c44307ec8ef7bf18f1012de35d8944ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/017400f609c1fb71ab5ad824c50eabd4c3eaf779", - "reference": "017400f609c1fb71ab5ad824c50eabd4c3eaf779", + "url": "https://api.github.com/repos/googleapis/google-api-php-client/zipball/b1f63d72c44307ec8ef7bf18f1012de35d8944ed", + "reference": "b1f63d72c44307ec8ef7bf18f1012de35d8944ed", "shasum": "" }, "require": { - "firebase/php-jwt": "~6.0", + "firebase/php-jwt": "^6.0", "google/apiclient-services": "~0.350", "google/auth": "^1.37", - "guzzlehttp/guzzle": "^6.5.8||^7.4.5", - "guzzlehttp/psr7": "^1.9.1||^2.2.1", + "guzzlehttp/guzzle": "^7.4.5", + "guzzlehttp/psr7": "^2.6", "monolog/monolog": "^2.9||^3.0", - "php": "^7.4|^8.0", + "php": "^8.0", "phpseclib/phpseclib": "^3.0.36" }, "require-dev": { "cache/filesystem-adapter": "^1.1", "composer/composer": "^1.10.23", "phpcompatibility/php-compatibility": "^9.2", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.5", + "phpspec/prophecy-phpunit": "^2.1", + "phpunit/phpunit": "^9.6", "squizlabs/php_codesniffer": "^3.8", "symfony/css-selector": "~2.1", "symfony/dom-crawler": "~2.1" @@ -2497,22 +2497,22 @@ ], "support": { "issues": "https://github.com/googleapis/google-api-php-client/issues", - "source": "https://github.com/googleapis/google-api-php-client/tree/v2.16.0" + "source": "https://github.com/googleapis/google-api-php-client/tree/v2.17.0" }, - "time": "2024-04-24T00:59:47+00:00" + "time": "2024-07-10T14:57:54+00:00" }, { "name": "google/apiclient-services", - "version": "v0.362.0", + "version": "v0.363.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-api-php-client-services.git", - "reference": "c5016217c8aba823a8ebeed6ccd75d93522e3311" + "reference": "5a0943e498e98e23dccdd98c5a3f74bc1b442053" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/c5016217c8aba823a8ebeed6ccd75d93522e3311", - "reference": "c5016217c8aba823a8ebeed6ccd75d93522e3311", + "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/5a0943e498e98e23dccdd98c5a3f74bc1b442053", + "reference": "5a0943e498e98e23dccdd98c5a3f74bc1b442053", "shasum": "" }, "require": { @@ -2541,22 +2541,22 @@ ], "support": { "issues": "https://github.com/googleapis/google-api-php-client-services/issues", - "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.362.0" + "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.363.0" }, - "time": "2024-06-28T01:06:13+00:00" + "time": "2024-07-02T01:04:18+00:00" }, { "name": "google/auth", - "version": "v1.40.0", + "version": "v1.41.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-auth-library-php.git", - "reference": "bff9f2d01677e71a98394b5ac981b99523df5178" + "reference": "1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/bff9f2d01677e71a98394b5ac981b99523df5178", - "reference": "bff9f2d01677e71a98394b5ac981b99523df5178", + "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038", + "reference": "1043ea18fe7f5dfbf5b208ce3ee6d6b6ab8cb038", "shasum": "" }, "require": { @@ -2601,9 +2601,9 @@ "support": { "docs": "https://googleapis.github.io/google-auth-library-php/main/", "issues": "https://github.com/googleapis/google-auth-library-php/issues", - "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.40.0" + "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.41.0" }, - "time": "2024-05-31T19:16:15+00:00" + "time": "2024-07-10T15:21:07+00:00" }, { "name": "google/cloud-core", From 0ee93937c0f05aa0fef6661043fcfd7dbb4a557f Mon Sep 17 00:00:00 2001 From: kaioken Date: Thu, 11 Jul 2024 00:06:02 -0400 Subject: [PATCH 31/67] fix: rouge workflow --- .../Zoho/Actions/SyncZohoLeadAction.php | 28 ++++++++----------- .../Zoho/DataTransferObject/ZohoLead.php | 2 ++ .../Guild/Leads/Actions/CreateLeadAction.php | 6 ++-- .../Leads/Jobs/CreateLeadsFromReceiverJob.php | 1 + 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php b/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php index 08685fd16..6e8b2d641 100644 --- a/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php +++ b/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php @@ -97,12 +97,12 @@ public function execute(): ?Lead } $lead = new DataTransferObjectLead( - $this->app, - $this->company->defaultBranch, - $user ?? $this->company->user, - $zohoLead->Full_Name, - $pipelineStage->getId(), - new People( + app: $this->app, + branch: $this->company->defaultBranch, + user: $user ?? $this->company->user, + title: $zohoLead->Full_Name, + pipeline_stage_id: $pipelineStage->getId(), + people: new People( $this->app, $this->company->defaultBranch, $user ?? $this->company->user, @@ -111,19 +111,13 @@ public function execute(): ?Lead Address::collect([], DataCollection::class), $zohoLead->Last_Name ), - $user ? $user->getId() : 0, - 0, - $leadStatus->getId(), - 0, - $this->receiver->getId(), - null, - null, - null, - [ + leads_owner_id: $user ? $user->getId() : 0, + status_id: $leadStatus->getId(), + receiver_id: $this->receiver->getId(), + custom_fields: [ CustomFieldEnum::ZOHO_LEAD_ID->value => $this->zohoLeadId, ], - [], - true + runWorkflow: false ); return (new CreateLeadAction($lead))->execute(); diff --git a/src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php b/src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php index 53153a77c..c34deaf49 100644 --- a/src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php +++ b/src/Domains/Connectors/Zoho/DataTransferObject/ZohoLead.php @@ -41,6 +41,8 @@ public static function fromLead(Lead $lead): self $people = $lead->people()->first(); $leadStatus = $lead->status()->first(); $owner = (string) ($lead->owner()->first() ? $company->get(CustomFieldEnum::DEFAULT_OWNER->value) : null); + + //@todo get the lead status from zoho $newLead = 'New Lead'; $status = $leadStatus ? ($leadStatus->get(CustomFieldEnum::ZOHO_STATUS_NAME->value) ?? $newLead) : $newLead; diff --git a/src/Domains/Guild/Leads/Actions/CreateLeadAction.php b/src/Domains/Guild/Leads/Actions/CreateLeadAction.php index bd4270dda..b50613eeb 100644 --- a/src/Domains/Guild/Leads/Actions/CreateLeadAction.php +++ b/src/Domains/Guild/Leads/Actions/CreateLeadAction.php @@ -61,12 +61,12 @@ public function execute(): Lead $newLead->people_id = $people->getId(); $newLead->email = $people->getEmails()->isNotEmpty() ? $people->getEmails()->first()?->value : null; $newLead->phone = $people->getPhones()->isNotEmpty() ? $people->getPhones()->first()?->value : null; - $newLead->saveOrFail(); - - $newLead->setCustomFields($this->leadData->custom_fields); if (! $this->leadData->runWorkflow) { $newLead->disableWorkflows(); } + $newLead->saveOrFail(); + + $newLead->setCustomFields($this->leadData->custom_fields); $newLead->saveCustomFields(); if ($this->leadData->files) { diff --git a/src/Domains/Guild/Leads/Jobs/CreateLeadsFromReceiverJob.php b/src/Domains/Guild/Leads/Jobs/CreateLeadsFromReceiverJob.php index b401530ca..f10eaa8e9 100644 --- a/src/Domains/Guild/Leads/Jobs/CreateLeadsFromReceiverJob.php +++ b/src/Domains/Guild/Leads/Jobs/CreateLeadsFromReceiverJob.php @@ -40,6 +40,7 @@ public function execute(): array $payload = $parseTemplate->execute(); } + $payload['receiver_id'] = $leadReceiver->getId(); $createLead = new CreateLeadAction( Lead::viaRequest( $leadReceiver->user, From 423c029666fcc4fea91ae810016c233e3fccc24f Mon Sep 17 00:00:00 2001 From: kaioken Date: Thu, 11 Jul 2024 13:27:57 -0400 Subject: [PATCH 32/67] refact: msg reciever --- .../ShopifyInventoryDownloadCommand.php | 2 +- .../Messages/MessageManagementMutation.php | 5 ---- .../Zoho/Workflows/ZohoLeadActivity.php | 10 ++++++-- .../Jobs/CreateMessageFromReceiverJob.php | 24 ++++++++++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/Connectors/Shopify/ShopifyInventoryDownloadCommand.php b/app/Console/Commands/Connectors/Shopify/ShopifyInventoryDownloadCommand.php index ab96cdca4..397662757 100644 --- a/app/Console/Commands/Connectors/Shopify/ShopifyInventoryDownloadCommand.php +++ b/app/Console/Commands/Connectors/Shopify/ShopifyInventoryDownloadCommand.php @@ -17,7 +17,7 @@ class ShopifyInventoryDownloadCommand extends Command * * @var string */ - protected $signature = '343 {app_id} {branch_id} {warehouse_id}'; + protected $signature = 'kanvas:inventory-shopify-sync {app_id} {branch_id} {warehouse_id}'; /** * The console command description. diff --git a/app/GraphQL/Social/Mutations/Messages/MessageManagementMutation.php b/app/GraphQL/Social/Mutations/Messages/MessageManagementMutation.php index 8f3f0c666..0cdefc2fe 100644 --- a/app/GraphQL/Social/Mutations/Messages/MessageManagementMutation.php +++ b/app/GraphQL/Social/Mutations/Messages/MessageManagementMutation.php @@ -10,17 +10,12 @@ use Kanvas\Apps\Models\Apps; use Kanvas\Auth\Exceptions\AuthenticationException; use Kanvas\Exceptions\ValidationException; -use Kanvas\Social\Enums\InteractionEnum; -use Kanvas\Social\Interactions\Actions\CreateInteraction; -use Kanvas\Social\Interactions\DataTransferObject\Interaction; use Kanvas\Social\Messages\Actions\CreateMessageAction; use Kanvas\Social\Messages\Actions\DistributeChannelAction; use Kanvas\Social\Messages\Actions\DistributeToUsers; use Kanvas\Social\Messages\DataTransferObject\MessageInput; -use Kanvas\Social\Messages\Enums\ActivityTypeEnum; use Kanvas\Social\Messages\Enums\DistributionTypeEnum; use Kanvas\Social\Messages\Models\Message; -use Kanvas\Social\Messages\Services\MessageInteractionService; use Kanvas\Social\Messages\Validations\ValidParentMessage; use Kanvas\Social\MessagesTypes\Actions\CreateMessageTypeAction; use Kanvas\Social\MessagesTypes\DataTransferObject\MessageTypeInput; diff --git a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php index 25f3ecd5a..35424abe3 100644 --- a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php +++ b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php @@ -123,7 +123,13 @@ protected function assignAgent( } if (is_object($agent)) { - $zohoData['Owner'] = (int) $agent->Owner['id']; + try { + ///lead owner should match lead routing + $zohoData['Owner'] = $zohoService->getAgentByEmail($agent->Lead_Routing)->Owner['id']; + } catch (Throwable $e) { + $zohoData['Owner'] = (int) $agent->Owner['id']; + } + if ($agent->Sponsor) { $zohoData['Sponsor'] = (string) $agent->Sponsor; } @@ -136,7 +142,7 @@ protected function assignAgent( if ($agentInfo && $agentInfo->get('over_write_owner')) { $zohoData['Owner'] = (int) $agentInfo->get('over_write_owner'); } - $zohoData['Lead_Source'] = $agent->name; + $zohoData['Lead_Source'] = $agent->name ?? $agent->Name; } elseif ($agentInfo instanceof Agent) { $zohoData['Owner'] = (int) $agentInfo->owner_linked_source_id; if (empty($defaultLeadSource)) { diff --git a/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php b/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php index 6f60e3dc3..31947cd81 100644 --- a/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php +++ b/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php @@ -7,7 +7,10 @@ use Exception; use Illuminate\Database\Eloquent\ModelNotFoundException; use Kanvas\Social\Messages\Actions\CreateMessageAction; +use Kanvas\Social\Messages\Actions\DistributeChannelAction; +use Kanvas\Social\Messages\Actions\DistributeToUsers; use Kanvas\Social\Messages\DataTransferObject\MessageInput; +use Kanvas\Social\Messages\Enums\DistributionTypeEnum; use Kanvas\Social\MessagesTypes\Actions\CreateMessageTypeAction; use Kanvas\Social\MessagesTypes\DataTransferObject\MessageTypeInput; use Kanvas\Social\MessagesTypes\Repositories\MessagesTypesRepository; @@ -37,11 +40,12 @@ public function execute(): array $messageType = (new CreateMessageTypeAction($messageTypeDto))->execute(); } + $user = $this->receiver->user; $createMessage = new CreateMessageAction( new MessageInput( app: $this->receiver->app, company: $this->receiver->company, - user: $this->receiver->user, + user: $user, type: $messageType, message: $payload['message'] ) @@ -49,6 +53,24 @@ public function execute(): array $message = $createMessage->execute(); + /** + * @todo refactor this logic here and in message mutation to avoid duplication + */ + if (key_exists('distribution', $payload)) { + $distributionType = DistributionTypeEnum::from($payload['distribution']['distributionType']); + + if ($distributionType->value == DistributionTypeEnum::ALL->value) { + $channels = key_exists('channels', $payload['distribution']) ? $payload['distribution']['channels'] : []; + (new DistributeChannelAction($channels, $message, $user))->execute(); + (new DistributeToUsers($message))->execute(); + } elseif ($distributionType->value == DistributionTypeEnum::Channels->value) { + $channels = key_exists('channels', $payload['distribution']) ? $payload['distribution']['channels'] : []; + (new DistributeChannelAction($channels, $message, $user))->execute(); + } elseif ($distributionType->value == DistributionTypeEnum::Followers->value) { + (new DistributeToUsers($message))->execute(); + } + } + return [ 'message' => 'Message created successfully from receiver with id ' . $message->getId(), 'message_id' => $message->getId(), From b582a34f910888cccb0a1d2fa20cf0f4c994e02f Mon Sep 17 00:00:00 2001 From: kaioken Date: Thu, 11 Jul 2024 16:00:03 -0400 Subject: [PATCH 33/67] fix: shopify client --- src/Domains/Connectors/Shopify/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Domains/Connectors/Shopify/Client.php b/src/Domains/Connectors/Shopify/Client.php index 6a88d153f..55a47450b 100644 --- a/src/Domains/Connectors/Shopify/Client.php +++ b/src/Domains/Connectors/Shopify/Client.php @@ -6,6 +6,7 @@ use Baka\Contracts\AppInterface; use Baka\Contracts\CompanyInterface; +use Baka\Support\Str; use Kanvas\Connectors\Shopify\Enums\CustomFieldEnum; use Kanvas\Connectors\Shopify\Services\ShopifyConfigurationService; use Kanvas\Exceptions\ValidationException; @@ -59,7 +60,7 @@ public static function getKeys(CompanyInterface $company, AppInterface $app, Reg $credential = $company->get($clientCredentialNaming); // its no supposed to explode with this - if (empty($credential)) { + if (empty($credential) || ! Str::isJson($credential)) { throw new ValidationException( 'Shopify keys are not set for company ' . $company->name . ' ' . $company->id . ' ' . 'on region ' . $region->name ); From 12563fdd633b0eb6aed9b24ebbe1c1412d11e858 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Jul 2024 22:19:43 +0000 Subject: [PATCH 34/67] build(deps): bump sentry/sentry-laravel from 4.6.1 to 4.7.0 Bumps [sentry/sentry-laravel](https://github.com/getsentry/sentry-laravel) from 4.6.1 to 4.7.0. - [Release notes](https://github.com/getsentry/sentry-laravel/releases) - [Changelog](https://github.com/getsentry/sentry-laravel/blob/master/CHANGELOG.md) - [Commits](https://github.com/getsentry/sentry-laravel/compare/4.6.1...4.7.0) --- updated-dependencies: - dependency-name: sentry/sentry-laravel dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index e7a000d95..9aea50c7a 100644 --- a/composer.lock +++ b/composer.lock @@ -8669,16 +8669,16 @@ }, { "name": "sentry/sentry-laravel", - "version": "4.6.1", + "version": "4.7.0", "source": { "type": "git", "url": "https://github.com/getsentry/sentry-laravel.git", - "reference": "7f5fd9f362e440c4c0c492f386b93095321f9101" + "reference": "44151798253145c1abc7fe7e38210b98f926d794" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/getsentry/sentry-laravel/zipball/7f5fd9f362e440c4c0c492f386b93095321f9101", - "reference": "7f5fd9f362e440c4c0c492f386b93095321f9101", + "url": "https://api.github.com/repos/getsentry/sentry-laravel/zipball/44151798253145c1abc7fe7e38210b98f926d794", + "reference": "44151798253145c1abc7fe7e38210b98f926d794", "shasum": "" }, "require": { @@ -8742,7 +8742,7 @@ ], "support": { "issues": "https://github.com/getsentry/sentry-laravel/issues", - "source": "https://github.com/getsentry/sentry-laravel/tree/4.6.1" + "source": "https://github.com/getsentry/sentry-laravel/tree/4.7.0" }, "funding": [ { @@ -8754,7 +8754,7 @@ "type": "custom" } ], - "time": "2024-06-18T15:06:09+00:00" + "time": "2024-07-10T21:55:04+00:00" }, { "name": "shopify/shopify-api", From 31bf13478a6af471096a7ca6061d67d206e76e28 Mon Sep 17 00:00:00 2001 From: kaioken Date: Thu, 11 Jul 2024 18:48:43 -0400 Subject: [PATCH 35/67] fix: email --- src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php index 35424abe3..29285b7bb 100644 --- a/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php +++ b/src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php @@ -125,9 +125,11 @@ protected function assignAgent( if (is_object($agent)) { try { ///lead owner should match lead routing - $zohoData['Owner'] = $zohoService->getAgentByEmail($agent->Lead_Routing)->Owner['id']; + $leadRoutingEmailCleanUp = preg_replace('/[^a-zA-Z0-9@._-]/', '', $agent->Lead_Routing); + $zohoData['Owner'] = $zohoService->getAgentByEmail($leadRoutingEmailCleanUp)->Owner['id']; } catch (Throwable $e) { - $zohoData['Owner'] = (int) $agent->Owner['id']; + //send fail notification and assign to default lead routing email + $zohoData['Owner'] = (int) ($app->get(CustomFieldEnum::DEFAULT_OWNER->value) ?? $agent->Owner['id']); } if ($agent->Sponsor) { From 2a63481ff13f84152bd40dcf1b86b7c792d144df Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 07:03:54 -0400 Subject: [PATCH 36/67] refact: dev and prod same --- docker-compose.development.yml | 104 +++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 36 deletions(-) diff --git a/docker-compose.development.yml b/docker-compose.development.yml index c08250deb..489bb435f 100644 --- a/docker-compose.development.yml +++ b/docker-compose.development.yml @@ -1,11 +1,16 @@ version: '3.8' -x-common-settings: &common-settings +x-common-queue-settings: &common-queue-settings + restart: always build: context: . dockerfile: development.Dockerfile extra_hosts: - "host.docker.internal:host-gateway" + command: + - "sh" + - "-c" + - "php artisan config:cache && php artisan queue:work --tries=3 --timeout=3750" environment: WWWUSER: "${WWWUSER}" LARAVEL_SAIL: 1 @@ -18,62 +23,89 @@ x-common-settings: &common-settings networks: - sail -x-common-queue-command: &common-queue-command - [ - "sh", - "-c", - "php artisan config:cache && php artisan queue:work --tries=3 --timeout=3750", - ] - services: php: container_name: php${APP_CONTAINER_NAME} - <<: *common-settings + build: + context: . + dockerfile: development.Dockerfile + extra_hosts: + - "host.docker.internal:host-gateway" + environment: + WWWUSER: "${WWWUSER}" + LARAVEL_SAIL: 1 + XDEBUG_MODE: "${SAIL_XDEBUG_MODE:-off}" + XDEBUG_CONFIG: "${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}" + volumes: + - ".:/var/www/html" + - ./docker/docker-php-ext-opcache.ini:/usr/local/etc/php/conf.d/docker-php-ext-opcache.ini + - ./docker/php.ini:/usr/local/etc/php/conf.d/xz-custom.ini + networks: + - sail queue: + <<: *common-queue-settings container_name: queue - <<: *common-settings - command: *common-queue-command queue2: + <<: *common-queue-settings container_name: queue2 - <<: *common-settings - command: *common-queue-command queue3: + <<: *common-queue-settings container_name: queue3 - <<: *common-settings - command: *common-queue-command + + queue4: + <<: *common-queue-settings + container_name: queue4 + + queue5: + <<: *common-queue-settings + container_name: queue5 + + queue6: + <<: *common-queue-settings + container_name: queue6 queue-social: + <<: *common-queue-settings container_name: queue-social - <<: *common-settings - command: - [ - "sh", - "-c", - "php artisan config:cache && php artisan queue:work --queue kanvas-social --tries=3 --timeout=3750", - ] + command: + - "sh" + - "-c" + - "php artisan config:cache && php artisan queue:work --queue kanvas-social --tries=3 --timeout=3750" queue-notifications: + <<: *common-queue-settings container_name: queue-notifications - <<: *common-settings - command: - [ - "sh", - "-c", - "php artisan config:cache && php artisan queue:work --queue notifications --tries=3 --timeout=3750", - ] + command: + - "sh" + - "-c" + - "php artisan config:cache && php artisan queue:work --queue notifications --tries=3 --timeout=3750" laravel-scheduler: container_name: laravel-scheduler - <<: *common-settings - command: - [ - "sh", - "-c", - "php artisan config:cache && php artisan schedule:work", - ] + restart: always + build: + context: . + dockerfile: development.Dockerfile + extra_hosts: + - "host.docker.internal:host-gateway" + command: + - "sh" + - "-c" + - "php artisan config:cache && php artisan schedule:work" + environment: + WWWUSER: "${WWWUSER}" + LARAVEL_SAIL: 1 + XDEBUG_MODE: "${SAIL_XDEBUG_MODE:-off}" + XDEBUG_CONFIG: "${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}" + volumes: + - ".:/var/www/html" + - ./docker/docker-php-ext-opcache.ini:/usr/local/etc/php/conf.d/docker-php-ext-opcache.ini + - ./docker/php.ini:/usr/local/etc/php/conf.d/xz-custom.ini + networks: + - sail nginx: image: nginx:latest From e46dd2b6d4756da9bf3a8e22449edd9e72e27080 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 07:10:23 -0400 Subject: [PATCH 37/67] fix: shopify validation --- src/Domains/Connectors/Shopify/Client.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Domains/Connectors/Shopify/Client.php b/src/Domains/Connectors/Shopify/Client.php index 55a47450b..9d0a7ef8c 100644 --- a/src/Domains/Connectors/Shopify/Client.php +++ b/src/Domains/Connectors/Shopify/Client.php @@ -6,7 +6,6 @@ use Baka\Contracts\AppInterface; use Baka\Contracts\CompanyInterface; -use Baka\Support\Str; use Kanvas\Connectors\Shopify\Enums\CustomFieldEnum; use Kanvas\Connectors\Shopify\Services\ShopifyConfigurationService; use Kanvas\Exceptions\ValidationException; @@ -60,7 +59,7 @@ public static function getKeys(CompanyInterface $company, AppInterface $app, Reg $credential = $company->get($clientCredentialNaming); // its no supposed to explode with this - if (empty($credential) || ! Str::isJson($credential)) { + if (empty($credential) || ! is_array($credential)) { throw new ValidationException( 'Shopify keys are not set for company ' . $company->name . ' ' . $company->id . ' ' . 'on region ' . $region->name ); From ae7feb1ea3560a53f9c482abd8f499468bf420ad Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 08:12:35 -0400 Subject: [PATCH 38/67] fix: test --- composer.lock | 50 +++++++++---------- ...024_06_25_032857_peoples_subscriptions.php | 20 +++++--- .../Stripe/Enums/ConfigurationEnum.php | 10 ++++ .../Jobs/UpdatePeopleStripeSubscription.php | 6 ++- .../CreateOrUpdatePeopleSubscription.php | 2 +- .../DataTransferObject/PeopleSubscription.php | 2 +- .../Stripe/UpdateSubscriptionTest.php | 8 ++- 7 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 src/Domains/Connectors/Stripe/Enums/ConfigurationEnum.php diff --git a/composer.lock b/composer.lock index 959529fb0..fa72f837d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "66a75e57f8f8feba0b4e9acf4ac16f7c", + "content-hash": "9fe1b13ba14b05cd9bf48c1443242686", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -1195,16 +1195,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.315.5", + "version": "3.316.2", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "3e6d619d45d8e1a8681dd58de61ddfe90e8341e6" + "reference": "4d8caae512c3be4d59ee6d583b3f82872dde5071" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3e6d619d45d8e1a8681dd58de61ddfe90e8341e6", - "reference": "3e6d619d45d8e1a8681dd58de61ddfe90e8341e6", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/4d8caae512c3be4d59ee6d583b3f82872dde5071", + "reference": "4d8caae512c3be4d59ee6d583b3f82872dde5071", "shasum": "" }, "require": { @@ -1284,9 +1284,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.315.5" + "source": "https://github.com/aws/aws-sdk-php/tree/3.316.2" }, - "time": "2024-07-03T18:12:51+00:00" + "time": "2024-07-10T19:16:28+00:00" }, { "name": "berkayk/onesignal-laravel", @@ -2673,16 +2673,16 @@ }, { "name": "google/cloud-storage", - "version": "v1.42.0", + "version": "v1.42.1", "source": { "type": "git", "url": "https://github.com/googleapis/google-cloud-php-storage.git", - "reference": "1c77f5882c30bec95ab2837b9534a946325d1c57" + "reference": "2a418cad887e44d08a86de19a878ea3607212edb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-cloud-php-storage/zipball/1c77f5882c30bec95ab2837b9534a946325d1c57", - "reference": "1c77f5882c30bec95ab2837b9534a946325d1c57", + "url": "https://api.github.com/repos/googleapis/google-cloud-php-storage/zipball/2a418cad887e44d08a86de19a878ea3607212edb", + "reference": "2a418cad887e44d08a86de19a878ea3607212edb", "shasum": "" }, "require": { @@ -2724,9 +2724,9 @@ ], "description": "Cloud Storage Client for PHP", "support": { - "source": "https://github.com/googleapis/google-cloud-php-storage/tree/v1.42.0" + "source": "https://github.com/googleapis/google-cloud-php-storage/tree/v1.42.1" }, - "time": "2024-05-19T17:27:42+00:00" + "time": "2024-07-08T23:14:13+00:00" }, { "name": "google/common-protos", @@ -6712,16 +6712,16 @@ }, { "name": "php-amqplib/php-amqplib", - "version": "v3.6.2", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/php-amqplib/php-amqplib.git", - "reference": "cb514530ce45a6d2f636be5196010c47c3bcf6e0" + "reference": "91fd00e74cd2eea624fd50a321d926b1c124bb99" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/cb514530ce45a6d2f636be5196010c47c3bcf6e0", - "reference": "cb514530ce45a6d2f636be5196010c47c3bcf6e0", + "url": "https://api.github.com/repos/php-amqplib/php-amqplib/zipball/91fd00e74cd2eea624fd50a321d926b1c124bb99", + "reference": "91fd00e74cd2eea624fd50a321d926b1c124bb99", "shasum": "" }, "require": { @@ -6787,9 +6787,9 @@ ], "support": { "issues": "https://github.com/php-amqplib/php-amqplib/issues", - "source": "https://github.com/php-amqplib/php-amqplib/tree/v3.6.2" + "source": "https://github.com/php-amqplib/php-amqplib/tree/v3.7.0" }, - "time": "2024-04-15T18:31:22+00:00" + "time": "2024-07-09T21:10:28+00:00" }, { "name": "php-http/client-common", @@ -9733,16 +9733,16 @@ }, { "name": "stripe/stripe-php", - "version": "v15.0.0", + "version": "v15.2.0", "source": { "type": "git", "url": "https://github.com/stripe/stripe-php.git", - "reference": "96f0dbe9c2b5365d716f86d92a27feecca2cbaee" + "reference": "29a28251d35dba236ad6e860e1927b3f35cc1b2e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/stripe/stripe-php/zipball/96f0dbe9c2b5365d716f86d92a27feecca2cbaee", - "reference": "96f0dbe9c2b5365d716f86d92a27feecca2cbaee", + "url": "https://api.github.com/repos/stripe/stripe-php/zipball/29a28251d35dba236ad6e860e1927b3f35cc1b2e", + "reference": "29a28251d35dba236ad6e860e1927b3f35cc1b2e", "shasum": "" }, "require": { @@ -9786,9 +9786,9 @@ ], "support": { "issues": "https://github.com/stripe/stripe-php/issues", - "source": "https://github.com/stripe/stripe-php/tree/v15.0.0" + "source": "https://github.com/stripe/stripe-php/tree/v15.2.0" }, - "time": "2024-06-24T23:05:11+00:00" + "time": "2024-07-11T18:46:58+00:00" }, { "name": "symfony/cache", diff --git a/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php b/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php index 84419a8e7..e31967662 100644 --- a/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php +++ b/database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php @@ -12,18 +12,22 @@ public function up(): void { Schema::create('peoples_subscriptions', function (Blueprint $table) { $table->id(); - $table->bigInteger('apps_id')->unsigned(); - $table->bigInteger('peoples_id')->unsigned(); - $table->string('subscription_type'); - $table->string('status'); + $table->bigInteger('apps_id')->unsigned()->index(); + $table->bigInteger('peoples_id')->unsigned()->index(); + $table->string('subscription_type')->index(); + $table->string('status')->index(); $table->date('first_date'); $table->date('start_date'); - $table->date('end_date')->nullable(); - $table->date('next_renewal')->nullable(); - $table->text('metadata')->nullable(); - $table->boolean('is_deleted')->default(0); + $table->date('end_date')->nullable()->index(); + $table->date('next_renewal')->nullable()->index(); + $table->json('metadata')->nullable(); + $table->boolean('is_deleted')->default(0)->index(); $table->dateTime('created_at')->index('created_at'); $table->dateTime('updated_at')->nullable()->index('updated_at'); + + //index apps people + $table->index(['apps_id', 'peoples_id']); + $table->index(['peoples_id', 'subscription_type']); }); } diff --git a/src/Domains/Connectors/Stripe/Enums/ConfigurationEnum.php b/src/Domains/Connectors/Stripe/Enums/ConfigurationEnum.php new file mode 100644 index 000000000..33e68de7f --- /dev/null +++ b/src/Domains/Connectors/Stripe/Enums/ConfigurationEnum.php @@ -0,0 +1,10 @@ +data = $this->webhookRequest->payload; $webhookSub = $this->data['data']['object']; $app = $this->webhookRequest->receiverWebhook->app; $company = $this->webhookRequest->receiverWebhook->company; $user = $this->webhookRequest->receiverWebhook->user; - $stripe = new StripeClient($app->get('stripe_secret_key')); + $stripe = new StripeClient($app->get(ConfigurationEnum::STRIPE_SECRET_KEY->value)); $customer = $stripe->customers->retrieve( $webhookSub['customer'], ['expand' => ['subscriptions']] @@ -59,7 +61,7 @@ public function execute(): array start_date: date('Y-m-d H:i:s', $subscriptions['current_period_start']), end_date: date('Y-m-d H:i:s', $subscriptions['ended_at']), next_renewal: date('Y-m-d H:i:s', $subscriptions['current_period_end']), - metadata: json_encode($this->data), + metadata: $this->data ?? [], ); $action = new CreateOrUpdatePeopleSubscription($dto); $peopleSub = $action->handle(); diff --git a/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php b/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php index b48685e9c..f95c0a380 100644 --- a/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php +++ b/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php @@ -23,7 +23,7 @@ public function handle(): PeopleSubscription 'start_date' => $this->peopleSubscriptionDTO->start_date, 'end_date' => $this->peopleSubscriptionDTO->end_date, 'next_renewal' => $this->peopleSubscriptionDTO->next_renewal, - 'metadata' => json_encode($this->peopleSubscriptionDTO->metadata), + 'metadata' => $this->peopleSubscriptionDTO->metadata, 'apps_id' => $this->peopleSubscriptionDTO->app->getId(), ]; diff --git a/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php b/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php index 048ed51cd..2cc66e3ac 100644 --- a/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php +++ b/src/Domains/Guild/Customers/DataTransferObject/PeopleSubscription.php @@ -19,7 +19,7 @@ public function __construct( public string $start_date, public ?string $end_date = null, public ?string $next_renewal = null, - public ?string $metadata = null, + public array $metadata = [], ) { } } diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php index 33d3fa45b..63baacc06 100644 --- a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Request; use Kanvas\Apps\Models\Apps; +use Kanvas\Connectors\Stripe\Enums\ConfigurationEnum; use Kanvas\Connectors\Stripe\Jobs\UpdatePeopleStripeSubscription; use Kanvas\Guild\Customers\Models\Contact; use Kanvas\Guild\Customers\Models\People; @@ -16,6 +17,7 @@ use Stripe\StripeClient; use Tests\TestCase; use Throwable; + final class UpdateSubscriptionTest extends TestCase { public function testUpdateSubscription() @@ -30,7 +32,8 @@ public function testUpdateSubscription() ->has(Contact::factory()->count(1), 'contacts') ->create(); - $stripe = new StripeClient(getenv('STRIPE_SECRET_KEY')); + $app->set(ConfigurationEnum::STRIPE_SECRET_KEY->value, getenv('STRIPE_SECRET_KEY')); + $stripe = new StripeClient($app->get(ConfigurationEnum::STRIPE_SECRET_KEY->value)); $customer = $stripe->customers->create([ 'email' => $people->getEmails()[0]->value, 'name' => $people->getName(), @@ -91,13 +94,14 @@ public function testUpdateSubscription() // Fake the queue Queue::fake(); $job = new UpdatePeopleStripeSubscription($webhookRequest); + try { $job->handle(); } catch (Throwable $e) { $this->fail($e->getMessage()); - } $result = $job->handle(); + $this->assertArrayHasKey('message', $result); $this->assertEquals('People Subscription updated', $result['message']); } From 0736257c7d740681f16303ddeeb72489495e8ac0 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 08:38:46 -0400 Subject: [PATCH 39/67] fix: test --- .github/workflows/static-analysis.yml | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 53f7b1177..7e80caf17 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -58,7 +58,7 @@ jobs: TEST_SHOPIFY_SHOP_URL: ${{ secrets.TEST_SHOPIFY_SHOP_URL }} TEST_APPLE_LOGIN_TOKEN: ${{ secrets.TEST_APPLE_LOGIN_TOKEN }} TEST_APOLLO_KEY: ${{ secrets.TEST_APOLLO_KEY }} - STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }} + TEST_STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }} strategy: fail-fast: false diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 968c1df20..9f2e82ff9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -66,7 +66,7 @@ jobs: TEST_SHOPIFY_SHOP_URL: ${{ secrets.TEST_SHOPIFY_SHOP_URL }} TEST_APPLE_LOGIN_TOKEN: ${{ secrets.TEST_APPLE_LOGIN_TOKEN }} TEST_APOLLO_KEY: ${{ secrets.TEST_APOLLO_KEY }} - STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }} + TEST_STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }} strategy: fail-fast: false matrix: From d26f10337d8f481a64b3d066abfccc6183fa2761 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 08:38:59 -0400 Subject: [PATCH 40/67] fix: test --- tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php index 63baacc06..c56fb7fce 100644 --- a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -32,7 +32,7 @@ public function testUpdateSubscription() ->has(Contact::factory()->count(1), 'contacts') ->create(); - $app->set(ConfigurationEnum::STRIPE_SECRET_KEY->value, getenv('STRIPE_SECRET_KEY')); + $app->set(ConfigurationEnum::STRIPE_SECRET_KEY->value, getenv('TEST_STRIPE_SECRET_KEY')); $stripe = new StripeClient($app->get(ConfigurationEnum::STRIPE_SECRET_KEY->value)); $customer = $stripe->customers->create([ 'email' => $people->getEmails()[0]->value, From 3df0fdc27355214bd0ddc0eb218af32bcb4b98a0 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 08:42:37 -0400 Subject: [PATCH 41/67] fix: test --- .../Integration/Stripe/UpdateSubscriptionTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php index c56fb7fce..3e11c5546 100644 --- a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -94,12 +94,6 @@ public function testUpdateSubscription() // Fake the queue Queue::fake(); $job = new UpdatePeopleStripeSubscription($webhookRequest); - - try { - $job->handle(); - } catch (Throwable $e) { - $this->fail($e->getMessage()); - } $result = $job->handle(); $this->assertArrayHasKey('message', $result); From 96a41c5ab769877f4cde40da621de4475131076f Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 08:44:23 -0400 Subject: [PATCH 42/67] fix: test --- .../Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php index 8b31a5164..8b337b13b 100644 --- a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php +++ b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php @@ -15,7 +15,7 @@ // Maybe add action at the of the class name class UpdatePeopleStripeSubscription extends ProcessWebhookJob { - public $data; + public array $data = []; public function execute(): array { From a37f1d68138c52b2118b2f64d5498ac72bbab19a Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 08:50:44 -0400 Subject: [PATCH 43/67] fix: test --- .../Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php index a55a09ab0..351bf2634 100644 --- a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php +++ b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php @@ -29,7 +29,7 @@ public function execute(): array status: '1', first_date: date('Y-m-d H:i:s', $member['created_at']), start_date: date('Y-m-d H:i:s', $member['created_at']), - metadata: json_encode($this->webhookRequest->payload) + metadata: $this->webhookRequest->payload ); $action = new CreateOrUpdatePeopleSubscription($dto); $peopleSub = $action->handle(); From f57f6ae25d2f0a96d9454359c2d2b7461cce11a0 Mon Sep 17 00:00:00 2001 From: Max Castro Date: Fri, 12 Jul 2024 09:14:26 -0400 Subject: [PATCH 44/67] Update .env.example --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index a4b43187f..4f6e2bddc 100644 --- a/.env.example +++ b/.env.example @@ -135,4 +135,4 @@ TEST_ZOHO_CLIENT_REFRESH_TOKEN= TEST_SHOPIFY_API_KEY= TEST_SHOPIFY_API_SECRET= TEST_SHOPIFY_SHOP_URL= -STRIPE_SECRET_KEY= \ No newline at end of file +TEST_STRIPE_SECRET_KEY= From 12f5ea5f951530bfdaff536caec32fc1d47d40c0 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Fri, 12 Jul 2024 11:33:03 -0400 Subject: [PATCH 45/67] fix: count by tags --- .../Guild/Queries/PeopleManagementQueries.php | 28 +++++++++++++++++++ graphql/schemas/Guild/people.graphql | 8 ++---- 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 app/GraphQL/Guild/Queries/PeopleManagementQueries.php diff --git a/app/GraphQL/Guild/Queries/PeopleManagementQueries.php b/app/GraphQL/Guild/Queries/PeopleManagementQueries.php new file mode 100644 index 000000000..b4963bb07 --- /dev/null +++ b/app/GraphQL/Guild/Queries/PeopleManagementQueries.php @@ -0,0 +1,28 @@ +where('tags.name', $request['tag']); + }); + + $builder->where('is_deleted', StateEnums::NO->getValue()); + $builder = $this->scopeFromCompany($builder); + $builder = $this->scopeFromApp($builder); + + return $builder->count(); + } +} diff --git a/graphql/schemas/Guild/people.graphql b/graphql/schemas/Guild/people.graphql index 6ba9ff219..b842f0305 100644 --- a/graphql/schemas/Guild/people.graphql +++ b/graphql/schemas/Guild/people.graphql @@ -133,11 +133,9 @@ extend type Query @guard { model: "Kanvas\\Guild\\Customers\\Models\\People" scopes: ["fromApp", "fromCompany", "notDeleted"] ) - peopleCountByTag(tag: String!): Int @cache(maxAge: 300) - @count( - model: "Kanvas\\Guild\\Customers\\Models\\People" - scopes: ["fromApp", "fromCompany", "notDeleted"] - where: [["tags", "name", "=", "$tag"]] + peopleCountByTag(tag: String!): Int + @field( + resolver: "App\\GraphQL\\Guild\\Queries\\PeopleManagementQueries@countByTag" ) } From 4babca39830e20cb269473a9010410bb41ed5e40 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Fri, 12 Jul 2024 15:23:18 -0400 Subject: [PATCH 46/67] refactor: fix table --- app/GraphQL/Guild/Queries/PeopleManagementQueries.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/GraphQL/Guild/Queries/PeopleManagementQueries.php b/app/GraphQL/Guild/Queries/PeopleManagementQueries.php index b4963bb07..2ff11d423 100644 --- a/app/GraphQL/Guild/Queries/PeopleManagementQueries.php +++ b/app/GraphQL/Guild/Queries/PeopleManagementQueries.php @@ -12,6 +12,7 @@ class PeopleManagementQueries { use KanvasScopesTrait; + protected string $table = 'peoples'; public function countByTag(mixed $root, array $request, GraphQLContext $context): int { From c944a3cbb7c3339c316e789b63362aed82ae9850 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 20:06:01 -0400 Subject: [PATCH 47/67] hotfix : social channel --- .../Social/Mutations/Channels/ChannelsManagementMutation.php | 2 +- src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php | 3 +++ src/Domains/Social/Channels/Models/Channel.php | 4 +++- .../Social/Channels/Repositories/ChannelRepository.php | 2 +- .../Social/Messages/Jobs/CreateMessageFromReceiverJob.php | 3 ++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php b/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php index cb7bda3d6..266ab3334 100644 --- a/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php +++ b/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php @@ -26,7 +26,7 @@ public function createChannel(mixed $rootValue, array $request): Channel name: $request['input']['name'], description: $request['input']['description'], entity_id: $request['input']['entity_id'], - entity_namespace: $systemModule->uuid, + entity_namespace: $systemModule->model_name, slug: $request['input']['slug'] ?? Str::slug($request['input']['name']) ); diff --git a/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php b/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php index 6e8b2d641..12460f3e2 100644 --- a/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php +++ b/src/Domains/Connectors/Zoho/Actions/SyncZohoLeadAction.php @@ -96,6 +96,9 @@ public function execute(): ?Lead ]; } + /** + * @todo assign owner and user and member # if exist + */ $lead = new DataTransferObjectLead( app: $this->app, branch: $this->company->defaultBranch, diff --git a/src/Domains/Social/Channels/Models/Channel.php b/src/Domains/Social/Channels/Models/Channel.php index cd2e1fbc2..0a662c50e 100644 --- a/src/Domains/Social/Channels/Models/Channel.php +++ b/src/Domains/Social/Channels/Models/Channel.php @@ -20,6 +20,8 @@ * @property string $slug * @property string $description * @property int $last_message_id + * @property int $apps_id + * @property int $companies_id * @property int $entity_id * @property int $entity_namespace */ @@ -42,7 +44,7 @@ public function users(): BelongsToMany public function systemModule(): BelongsTo { - return $this->belongsTo(SystemModules::class, 'entity_namespace', 'model_name'); + return $this->belongsTo(SystemModules::class, 'entity_namespace', 'model_name')->where('apps_id', $this->apps_id); } public function messages(): BelongsToMany diff --git a/src/Domains/Social/Channels/Repositories/ChannelRepository.php b/src/Domains/Social/Channels/Repositories/ChannelRepository.php index 9b1ee3dd7..049f14104 100644 --- a/src/Domains/Social/Channels/Repositories/ChannelRepository.php +++ b/src/Domains/Social/Channels/Repositories/ChannelRepository.php @@ -19,7 +19,7 @@ public static function getByIdBuilder(Users $user): Builder { $databaseSocial = config('database.connections.social.database', 'social'); $builder = Channel::join($databaseSocial . '.channel_users', 'channel_users.channel_id', '=', 'channels.id') - ->where('users_id', auth()->user()->id); + ->where('users_id', $user->getId()); return $builder; } diff --git a/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php b/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php index 31947cd81..67b5273c3 100644 --- a/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php +++ b/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php @@ -75,6 +75,7 @@ public function execute(): array 'message' => 'Message created successfully from receiver with id ' . $message->getId(), 'message_id' => $message->getId(), 'message_verb' => $messageType->verb, + 'distribution' => $payload['distribution'] ?? null ]; } -} +} \ No newline at end of file From c83dbcbb01e6facf441c03aafb9aa24bcac9204f Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 20:08:13 -0400 Subject: [PATCH 48/67] fix: format --- .../Social/Messages/Jobs/CreateMessageFromReceiverJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php b/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php index 67b5273c3..a8afb90b1 100644 --- a/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php +++ b/src/Domains/Social/Messages/Jobs/CreateMessageFromReceiverJob.php @@ -75,7 +75,7 @@ public function execute(): array 'message' => 'Message created successfully from receiver with id ' . $message->getId(), 'message_id' => $message->getId(), 'message_verb' => $messageType->verb, - 'distribution' => $payload['distribution'] ?? null + 'distribution' => $payload['distribution'] ?? null, ]; } -} \ No newline at end of file +} From c47cc85269c658f760a1743a5d65e2c54d69fe88 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 20:09:08 -0400 Subject: [PATCH 49/67] fix: format --- src/Domains/Inventory/Channels/DataTransferObject/Channels.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Domains/Inventory/Channels/DataTransferObject/Channels.php b/src/Domains/Inventory/Channels/DataTransferObject/Channels.php index 542626f7d..c8c3cb1d2 100644 --- a/src/Domains/Inventory/Channels/DataTransferObject/Channels.php +++ b/src/Domains/Inventory/Channels/DataTransferObject/Channels.php @@ -25,6 +25,7 @@ public function __construct( public UserInterface $user, public string $name, public ?string $description = null, + public ?string $slug = null, public bool $is_default = false, public bool $is_published = true, ) { From af2b1a44730f9344043f2c96cc741dbf0f167a34 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 20:14:37 -0400 Subject: [PATCH 50/67] fix: order --- src/Domains/Inventory/Channels/DataTransferObject/Channels.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Domains/Inventory/Channels/DataTransferObject/Channels.php b/src/Domains/Inventory/Channels/DataTransferObject/Channels.php index c8c3cb1d2..937aa6be0 100644 --- a/src/Domains/Inventory/Channels/DataTransferObject/Channels.php +++ b/src/Domains/Inventory/Channels/DataTransferObject/Channels.php @@ -25,9 +25,9 @@ public function __construct( public UserInterface $user, public string $name, public ?string $description = null, - public ?string $slug = null, public bool $is_default = false, public bool $is_published = true, + public ?string $slug = null ) { } From 1591cb278a6fb588bc8c52d901f29df1fb4d639c Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 20:29:08 -0400 Subject: [PATCH 51/67] refact: add to channel --- .../Mutations/Channels/ChannelsManagementMutation.php | 10 ++++++++-- tests/GraphQL/Social/ChannelsTest.php | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php b/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php index 266ab3334..8dafaadee 100644 --- a/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php +++ b/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php @@ -4,6 +4,8 @@ namespace App\GraphQL\Social\Mutations\Channels; +use Baka\Support\Str; +use Kanvas\AccessControlList\Enums\RolesEnums; use Kanvas\AccessControlList\Repositories\RolesRepository; use Kanvas\Apps\Models\Apps; use Kanvas\Social\Channels\Actions\CreateChannelAction; @@ -12,7 +14,6 @@ use Kanvas\Social\Channels\Repositories\ChannelRepository; use Kanvas\SystemModules\Repositories\SystemModulesRepository; use Kanvas\Users\Models\Users; -use Baka\Support\Str; class ChannelsManagementMutation { @@ -65,7 +66,12 @@ public function attachUserToChannel(mixed $rootValue, array $request): Channel { $channel = ChannelRepository::getById((int)$request['input']['channel_id'], auth()->user()); $user = Users::getByIdFromCompany($request['input']['user_id'], auth()->user()->getCurrentCompany()); - $roles = RolesRepository::getByIdFromCompany($request['input']['roles_id'], auth()->user()->getCurrentCompany()); + + try { + $roles = RolesRepository::getByMixedParamFromCompany($request['input']['roles_id'], auth()->user()->getCurrentCompany()); + } catch (\Exception $e) { + $roles = RolesRepository::getByMixedParamFromCompany(RolesEnums::USER->value, auth()->user()->getCurrentCompany()); + } $channel->users()->attach($user->id, ['roles_id' => $roles->id]); return $channel; diff --git a/tests/GraphQL/Social/ChannelsTest.php b/tests/GraphQL/Social/ChannelsTest.php index f0e6362ff..be6c30e36 100644 --- a/tests/GraphQL/Social/ChannelsTest.php +++ b/tests/GraphQL/Social/ChannelsTest.php @@ -40,7 +40,7 @@ public function testCreateChannel() 'name' => $data['name'], 'description' => $data['description'], 'entity_id' => $data['entity_id'], - 'entity_namespace' => $data['entity_namespace_uuid'], + 'entity_namespace' => $systemModule->model_name ], ], ]); @@ -184,6 +184,7 @@ public function testAttachUserToSocialChannel() ], ] ); + $response->assertJsonStructure([ 'data' => [ 'attachUserToSocialChannel' => [ From cf55fa59e32df442bf9fd5eca8423a6f265fef75 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 20:29:47 -0400 Subject: [PATCH 52/67] refact: add to channel --- .../Social/Mutations/Channels/ChannelsManagementMutation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php b/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php index 8dafaadee..b2c9d062a 100644 --- a/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php +++ b/app/GraphQL/Social/Mutations/Channels/ChannelsManagementMutation.php @@ -5,6 +5,7 @@ namespace App\GraphQL\Social\Mutations\Channels; use Baka\Support\Str; +use Exception; use Kanvas\AccessControlList\Enums\RolesEnums; use Kanvas\AccessControlList\Repositories\RolesRepository; use Kanvas\Apps\Models\Apps; @@ -69,7 +70,7 @@ public function attachUserToChannel(mixed $rootValue, array $request): Channel try { $roles = RolesRepository::getByMixedParamFromCompany($request['input']['roles_id'], auth()->user()->getCurrentCompany()); - } catch (\Exception $e) { + } catch (Exception $e) { $roles = RolesRepository::getByMixedParamFromCompany(RolesEnums::USER->value, auth()->user()->getCurrentCompany()); } $channel->users()->attach($user->id, ['roles_id' => $roles->id]); From 19fec2e78f4f05bfeefc4eb231a53aa292b81515 Mon Sep 17 00:00:00 2001 From: kaioken Date: Fri, 12 Jul 2024 21:34:41 -0400 Subject: [PATCH 53/67] Refact: rename --- .../{ => Workflows}/CreateEntityWorkflowCommand.php | 2 +- .../Commands/Workflows/KanvasCreateReceiverCommand.php | 6 +++++- ...bscription.php => UpdatePeopleGhostSubscriptionJob.php} | 6 +++--- ...scription.php => UpdatePeopleStripeSubscriptionJob.php} | 6 +++--- ...tion.php => CreateOrUpdatePeopleSubscriptionAction.php} | 2 +- .../Integration/Ghosts/CreatePeopleSubscriptionTest.php | 6 +++--- .../Integration/Stripe/UpdateSubscriptionTest.php | 7 +++---- 7 files changed, 19 insertions(+), 16 deletions(-) rename app/Console/Commands/{ => Workflows}/CreateEntityWorkflowCommand.php (99%) rename src/Domains/Connectors/Ghost/Jobs/{UpdatePeopleGhostSubscription.php => UpdatePeopleGhostSubscriptionJob.php} (89%) rename src/Domains/Connectors/Stripe/Jobs/{UpdatePeopleStripeSubscription.php => UpdatePeopleStripeSubscriptionJob.php} (94%) rename src/Domains/Guild/Customers/Actions/{CreateOrUpdatePeopleSubscription.php => CreateOrUpdatePeopleSubscriptionAction.php} (96%) diff --git a/app/Console/Commands/CreateEntityWorkflowCommand.php b/app/Console/Commands/Workflows/CreateEntityWorkflowCommand.php similarity index 99% rename from app/Console/Commands/CreateEntityWorkflowCommand.php rename to app/Console/Commands/Workflows/CreateEntityWorkflowCommand.php index d7caa7740..bebd584c2 100644 --- a/app/Console/Commands/CreateEntityWorkflowCommand.php +++ b/app/Console/Commands/Workflows/CreateEntityWorkflowCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Console\Commands; +namespace App\Console\Commands\Workflows; use Illuminate\Console\Command; use Kanvas\Apps\Models\Apps; diff --git a/app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php b/app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php index 551c24c11..0a02df291 100644 --- a/app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php +++ b/app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php @@ -20,7 +20,7 @@ class KanvasCreateReceiverCommand extends Command * * @var string */ - protected $signature = 'kanvas:create-receiver'; + protected $signature = 'kanvas:create-receiver-workflow'; public function handle(): void { @@ -29,15 +29,19 @@ public function handle(): void label: 'Select the app for the receiver: ', options: Apps::pluck('name', 'id'), ); + $action = select( label: 'Select the action for the receiver: ', options: WorkflowAction::pluck('name', 'id'), ); + $userId = $this->ask('Enter the user ID for the receiver: '); $companyId = $this->ask('Enter the company ID for the receiver: '); $name = $this->ask('Enter the name for the receiver: '); $description = $this->ask('Enter the description for the receiver: '); + $company = Companies::getById($companyId); + $user = UsersRepository::getUserOfCompanyById($company, (int)$userId); $receiver = ReceiverWebhook::create([ diff --git a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscriptionJob.php similarity index 89% rename from src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php rename to src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscriptionJob.php index 351bf2634..984913e2b 100644 --- a/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscription.php +++ b/src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscriptionJob.php @@ -5,13 +5,13 @@ namespace Kanvas\Connectors\Ghost\Jobs; use Exception; -use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscription; +use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscriptionAction; use Kanvas\Guild\Customers\DataTransferObject\PeopleSubscription as PeopleSubscriptionDTO; use Kanvas\Guild\Customers\Repositories\PeoplesRepository; use Kanvas\Workflow\Jobs\ProcessWebhookJob; // Maybe add action at the of the class name -class UpdatePeopleGhostSubscription extends ProcessWebhookJob +class UpdatePeopleGhostSubscriptionJob extends ProcessWebhookJob { public function execute(): array { @@ -31,7 +31,7 @@ public function execute(): array start_date: date('Y-m-d H:i:s', $member['created_at']), metadata: $this->webhookRequest->payload ); - $action = new CreateOrUpdatePeopleSubscription($dto); + $action = new CreateOrUpdatePeopleSubscriptionAction($dto); $peopleSub = $action->handle(); return [ diff --git a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscriptionJob.php similarity index 94% rename from src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php rename to src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscriptionJob.php index 8b337b13b..410ec53cd 100644 --- a/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscription.php +++ b/src/Domains/Connectors/Stripe/Jobs/UpdatePeopleStripeSubscriptionJob.php @@ -6,14 +6,14 @@ use Illuminate\Support\Facades\Log; use Kanvas\Connectors\Stripe\Enums\ConfigurationEnum; -use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscription; +use Kanvas\Guild\Customers\Actions\CreateOrUpdatePeopleSubscriptionAction; use Kanvas\Guild\Customers\DataTransferObject\PeopleSubscription as PeopleSubscriptionDTO; use Kanvas\Guild\Customers\Repositories\PeoplesRepository; use Kanvas\Workflow\Jobs\ProcessWebhookJob; use Stripe\StripeClient; // Maybe add action at the of the class name -class UpdatePeopleStripeSubscription extends ProcessWebhookJob +class UpdatePeopleStripeSubscriptionJob extends ProcessWebhookJob { public array $data = []; @@ -63,7 +63,7 @@ public function execute(): array next_renewal: date('Y-m-d H:i:s', $subscriptions['current_period_end']), metadata: $this->data ?? [], ); - $action = new CreateOrUpdatePeopleSubscription($dto); + $action = new CreateOrUpdatePeopleSubscriptionAction($dto); $peopleSub = $action->handle(); return [ diff --git a/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php b/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscriptionAction.php similarity index 96% rename from src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php rename to src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscriptionAction.php index f95c0a380..f937b0080 100644 --- a/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscription.php +++ b/src/Domains/Guild/Customers/Actions/CreateOrUpdatePeopleSubscriptionAction.php @@ -7,7 +7,7 @@ use Kanvas\Guild\Customers\DataTransferObject\PeopleSubscription as PeopleSubscriptionDTO; use Kanvas\Guild\Customers\Models\PeopleSubscription; -class CreateOrUpdatePeopleSubscription +class CreateOrUpdatePeopleSubscriptionAction { public function __construct( private PeopleSubscriptionDTO $peopleSubscriptionDTO diff --git a/tests/Connectors/Integration/Ghosts/CreatePeopleSubscriptionTest.php b/tests/Connectors/Integration/Ghosts/CreatePeopleSubscriptionTest.php index 19b927681..9c603b91d 100644 --- a/tests/Connectors/Integration/Ghosts/CreatePeopleSubscriptionTest.php +++ b/tests/Connectors/Integration/Ghosts/CreatePeopleSubscriptionTest.php @@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Queue; use Illuminate\Support\Facades\Request; use Kanvas\Apps\Models\Apps; -use Kanvas\Connectors\Ghost\Jobs\UpdatePeopleGhostSubscription; +use Kanvas\Connectors\Ghost\Jobs\UpdatePeopleGhostSubscriptionJob; use Kanvas\Guild\Customers\Models\Contact; use Kanvas\Guild\Customers\Models\People; use Kanvas\Workflow\Actions\ProcessWebhookAttemptAction; @@ -37,7 +37,7 @@ public function testUpdateSubscription() $workflowAction = WorkflowAction::firstOrCreate([ 'name' => 'Update People Subscription', - 'model_name' => UpdatePeopleGhostSubscription::class, + 'model_name' => UpdatePeopleGhostSubscriptionJob::class, ]); $receiverWebhook = ReceiverWebhook::factory() @@ -55,7 +55,7 @@ public function testUpdateSubscription() // Fake the queue Queue::fake(); - $job = new UpdatePeopleGhostSubscription($webhookRequest); + $job = new UpdatePeopleGhostSubscriptionJob($webhookRequest); $result = $job->handle(); $this->assertArrayHasKey('success', $result); $this->assertArrayHasKey('data', $result); diff --git a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php index 3e11c5546..db3f8cd8d 100644 --- a/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php +++ b/tests/Connectors/Integration/Stripe/UpdateSubscriptionTest.php @@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Request; use Kanvas\Apps\Models\Apps; use Kanvas\Connectors\Stripe\Enums\ConfigurationEnum; -use Kanvas\Connectors\Stripe\Jobs\UpdatePeopleStripeSubscription; +use Kanvas\Connectors\Stripe\Jobs\UpdatePeopleStripeSubscriptionJob; use Kanvas\Guild\Customers\Models\Contact; use Kanvas\Guild\Customers\Models\People; use Kanvas\Workflow\Actions\ProcessWebhookAttemptAction; @@ -16,7 +16,6 @@ use Kanvas\Workflow\Models\WorkflowAction; use Stripe\StripeClient; use Tests\TestCase; -use Throwable; final class UpdateSubscriptionTest extends TestCase { @@ -75,7 +74,7 @@ public function testUpdateSubscription() $workflowAction = WorkflowAction::firstOrCreate([ 'name' => 'Update People Subscription', - 'model_name' => UpdatePeopleStripeSubscription::class, + 'model_name' => UpdatePeopleStripeSubscriptionJob::class, ]); $receiverWebhook = ReceiverWebhook::factory() @@ -93,7 +92,7 @@ public function testUpdateSubscription() // Fake the queue Queue::fake(); - $job = new UpdatePeopleStripeSubscription($webhookRequest); + $job = new UpdatePeopleStripeSubscriptionJob($webhookRequest); $result = $job->handle(); $this->assertArrayHasKey('message', $result); From 58bc007c165a6dfe010f29ea263d53eef40da815 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Fri, 12 Jul 2024 23:14:45 -0400 Subject: [PATCH 54/67] refactor: add count people by subscription type --- .../Guild/Queries/PeopleManagementQueries.php | 13 +++++ graphql/schemas/Guild/people.graphql | 16 ++++++ src/Domains/Guild/Customers/Models/People.php | 9 ++++ tests/GraphQL/Guild/PeopleTest.php | 52 +++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/app/GraphQL/Guild/Queries/PeopleManagementQueries.php b/app/GraphQL/Guild/Queries/PeopleManagementQueries.php index 2ff11d423..f141039f9 100644 --- a/app/GraphQL/Guild/Queries/PeopleManagementQueries.php +++ b/app/GraphQL/Guild/Queries/PeopleManagementQueries.php @@ -26,4 +26,17 @@ public function countByTag(mixed $root, array $request, GraphQLContext $context) return $builder->count(); } + + public function getBySubscriptionType(mixed $root, array $request, GraphQLContext $context): int + { + $builder = People::whereHas('subscriptions', function ($query) use ($request) { + $query->where('peoples_subscriptions.subscription_type', $request['type']); + }); + + $builder->where('is_deleted', StateEnums::NO->getValue()); + $builder = $this->scopeFromCompany($builder); + $builder = $this->scopeFromApp($builder); + + return $builder->count(); + } } diff --git a/graphql/schemas/Guild/people.graphql b/graphql/schemas/Guild/people.graphql index b842f0305..162286304 100644 --- a/graphql/schemas/Guild/people.graphql +++ b/graphql/schemas/Guild/people.graphql @@ -7,10 +7,12 @@ type People { firstname: String! middlename: String lastname: String + subscriptions: [PeopleSubscription!]! @hasMany dob: Date organizations: [Organization!] @belongsToMany contacts: [Contact!]! @hasMany address: [Address!]! @hasMany + employment_history: [PeopleEmploymentHistory!] @hasMany(relation: "employmentHistory") files: [Filesystem!]! @@ -29,6 +31,16 @@ type People { builder: "App\\GraphQL\\Social\\Queries\\Tags\\TagsQueries@getTagsBuilder" ) } +type PeopleSubscription { + id: ID! + subscription_type: String! + status: String! + start_date: Date! + end_date: Date + first_date: Date + next_renewal: Date +} + type PeopleEmploymentHistory { id: ID! organization: Organization! @belongsTo @@ -137,6 +149,10 @@ extend type Query @guard { @field( resolver: "App\\GraphQL\\Guild\\Queries\\PeopleManagementQueries@countByTag" ) + peopleCountBySubscriptionType(type: String!): Int + @field( + resolver: "App\\GraphQL\\Guild\\Queries\\PeopleManagementQueries@getBySubscriptionType" + ) } extend type Mutation @guard { diff --git a/src/Domains/Guild/Customers/Models/People.php b/src/Domains/Guild/Customers/Models/People.php index 5b814669e..180f7f4bc 100644 --- a/src/Domains/Guild/Customers/Models/People.php +++ b/src/Domains/Guild/Customers/Models/People.php @@ -115,6 +115,15 @@ public function phones(): HasMany ); } + public function subscriptions(): HasMany + { + return $this->hasMany( + PeopleSubscription::class, + 'peoples_id', + 'id' + ); + } + /** * @psalm-suppress MixedReturnStatement */ diff --git a/tests/GraphQL/Guild/PeopleTest.php b/tests/GraphQL/Guild/PeopleTest.php index b54434259..ba48d8b7c 100644 --- a/tests/GraphQL/Guild/PeopleTest.php +++ b/tests/GraphQL/Guild/PeopleTest.php @@ -457,4 +457,56 @@ public function testCountPeople() ]); $this->assertTrue(is_int($response['data']['peopleCount'])); } + + public function testPeopleCountBySubscriptionType() + { + $user = auth()->user(); + $branch = $user->getCurrentBranch(); + $firstname = fake()->firstName(); + $lastname = fake()->lastName(); + + $input = [ + 'firstname' => $firstname, + 'lastname' => $lastname, + 'contacts' => [ + [ + 'value' => fake()->email(), + 'contacts_types_id' => 1, + 'weight' => 0, + ], + [ + 'value' => fake()->phoneNumber(), + 'contacts_types_id' => 2, + 'weight' => 0, + ], + ], + 'address' => [ + [ + 'address' => fake()->address(), + 'city' => fake()->city(), + 'county' => fake()->city(), + 'state' => fake()->state(), + 'country' => fake()->country(), + 'zip' => fake()->postcode(), + ], + ], + 'custom_fields' => [], + ]; + + $this->createPeopleAndResponse($input); + + $response = $this->graphQL(' + query { + peopleCountBySubscriptionType( + type: "Free" + ) + } + '); + $response->assertJsonStructure([ + 'data' => [ + 'peopleCountBySubscriptionType', + ], + ]); + $this->assertTrue(is_int($response['data']['peopleCount'])); + } } From 1c74f84e25b72c44298ea3d2a7b269caedb3a4f8 Mon Sep 17 00:00:00 2001 From: FredPeal Date: Fri, 12 Jul 2024 23:24:52 -0400 Subject: [PATCH 55/67] refactor: people type --- tests/GraphQL/Guild/PeopleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/GraphQL/Guild/PeopleTest.php b/tests/GraphQL/Guild/PeopleTest.php index ba48d8b7c..2650c70e2 100644 --- a/tests/GraphQL/Guild/PeopleTest.php +++ b/tests/GraphQL/Guild/PeopleTest.php @@ -507,6 +507,6 @@ public function testPeopleCountBySubscriptionType() 'peopleCountBySubscriptionType', ], ]); - $this->assertTrue(is_int($response['data']['peopleCount'])); + $this->assertTrue(is_int($response['data']['peopleCountBySubscriptionType'])); } } From c1b18f532def8e092461dfa400fbe2893f840e69 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sat, 13 Jul 2024 01:03:04 -0400 Subject: [PATCH 56/67] refact: user interaction --- ...045959_add_app_id_to_user_interactions.php | 28 +++++++++++++++++++ .../schemas/Social/usersInteractions.graphql | 5 ++-- .../Actions/CreateUserInteractionAction.php | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 database/migrations/Social/2024_07_13_045959_add_app_id_to_user_interactions.php diff --git a/database/migrations/Social/2024_07_13_045959_add_app_id_to_user_interactions.php b/database/migrations/Social/2024_07_13_045959_add_app_id_to_user_interactions.php new file mode 100644 index 000000000..8804aab12 --- /dev/null +++ b/database/migrations/Social/2024_07_13_045959_add_app_id_to_user_interactions.php @@ -0,0 +1,28 @@ +bigInteger('apps_id')->after('users_id')->nullable()->index(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users_interactions', function (Blueprint $table) { + $table->dropColumn('apps_id'); + }); + } +}; diff --git a/graphql/schemas/Social/usersInteractions.graphql b/graphql/schemas/Social/usersInteractions.graphql index a2aea4dc2..8db0bc57e 100644 --- a/graphql/schemas/Social/usersInteractions.graphql +++ b/graphql/schemas/Social/usersInteractions.graphql @@ -21,7 +21,7 @@ type Interaction { type UserEntityInteraction { entity_id: ID! entity_namespace: String! - interactions: JSON + interactions: Mixed } input UserInteractionInput { @@ -54,10 +54,11 @@ extend type Query @guard { @paginate( model: "Kanvas\\Social\\Interactions\\Models\\UsersInteractions" defaultCount: 25 + scopes: ["fromApp", "fromUser"] ) } -extend type Query { +extend type Query @guard { getUserInteraction( entity_id: ID! entity_namespace: String! diff --git a/src/Domains/Social/Interactions/Actions/CreateUserInteractionAction.php b/src/Domains/Social/Interactions/Actions/CreateUserInteractionAction.php index d09c61353..b295a8c99 100644 --- a/src/Domains/Social/Interactions/Actions/CreateUserInteractionAction.php +++ b/src/Domains/Social/Interactions/Actions/CreateUserInteractionAction.php @@ -19,6 +19,7 @@ public function execute(): UsersInteractions { $userInteraction = UsersInteractions::firstOrCreate([ 'users_id' => $this->userInteractionData->user->getId(), + 'apps_id' => $this->userInteractionData->interaction->apps_id, 'entity_id' => $this->userInteractionData->entity_id, 'entity_namespace' => $this->userInteractionData->entity_namespace, 'interactions_id' => $this->userInteractionData->interaction->getId(), From 9a16e4b790350bca9a24201f043141d21186e286 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sat, 13 Jul 2024 01:06:50 -0400 Subject: [PATCH 57/67] fix: format --- .../2024_07_13_045959_add_app_id_to_user_interactions.php | 3 +-- graphql/schemas/Social/interactions.graphql | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/database/migrations/Social/2024_07_13_045959_add_app_id_to_user_interactions.php b/database/migrations/Social/2024_07_13_045959_add_app_id_to_user_interactions.php index 8804aab12..acad3492b 100644 --- a/database/migrations/Social/2024_07_13_045959_add_app_id_to_user_interactions.php +++ b/database/migrations/Social/2024_07_13_045959_add_app_id_to_user_interactions.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class () extends Migration { /** * Run the migrations. */ diff --git a/graphql/schemas/Social/interactions.graphql b/graphql/schemas/Social/interactions.graphql index 461455c9e..a0fd0403d 100644 --- a/graphql/schemas/Social/interactions.graphql +++ b/graphql/schemas/Social/interactions.graphql @@ -48,6 +48,7 @@ extend type Mutation @guardByAuthOrCompany { @field( resolver: "App\\GraphQL\\Social\\Mutations\\Interactions\\EntityInteractionMutation@disLikeEntity" ) + @deprecated(reason: "Use likeEntity instead") getInteractionByEntity(input: LikeEntityInput!): Interactions! @field( resolver: "App\\GraphQL\\Social\\Mutations\\Interactions\\EntityInteractionMutation@getInteractionByEntity" From 3cca41c82dc9de096f1d902b244f9403ebd2a258 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sat, 13 Jul 2024 01:22:50 -0400 Subject: [PATCH 58/67] fix: product slug --- ...07_13_052119_update_product_slug_index.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 database/migrations/Inventory/2024_07_13_052119_update_product_slug_index.php diff --git a/database/migrations/Inventory/2024_07_13_052119_update_product_slug_index.php b/database/migrations/Inventory/2024_07_13_052119_update_product_slug_index.php new file mode 100644 index 000000000..d5fccb9f9 --- /dev/null +++ b/database/migrations/Inventory/2024_07_13_052119_update_product_slug_index.php @@ -0,0 +1,31 @@ +dropUnique(['companies_id', 'slug']); + + $table->unique(['companies_id', 'slug', 'is_deleted']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('products', function (Blueprint $table) { + $table->dropUnique(['companies_id', 'slug', 'is_deleted']); + + $table->unique(['companies_id', 'slug']); + }); + } +}; From 2bfe67c028685a056e778f906356cf4f5b7872ac Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 20:58:20 -0400 Subject: [PATCH 59/67] fix: smtp configuration per app --- .../Apps/Support/SmtpRuntimeConfiguration.php | 19 +++++---- src/Kanvas/Notifications/KanvasMailable.php | 42 +++++++++++++++++++ src/Kanvas/Notifications/Notification.php | 14 ++++--- 3 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 src/Kanvas/Notifications/KanvasMailable.php diff --git a/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php b/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php index 784050541..a828d3d84 100644 --- a/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php +++ b/src/Kanvas/Apps/Support/SmtpRuntimeConfiguration.php @@ -7,27 +7,28 @@ use Baka\Contracts\AppInterface; use Baka\Contracts\CompanyInterface; use Baka\Contracts\HashTableInterface; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Config; class SmtpRuntimeConfiguration { protected string $appSmtp = 'appSmtp'; protected string $companySmtp = 'companySmtp'; - protected string $defaultSmtp; + protected array $defaultSmtp; public function __construct( protected AppInterface $app, protected ?CompanyInterface $company = null ) { - $this->defaultSmtp = config('mail.default'); + $this->defaultSmtp = config('mail.mailers.smtp'); } /** * Load SMTP settings from the given source. */ - protected function loadSmtpSettingsFromSource(string $provider, HashTableInterface $source): string + protected function loadSmtpSettingsFromSource(string $provider, HashTableInterface $source): array { - $config = [ + return [ 'transport' => 'smtp', 'host' => $source->get('smtp_host'), 'port' => $source->get('smtp_port'), @@ -37,16 +38,16 @@ protected function loadSmtpSettingsFromSource(string $provider, HashTableInterfa 'timeout' => null, ]; - Config::set('mail.mailers.' . $provider, $config); + //Config::set('mail.mailers.' . $provider, $config); - return $provider; + //return $provider; } /** * Load SMTP settings from the app. */ - protected function loadAppSettings(): string + protected function loadAppSettings(): array { return $this->loadSmtpSettingsFromSource($this->appSmtp, $this->app); } @@ -54,7 +55,7 @@ protected function loadAppSettings(): string /** * Load SMTP settings from the company config. */ - protected function loadCompanySettings(): string + protected function loadCompanySettings(): array { return $this->loadSmtpSettingsFromSource($this->companySmtp, $this->company); } @@ -63,7 +64,7 @@ protected function loadCompanySettings(): string * Determine the source of SMTP settings and load them. * Returns the SMTP settings source used. */ - public function loadSmtpSettings(): string + public function loadSmtpSettings(): array { if ($this->company !== null && $this->company->get('smtp_host')) { return $this->loadCompanySettings(); diff --git a/src/Kanvas/Notifications/KanvasMailable.php b/src/Kanvas/Notifications/KanvasMailable.php new file mode 100644 index 000000000..7c2e8d799 --- /dev/null +++ b/src/Kanvas/Notifications/KanvasMailable.php @@ -0,0 +1,42 @@ + $this->emailContent, + ], + ); + } + + public function build(): self + { + //thanks to https://github.com/laravel/framework/issues/42602#issuecomment-1143637921 + $customConfig = Mail::createSymfonyTransport($this->mailerConfig); + Mail::setSymfonyTransport($customConfig); + + return $this; + } +} diff --git a/src/Kanvas/Notifications/Notification.php b/src/Kanvas/Notifications/Notification.php index d436a70ad..a79803e43 100644 --- a/src/Kanvas/Notifications/Notification.php +++ b/src/Kanvas/Notifications/Notification.php @@ -11,8 +11,11 @@ use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Model; +use Illuminate\Mail\Mailable; +use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification as LaravelNotification; +use Illuminate\Support\Facades\Config; use Kanvas\Apps\Models\Apps; use Kanvas\Apps\Support\SmtpRuntimeConfiguration; use Kanvas\Exceptions\ValidationException; @@ -142,20 +145,19 @@ public function via(object $notifiable): array * * @param mixed $notifiable */ - public function toMail($notifiable): ?MailMessage + public function toMail($notifiable): Mailable { $smtpConfiguration = new SmtpRuntimeConfiguration($this->app, $this->company); - $mailer = $smtpConfiguration->loadSmtpSettings(); + $mailConfig = $smtpConfiguration->loadSmtpSettings(); $fromMail = $smtpConfiguration->getFromEmail(); $fromEmail = $fromMail['address']; $fromName = $fromMail['name']; - $mailMessage = (new MailMessage()) - ->mailer($mailer) + $toEmail = $notifiable instanceof AnonymousNotifiable ? $notifiable->routes['mail'] : $notifiable->email; + $mailMessage = (new KanvasMailable($mailConfig, $this->getEmailContent())) ->from($fromEmail, $fromName) - //->subject($this->app->get('name') . ' - ' . $this->getTitle() - ->view('emails.layout', ['html' => $this->getEmailContent()]); + ->to($toEmail); $this->subject = $this->subject ?? $this->getNotificationTitle(); From 05f704816ee70836389929f182c74c68368a4a23 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 21:22:41 -0400 Subject: [PATCH 60/67] fix: smtp configuration per app --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9f2e82ff9..24a05aef8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -160,7 +160,7 @@ jobs: - name: Run Tests if: success() - run: php artisan test + run: php artisan test --debug - name: Upload artifacts uses: actions/upload-artifact@master From 6cc20de66b7169e105f8cc8efda349a5de0c2fa8 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 21:29:52 -0400 Subject: [PATCH 61/67] fix: smtp configuration per app --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 24a05aef8..600fc674a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -160,7 +160,7 @@ jobs: - name: Run Tests if: success() - run: php artisan test --debug + run: php artisan test --verbose - name: Upload artifacts uses: actions/upload-artifact@master From efee3c03daf88c4bb4a35bcbfaedb01970cce97e Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 21:37:40 -0400 Subject: [PATCH 62/67] fix: smtp configuration per app --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 600fc674a..990b16379 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -56,7 +56,7 @@ jobs: MEILISEARCH_HOST: http://localhost:7700 MEILISEARCH_KEY: masterKey SCOUT_QUEUE: false - #APP_DEBUG: true + APP_DEBUG: true #third party integration TEST_ZOHO_CLIENT_ID: ${{ secrets.TEST_ZOHO_CLIENT_ID }} TEST_ZOHO_CLIENT_SECRET: ${{ secrets.TEST_ZOHO_CLIENT_SECRET }} @@ -160,7 +160,7 @@ jobs: - name: Run Tests if: success() - run: php artisan test --verbose + run: php artisan test - name: Upload artifacts uses: actions/upload-artifact@master From 96018b2ebecb65ec47d101005e3e0d84c17d71e1 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 21:45:32 -0400 Subject: [PATCH 63/67] fix: smtp configuration per app --- .github/workflows/tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 990b16379..c0e86bdd0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -57,6 +57,8 @@ jobs: MEILISEARCH_KEY: masterKey SCOUT_QUEUE: false APP_DEBUG: true + MAIL_MAILER: null + #third party integration TEST_ZOHO_CLIENT_ID: ${{ secrets.TEST_ZOHO_CLIENT_ID }} TEST_ZOHO_CLIENT_SECRET: ${{ secrets.TEST_ZOHO_CLIENT_SECRET }} From 67241bfcd5d3a480ea90a5c3e4652a386f87c4fd Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 21:53:02 -0400 Subject: [PATCH 64/67] fix: smtp configuration per app --- .github/workflows/tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c0e86bdd0..3bcc7c546 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -57,8 +57,7 @@ jobs: MEILISEARCH_KEY: masterKey SCOUT_QUEUE: false APP_DEBUG: true - MAIL_MAILER: null - + #third party integration TEST_ZOHO_CLIENT_ID: ${{ secrets.TEST_ZOHO_CLIENT_ID }} TEST_ZOHO_CLIENT_SECRET: ${{ secrets.TEST_ZOHO_CLIENT_SECRET }} From d13c02d55123ad63c00fb7210929d1dfb7f6c69c Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 22:03:33 -0400 Subject: [PATCH 65/67] fix: smtp configuration per app --- src/Kanvas/Notifications/KanvasMailable.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Kanvas/Notifications/KanvasMailable.php b/src/Kanvas/Notifications/KanvasMailable.php index 7c2e8d799..6cfdef076 100644 --- a/src/Kanvas/Notifications/KanvasMailable.php +++ b/src/Kanvas/Notifications/KanvasMailable.php @@ -33,6 +33,11 @@ public function content(): Content public function build(): self { + if (app()->environment('testing')) { + // Skip setting the custom mailer configuration in testing environment + return $this; + } + //thanks to https://github.com/laravel/framework/issues/42602#issuecomment-1143637921 $customConfig = Mail::createSymfonyTransport($this->mailerConfig); Mail::setSymfonyTransport($customConfig); From 1465bac859a3f8ce6672357c43e7b75d2eab4337 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 22:09:59 -0400 Subject: [PATCH 66/67] fix: smtp configuration per app --- .github/workflows/tests.yml | 2 +- src/Kanvas/Notifications/KanvasMailable.php | 2 +- tests/TestCase.php | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3bcc7c546..d101e0e8b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -56,7 +56,7 @@ jobs: MEILISEARCH_HOST: http://localhost:7700 MEILISEARCH_KEY: masterKey SCOUT_QUEUE: false - APP_DEBUG: true + #APP_DEBUG: true #third party integration TEST_ZOHO_CLIENT_ID: ${{ secrets.TEST_ZOHO_CLIENT_ID }} diff --git a/src/Kanvas/Notifications/KanvasMailable.php b/src/Kanvas/Notifications/KanvasMailable.php index 6cfdef076..79f3b1209 100644 --- a/src/Kanvas/Notifications/KanvasMailable.php +++ b/src/Kanvas/Notifications/KanvasMailable.php @@ -35,7 +35,7 @@ public function build(): self { if (app()->environment('testing')) { // Skip setting the custom mailer configuration in testing environment - return $this; + //return $this; } //thanks to https://github.com/laravel/framework/issues/42602#issuecomment-1143637921 diff --git a/tests/TestCase.php b/tests/TestCase.php index ebaaad3b2..05673bd0f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,16 +3,31 @@ namespace Tests; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use Illuminate\Support\Facades\Mail; use Kanvas\Auth\Actions\RegisterUsersAction; use Kanvas\Auth\DataTransferObject\RegisterInput as RegisterPostDataDto; use Kanvas\Users\Models\Users; use Nuwave\Lighthouse\Testing\MakesGraphQLRequests; +use Symfony\Component\Mailer\Transport\TransportInterface; class TestCase extends BaseTestCase { use CreatesApplication; use MakesGraphQLRequests; + protected function setUp(): void + { + parent::setUp(); + + // Mock the createSymfonyTransport method + Mail::shouldReceive('createSymfonyTransport') + ->andReturn(\Mockery::mock(TransportInterface::class)); + + // Mock the setSymfonyTransport method + Mail::shouldReceive('setSymfonyTransport') + ->andReturnNull(); + } + /** * createUser. * From 67a7a981de3bd00ba112569b0aff753eb793f526 Mon Sep 17 00:00:00 2001 From: kaioken Date: Sun, 14 Jul 2024 22:15:56 -0400 Subject: [PATCH 67/67] fix: smtp configuration per app --- src/Kanvas/Notifications/KanvasMailable.php | 2 +- tests/TestCase.php | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Kanvas/Notifications/KanvasMailable.php b/src/Kanvas/Notifications/KanvasMailable.php index 79f3b1209..6cfdef076 100644 --- a/src/Kanvas/Notifications/KanvasMailable.php +++ b/src/Kanvas/Notifications/KanvasMailable.php @@ -35,7 +35,7 @@ public function build(): self { if (app()->environment('testing')) { // Skip setting the custom mailer configuration in testing environment - //return $this; + return $this; } //thanks to https://github.com/laravel/framework/issues/42602#issuecomment-1143637921 diff --git a/tests/TestCase.php b/tests/TestCase.php index 05673bd0f..ebaaad3b2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,31 +3,16 @@ namespace Tests; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; -use Illuminate\Support\Facades\Mail; use Kanvas\Auth\Actions\RegisterUsersAction; use Kanvas\Auth\DataTransferObject\RegisterInput as RegisterPostDataDto; use Kanvas\Users\Models\Users; use Nuwave\Lighthouse\Testing\MakesGraphQLRequests; -use Symfony\Component\Mailer\Transport\TransportInterface; class TestCase extends BaseTestCase { use CreatesApplication; use MakesGraphQLRequests; - protected function setUp(): void - { - parent::setUp(); - - // Mock the createSymfonyTransport method - Mail::shouldReceive('createSymfonyTransport') - ->andReturn(\Mockery::mock(TransportInterface::class)); - - // Mock the setSymfonyTransport method - Mail::shouldReceive('setSymfonyTransport') - ->andReturnNull(); - } - /** * createUser. *