-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1597 from bakaphp/KA-345
Ka 345
- Loading branch information
Showing
20 changed files
with
603 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/Console/Commands/Workflows/KanvasCreateReceiverCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
database/migrations/Guild/2024_06_25_032857_peoples_subscriptions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}; |
42 changes: 42 additions & 0 deletions
42
src/Domains/Connectors/Ghost/Jobs/UpdatePeopleGhostSubscriptionJob.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} |
Oops, something went wrong.