1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for subscription webhooks

This commit is contained in:
David Bomba 2021-07-15 11:06:14 +10:00
parent a6146ee468
commit 46bc8fa495
3 changed files with 39 additions and 15 deletions

View File

@ -47,6 +47,9 @@ class StoreCompanyGatewayRequest extends Request
$gateway = Gateway::where('key', $input['gateway_key'])->first(); $gateway = Gateway::where('key', $input['gateway_key'])->first();
if($gateway);
{
$default_gateway_fields = json_decode($gateway->fields); $default_gateway_fields = json_decode($gateway->fields);
/*Force gateway properties */ /*Force gateway properties */
@ -68,6 +71,8 @@ class StoreCompanyGatewayRequest extends Request
if (isset($input['fees_and_limits'])) if (isset($input['fees_and_limits']))
$input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']); $input['fees_and_limits'] = $this->cleanFeesAndLimits($input['fees_and_limits']);
}
$this->replace($input); $this->replace($input);
} }

View File

@ -39,6 +39,7 @@ class InvoicePaidActivity implements ShouldQueue
*/ */
public function handle($event) public function handle($event)
{ {
MultiDB::setDb($event->company->db); MultiDB::setDb($event->company->db);
$fields = new stdClass; $fields = new stdClass;
@ -53,6 +54,7 @@ class InvoicePaidActivity implements ShouldQueue
if($event->invoice->subscription()->exists()) if($event->invoice->subscription()->exists())
{ {
nlog("subscription exists");
$event->invoice->subscription->service()->planPaid($event->invoice); $event->invoice->subscription->service()->planPaid($event->invoice);
} }

View File

@ -695,10 +695,14 @@ nlog("handle plan change");
*/ */
public function triggerWebhook($context) 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) { 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]; return ["message" => "Success", "status_code" => 200];
} }
nlog("past first if");
$response = false; $response = false;
$body = array_merge($context, [ $body = array_merge($context, [
@ -709,6 +713,8 @@ nlog("handle plan change");
$response = $this->sendLoad($this->subscription, $body); $response = $this->sendLoad($this->subscription, $body);
nlog("after response");
/* Append the response to the system logger body */ /* Append the response to the system logger body */
if(is_array($response)){ if(is_array($response)){
@ -732,6 +738,7 @@ nlog("handle plan change");
$client->company, $client->company,
); );
nlog("ready to fire back");
if(is_array($body)) if(is_array($body))
return $response; return $response;
@ -909,14 +916,24 @@ nlog("handle plan change");
public function planPaid($invoice) 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 = [
'context' => 'plan_paid', 'context' => 'plan_paid',
'subscription' => $this->subscription->hashed_id, 'subscription' => $this->subscription->hashed_id,
'recurring_invoice' => $invoice->recurring_invoice->hashed_id, 'recurring_invoice' => $recurring_invoice_hashed_id,
'client' => $invoice->client->hashed_id, 'client' => $invoice->client->hashed_id,
'contact' => $invoice->client->primary_contact()->first()->hashed_id, 'contact' => $invoice->client->primary_contact()->first()->hashed_id,
]; ];
$this->triggerWebhook($context); nlog($context);
$response = $this->triggerWebhook($context);
nlog($response);
return true;
} }
} }