mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on subs
This commit is contained in:
parent
fcaabace7f
commit
8d4fa8cb42
@ -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,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $client->{$this->subscription->webhook_configuration['post_purchase_rest_method']}($this->subscription->webhook_configuration['post_purchase_url'],[
|
|
||||||
RequestOptions::JSON => ['body' => $body]
|
try{
|
||||||
]);
|
$response = $client->{$this->subscription->webhook_configuration['post_purchase_rest_method']}($this->subscription->webhook_configuration['post_purchase_url'],[
|
||||||
|
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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user