Skip to content

Commit

Permalink
Merge pull request #1597 from bakaphp/KA-345
Browse files Browse the repository at this point in the history
Ka 345
  • Loading branch information
kaioken authored Jul 13, 2024
2 parents 5e3129d + 19fec2e commit b4e0b77
Show file tree
Hide file tree
Showing 20 changed files with 603 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ TEST_ZOHO_CLIENT_REFRESH_TOKEN=

TEST_SHOPIFY_API_KEY=
TEST_SHOPIFY_API_SECRET=
TEST_SHOPIFY_SHOP_URL=
TEST_SHOPIFY_SHOP_URL=
TEST_STRIPE_SECRET_KEY=
2 changes: 2 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
TEST_STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }}

strategy:
fail-fast: false
matrix:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
TEST_STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }}
strategy:
fail-fast: false
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 62 additions & 0 deletions app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

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\ReceiverWebhook;
use Kanvas\Workflow\Models\WorkflowAction;

use function Laravel\Prompts\select;

class KanvasCreateReceiverCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kanvas:create-receiver-workflow';

public function handle(): void
{
$this->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);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/ReceiverController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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\Zoho\Actions\SyncZohoAgentAction;
use Kanvas\Connectors\Zoho\Actions\SyncZohoLeadAction;
Expand All @@ -30,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) {
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
97 changes: 78 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('peoples_subscriptions', function (Blueprint $table) {
$table->id();
$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()->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']);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('peoples_subscriptions');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Kanvas\Connectors\Ghost\Jobs;

use Exception;
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 UpdatePeopleGhostSubscriptionJob 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,
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
);
$action = new CreateOrUpdatePeopleSubscriptionAction($dto);
$peopleSub = $action->handle();

return [
'success' => true,
'data' => $peopleSub,
];
}
}
10 changes: 10 additions & 0 deletions src/Domains/Connectors/Stripe/Enums/ConfigurationEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Kanvas\Connectors\Stripe\Enums;

enum ConfigurationEnum: string
{
case STRIPE_SECRET_KEY = 'STRIPE_SECRET_KEY';
}
Loading

0 comments on commit b4e0b77

Please sign in to comment.