mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 08:37:32 -05:00 
			
		
		
		
	Subscription service
This commit is contained in:
		
							parent
							
								
									06c5cf0519
								
							
						
					
					
						commit
						fcac89a92c
					
				@ -111,20 +111,26 @@ class SubscriptionService
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Hits the client endpoint to determine whether the user is able to access this subscription */
 | 
				
			||||||
    public function isEligible($contact)
 | 
					    public function isEligible($contact)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $data = [
 | 
					
 | 
				
			||||||
 | 
					        $context = [
 | 
				
			||||||
            'context' => 'is_eligible',
 | 
					            'context' => 'is_eligible',
 | 
				
			||||||
            'subscription' => $this->subscription->hashed_id,
 | 
					            'subscription' => $this->subscription->hashed_id,
 | 
				
			||||||
            'contact' => $contact->hashed_id,
 | 
					            'contact' => $contact->hashed_id,
 | 
				
			||||||
            'contact_email' => $contact->email
 | 
					            'contact_email' => $contact->email
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $response = $this->triggerWebhook($context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /* Starts the process to create a trial 
 | 
				
			||||||
        'email' => $this->email ?? $this->contact->email,
 | 
					        - we create a recurring invoice, which is has its next_send_date as now() + trial_duration
 | 
				
			||||||
        'quantity' => $this->quantity,
 | 
					        - we then hit the client API end point to advise the trial payload
 | 
				
			||||||
        'contact_id' => $this->contact->id,
 | 
					        - we then return the user to either a predefined user endpoint, OR we return the user to the recurring invoice page.
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
    public function startTrial(array $data)
 | 
					    public function startTrial(array $data)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -162,7 +168,7 @@ class SubscriptionService
 | 
				
			|||||||
            ];
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //execute any webhooks
 | 
					        //execute any webhooks
 | 
				
			||||||
        $this->triggerWebhook($context);
 | 
					        $response = $this->triggerWebhook($context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(array_key_exists('return_url', $this->subscription->webhook_configuration) && strlen($this->subscription->webhook_configuration['return_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['return_url']);
 | 
					            return redirect($this->subscription->webhook_configuration['return_url']);
 | 
				
			||||||
@ -213,9 +219,10 @@ class SubscriptionService
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        /* If no webhooks have been set, then just return gracefully */
 | 
					        /* If no webhooks have been set, then just return gracefully */
 | 
				
			||||||
        if(!array_key_exists('post_purchase_url', $this->subscription->webhook_configuration) || !array_key_exists('post_purchase_rest_method', $this->subscription->webhook_configuration)) {
 | 
					        if(!array_key_exists('post_purchase_url', $this->subscription->webhook_configuration) || !array_key_exists('post_purchase_rest_method', $this->subscription->webhook_configuration)) {
 | 
				
			||||||
            return;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $response = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $body = array_merge($context, [
 | 
					        $body = array_merge($context, [
 | 
				
			||||||
            'company_key' => $this->subscription->company->company_key, 
 | 
					            'company_key' => $this->subscription->company->company_key, 
 | 
				
			||||||
@ -241,7 +248,7 @@ class SubscriptionService
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        catch(\Exception $e)
 | 
					        catch(\Exception $e)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            $body = array_merge($body, ['exception' => $e->getMessage()]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Append the response to the system logger body */
 | 
					        /* Append the response to the system logger body */
 | 
				
			||||||
@ -263,6 +270,8 @@ class SubscriptionService
 | 
				
			|||||||
                $client,
 | 
					                $client,
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $response;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function fireNotifications()
 | 
					    public function fireNotifications()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user