Working on subs

This commit is contained in:
David Bomba 2021-04-05 12:42:49 +10:00
parent fcaabace7f
commit 8d4fa8cb42

View File

@ -152,8 +152,9 @@ class SubscriptionService
//execute any webhooks //execute any webhooks
$this->triggerWebhook($context); $this->triggerWebhook($context);
if(array_key_exists('post_purchase_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['post_purchase_url']) >=1) if(array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_url']) >=1){
return redirect($this->subscription->webhook_configuration['post_purchase_url']); return redirect($this->subscription->webhook_configuration['return_url']);
}
return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id); return redirect('/client/recurring_invoices/'.$recurring_invoice->hashed_id);
} }
@ -235,28 +236,37 @@ class SubscriptionService
//@todo - need refactor //@todo - need refactor
public function triggerWebhook($context) public function triggerWebhook($context)
{ {
//context = 'trial, recurring_purchase, single_purchase'
//hit the webhook to after a successful onboarding
$body = $context; $body = array_merge($context, [
'company_key' => $this->subscription->company->company_key,
'account_key' => $this->subscription->company->account->key,
'db' => $this->subscription->company->db,
]);
if(Ninja::isHosted()) $headers = [
{ 'Content-Type' => 'application/json',
$hosted = [ 'X-Requested-With' => 'XMLHttpRequest',
'company' => $this->subscription->company,
]; ];
$body = array_merge($body, $hosted); //$this->subscription->webhook_configuration['post_purchase_headers']
}
$client = new \GuzzleHttp\Client( $client = new \GuzzleHttp\Client(
[ [
'headers' => $this->subscription->webhook_configuration['post_purchase_headers'] 'headers' => $headers,
]); ]);
try{
$response = $client->{$this->subscription->webhook_configuration['post_purchase_rest_method']}($this->subscription->webhook_configuration['post_purchase_url'],[ $response = $client->{$this->subscription->webhook_configuration['post_purchase_rest_method']}($this->subscription->webhook_configuration['post_purchase_url'],[
RequestOptions::JSON => ['body' => $body] RequestOptions::JSON => ['body' => $body], RequestOptions::ALLOW_REDIRECTS => false
]); ]);
}
catch(\Exception $e)
{
nlog($e->getMessage());
}
// $response = $client->post('http://ninja.test:8000/api/admin/plan',[RequestOptions::JSON => ['body' => $body]]);
// SystemLogger::dispatch( // SystemLogger::dispatch(
// $body, // $body,