diff --git a/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php b/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php index 4af93dba89..8b4a9109e2 100644 --- a/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php +++ b/app/Http/Requests/CompanyGateway/StoreCompanyGatewayRequest.php @@ -47,27 +47,32 @@ class StoreCompanyGatewayRequest extends Request $gateway = Gateway::where('key', $input['gateway_key'])->first(); - $default_gateway_fields = json_decode($gateway->fields); + if($gateway); + { - /*Force gateway properties */ - if (isset($input['config']) && is_object(json_decode($input['config']))) { + $default_gateway_fields = json_decode($gateway->fields); - foreach (json_decode($input['config']) as $key => $value) { + /*Force gateway properties */ + if (isset($input['config']) && is_object(json_decode($input['config']))) { - $default_gateway_fields->{$key} = $value; + foreach (json_decode($input['config']) as $key => $value) { + + $default_gateway_fields->{$key} = $value; + + } + + $input['config'] = json_encode($default_gateway_fields); } - $input['config'] = json_encode($default_gateway_fields); - + if (isset($input['config'])) + $input['config'] = encrypt($input['config']); + + if (isset($input['fees_and_limits'])) + $input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']); + } - if (isset($input['config'])) - $input['config'] = encrypt($input['config']); - - if (isset($input['fees_and_limits'])) - $input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']); - $this->replace($input); } diff --git a/app/Listeners/Invoice/InvoicePaidActivity.php b/app/Listeners/Invoice/InvoicePaidActivity.php index e42fe41a00..65351ff34c 100644 --- a/app/Listeners/Invoice/InvoicePaidActivity.php +++ b/app/Listeners/Invoice/InvoicePaidActivity.php @@ -39,6 +39,7 @@ class InvoicePaidActivity implements ShouldQueue */ public function handle($event) { + MultiDB::setDb($event->company->db); $fields = new stdClass; @@ -53,6 +54,7 @@ class InvoicePaidActivity implements ShouldQueue if($event->invoice->subscription()->exists()) { + nlog("subscription exists"); $event->invoice->subscription->service()->planPaid($event->invoice); } diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index aeca8d1b35..2e0ed98573 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -695,10 +695,14 @@ nlog("handle plan change"); */ public function triggerWebhook($context) { + nlog("trigger webook"); + if (empty($this->subscription->webhook_configuration['post_purchase_url']) || is_null($this->subscription->webhook_configuration['post_purchase_url']) || strlen($this->subscription->webhook_configuration['post_purchase_url']) < 1) { return ["message" => "Success", "status_code" => 200]; } + nlog("past first if"); + $response = false; $body = array_merge($context, [ @@ -709,6 +713,8 @@ nlog("handle plan change"); $response = $this->sendLoad($this->subscription, $body); + nlog("after response"); + /* Append the response to the system logger body */ if(is_array($response)){ @@ -732,6 +738,7 @@ nlog("handle plan change"); $client->company, ); + nlog("ready to fire back"); if(is_array($body)) return $response; @@ -909,14 +916,24 @@ nlog("handle plan change"); public function planPaid($invoice) { + nlog("this is a plan that has been paid"); + + $recurring_invoice_hashed_id = $invoice->recurring_invoice()->exists() ? $invoice->recurring_invoice->hashed_id : null; + $context = [ 'context' => 'plan_paid', 'subscription' => $this->subscription->hashed_id, - 'recurring_invoice' => $invoice->recurring_invoice->hashed_id, + 'recurring_invoice' => $recurring_invoice_hashed_id, 'client' => $invoice->client->hashed_id, 'contact' => $invoice->client->primary_contact()->first()->hashed_id, ]; - $this->triggerWebhook($context); + nlog($context); + + $response = $this->triggerWebhook($context); + + nlog($response); + + return true; } }