From c7d7916b047a3456e79ab24ecac4b060f5f99ad1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 21 Mar 2021 16:35:09 +1100 Subject: [PATCH] Update defaults --- app/Console/Commands/CreateSingleAccount.php | 1 + .../Billing/WebhookConfiguration.php | 6 ++++ .../BillingSubscriptionService.php | 35 +++++++++++++++++++ database/factories/CompanyFactory.php | 1 + 4 files changed, 43 insertions(+) diff --git a/app/Console/Commands/CreateSingleAccount.php b/app/Console/Commands/CreateSingleAccount.php index 082f30842f..bcddc6b2b7 100644 --- a/app/Console/Commands/CreateSingleAccount.php +++ b/app/Console/Commands/CreateSingleAccount.php @@ -101,6 +101,7 @@ class CreateSingleAccount extends Command $company = Company::factory()->create([ 'account_id' => $account->id, 'slack_webhook_url' => config('ninja.notification.slack'), + 'default_password_timeout' => 30*60000, ]); $account->default_company_id = $company->id; diff --git a/app/DataMapper/Billing/WebhookConfiguration.php b/app/DataMapper/Billing/WebhookConfiguration.php index fe562650b9..591ee23697 100644 --- a/app/DataMapper/Billing/WebhookConfiguration.php +++ b/app/DataMapper/Billing/WebhookConfiguration.php @@ -35,12 +35,18 @@ class WebhookConfiguration */ public $post_purchase_body = ''; + /** + * @var string + */ + public $post_purchase_rest_method = 'POST'; + /** * @var array */ public static $casts = [ 'return_url' => 'string', 'post_purchase_url' => 'string', + 'post_purchase_rest_method' => 'string', 'post_purchase_headers' => 'array', 'post_purchase_body' => 'object', ]; diff --git a/app/Services/BillingSubscription/BillingSubscriptionService.php b/app/Services/BillingSubscription/BillingSubscriptionService.php index 0043e028e5..7b5013299f 100644 --- a/app/Services/BillingSubscription/BillingSubscriptionService.php +++ b/app/Services/BillingSubscription/BillingSubscriptionService.php @@ -13,17 +13,25 @@ namespace App\Services\BillingSubscription; use App\DataMapper\InvoiceItem; use App\Factory\InvoiceFactory; +use App\Jobs\Util\SystemLogger; use App\Models\BillingSubscription; use App\Models\ClientSubscription; use App\Models\PaymentHash; use App\Models\Product; +use App\Models\SystemLog; use App\Repositories\InvoiceRepository; +use App\Utils\Traits\MakesHash; +use GuzzleHttp\RequestOptions; class BillingSubscriptionService { + use MakesHash; + /** @var BillingSubscription */ private $billing_subscription; + private $client_subscription; + public function __construct(BillingSubscription $billing_subscription) { $this->billing_subscription = $billing_subscription; @@ -158,11 +166,38 @@ class BillingSubscriptionService // client_id $cs->save(); + + $this->client_subscription = $cs; + } public function triggerWebhook($payment_hash) { //hit the webhook to after a successful onboarding + //$client = xxxxxxx + //todo webhook + + $body = [ + 'billing_subscription' => $this->billing_subscription, + 'client_subscription' => $this->client_subscription, + // 'client' => $client->toArray(), + ]; + + + $client = new \GuzzleHttp\Client(['headers' => $this->billing_subscription->webhook_configuration->post_purchase_headers]); + + $response = $client->{$this->billing_subscription->webhook_configuration->post_purchase_rest_method}($this->billing_subscription->post_purchase_url,[ + RequestOptions::JSON => ['body' => $body] + ]); + + SystemLogger::dispatch( + $body, + SystemLog::CATEGORY_WEBHOOK, + SystemLog::EVENT_WEBHOOK_RESPONSE, + SystemLog::TYPE_WEBHOOK_RESPONSE, + //$client, + ); + } public function fireNotifications() diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php index 4dd793b5a4..2a4a9850c6 100644 --- a/database/factories/CompanyFactory.php +++ b/database/factories/CompanyFactory.php @@ -37,6 +37,7 @@ class CompanyFactory extends Factory 'db' => config('database.default'), 'settings' => CompanySettings::defaults(), 'is_large' => false, + 'default_password_timeout' => 30*60000, 'enabled_modules' => config('ninja.enabled_modules'), 'custom_fields' => (object) [ //'invoice1' => 'Custom Date|date',