From 3477ce5fe29d2b40320f9900be0f52c6a34d1535 Mon Sep 17 00:00:00 2001 From: Sugavanas Date: Mon, 5 Apr 2021 22:36:30 +0800 Subject: [PATCH 1/6] Update README.md Install composer package first before running artisan to set application key. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa2a4db850a6..ddbf730773bf 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Currently the client portal and API are of alpha quality, to get started: git clone https://github.com/invoiceninja/invoiceninja.git git checkout v5-stable cp .env.example .env -php artisan key:generate composer update +php artisan key:generate ``` Please Note: Your APP_KEY in the .env file is used to encrypt data, if you lose this you will not be able to run the application. @@ -91,4 +91,4 @@ To manage our workflow we will be creating separate branches for the client (Flu ## License Invoice Ninja is released under the Attribution Assurance License. -See [LICENSE](LICENSE) for details. \ No newline at end of file +See [LICENSE](LICENSE) for details. From fe7b3c79e77f6b62cdefd9df24060fa9f1ff8de8 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 16:07:35 +1000 Subject: [PATCH 2/6] Working on subscriptions --- .../Subscription/SubscriptionService.php | 52 ++++++------------- tests/Feature/Ninja/PlanTest.php | 4 +- 2 files changed, 16 insertions(+), 40 deletions(-) diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 4e7dd9447d55..4de7e80d7e03 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -111,6 +111,16 @@ class SubscriptionService } } + public function isEligible($contact) + { + $data = [ + 'context' => 'is_eligible', + 'subscription' => $this->subscription->hashed_id, + 'contact' => $contact->hashed_id, + 'contact_email' => $contact->email + ]; + } + /** 'email' => $this->email ?? $this->contact->email, 'quantity' => $this->quantity, @@ -199,45 +209,13 @@ class SubscriptionService return $recurring_invoice; } - // @deprecated due to change in architecture - - // public function createClientSubscription($payment_hash) - // { - - // //is this a recurring or one off subscription. - - // $cs = new ClientSubscription(); - // $cs->subscription_id = $this->subscription->id; - // $cs->company_id = $this->subscription->company_id; - - // $cs->invoice_id = $payment_hash->billing_context->invoice_id; - // $cs->client_id = $payment_hash->billing_context->client_id; - // $cs->quantity = $payment_hash->billing_context->quantity; - - // //if is_recurring - // //create recurring invoice from invoice - // if($this->subscription->is_recurring) - // { - // $recurring_invoice = $this->convertInvoiceToRecurring($payment_hash); - // $recurring_invoice->frequency_id = $this->subscription->frequency_id; - // $recurring_invoice->next_send_date = $recurring_invoice->nextDateByFrequency(now()->format('Y-m-d')); - // $recurring_invoice->save(); - // $cs->recurring_invoice_id = $recurring_invoice->id; - - // //?set the recurring invoice as active - set the date here also based on the frequency? - // $recurring_invoice->service()->start(); - // } - - - // $cs->save(); - - // $this->client_subscription = $cs; - - // } - - //@todo - need refactor public function triggerWebhook($context) { + /* 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) { + return; + } + $body = array_merge($context, [ 'company_key' => $this->subscription->company->company_key, diff --git a/tests/Feature/Ninja/PlanTest.php b/tests/Feature/Ninja/PlanTest.php index 4ec042b83ecf..c2e36583d535 100644 --- a/tests/Feature/Ninja/PlanTest.php +++ b/tests/Feature/Ninja/PlanTest.php @@ -40,7 +40,7 @@ class PlanTest extends TestCase Model::reguard(); } - public function testTrialPlans() + public function testTrialFeatures() { config(['ninja.production' => true]); @@ -51,8 +51,6 @@ class PlanTest extends TestCase $this->account->trial_duration = 60*60*24*31; $this->account->save(); - nlog($this->account->getPlanDetails()); - $this->assertFalse($this->account->hasFeature(Account::FEATURE_USERS)); $this->account->trial_plan = 'pro'; From 6b9001684ea23b6bc316ce33479e4c3b96d8a098 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 17:11:58 +1000 Subject: [PATCH 3/6] Fixes for tests --- app/Services/Subscription/SubscriptionService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 4de7e80d7e03..06f1f1150739 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -212,7 +212,7 @@ class SubscriptionService public function triggerWebhook($context) { /* 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; } From 06c5cf05196ee355681115f71af353473c3db4ec Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 17:14:30 +1000 Subject: [PATCH 4/6] add response to system logger for subscription API calls --- app/Services/Subscription/SubscriptionService.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 06f1f1150739..905c6e3b2bf4 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -244,6 +244,15 @@ class SubscriptionService } + /* Append the response to the system logger body */ + if($response) { + + $status = $response->getStatusCode(); + $response_body = $response->getBody(); + $body = array_merge($body, ['status' => $status, 'response_body' => $response_body]); + + } + $client = \App\Models\Client::find($this->decodePrimaryKey($body['client'])); SystemLogger::dispatch( From fcac89a92cbde94e36d6a13893283f59a1394d63 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 17:55:18 +1000 Subject: [PATCH 5/6] Subscription service --- .../Subscription/SubscriptionService.php | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 905c6e3b2bf4..aa2a47ac2ad9 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -111,21 +111,27 @@ class SubscriptionService } } + /* Hits the client endpoint to determine whether the user is able to access this subscription */ public function isEligible($contact) { - $data = [ + + $context = [ 'context' => 'is_eligible', 'subscription' => $this->subscription->hashed_id, 'contact' => $contact->hashed_id, 'contact_email' => $contact->email ]; + + $response = $this->triggerWebhook($context); + + } - /** - 'email' => $this->email ?? $this->contact->email, - 'quantity' => $this->quantity, - 'contact_id' => $this->contact->id, - */ + /* Starts the process to create a trial + - we create a recurring invoice, which is has its next_send_date as now() + trial_duration + - we then hit the client API end point to advise the trial payload + - 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) { // Redirects from here work just fine. Livewire will respect it. @@ -162,7 +168,7 @@ class SubscriptionService ]; //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){ 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(!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, [ 'company_key' => $this->subscription->company->company_key, @@ -241,7 +248,7 @@ class SubscriptionService } catch(\Exception $e) { - + $body = array_merge($body, ['exception' => $e->getMessage()]); } /* Append the response to the system logger body */ @@ -263,6 +270,8 @@ class SubscriptionService $client, ); + return $response; + } public function fireNotifications() From db5e896e466365c71e2c24c4f5efe3e512b817f3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 6 Apr 2021 19:07:21 +1000 Subject: [PATCH 6/6] 5.1.35 --- VERSION.txt | 2 +- app/Jobs/Mail/PaymentFailureMailer.php | 8 ++++---- app/Mail/Admin/PaymentFailureObject.php | 12 ++++++------ config/ninja.php | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index eeb25c4a8c70..ba7fe367e31c 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.1.34 \ No newline at end of file +5.1.35 \ No newline at end of file diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index bce2f69c3656..7f40eda15cb5 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -38,7 +38,7 @@ class PaymentFailureMailer implements ShouldQueue public $company; - public $payment_hash; + public $amount; public $settings; @@ -50,7 +50,7 @@ class PaymentFailureMailer implements ShouldQueue * @param $company * @param $amount */ - public function __construct($client, $error, $company, $payment_hash) + public function __construct($client, $error, $company, $amount) { $this->company = $company; @@ -58,7 +58,7 @@ class PaymentFailureMailer implements ShouldQueue $this->client = $client; - $this->payment_hash = $payment_hash; + $this->amount = $amount; $this->company = $company; @@ -86,7 +86,7 @@ class PaymentFailureMailer implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); - $mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build(); + $mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount))->build(); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer($mail_obj); diff --git a/app/Mail/Admin/PaymentFailureObject.php b/app/Mail/Admin/PaymentFailureObject.php index 3c199f8e491e..49ddfa4abe0c 100644 --- a/app/Mail/Admin/PaymentFailureObject.php +++ b/app/Mail/Admin/PaymentFailureObject.php @@ -26,9 +26,9 @@ class PaymentFailureObject public $company; - public $payment_hash; + public $amount; - private $invoices; + // private $invoices; /** * Create a new job instance. @@ -38,7 +38,7 @@ class PaymentFailureObject * @param $company * @param $amount */ - public function __construct($client, $error, $company, $payment_hash) + public function __construct($client, $error, $company, $amount) { $this->client = $client; @@ -46,7 +46,7 @@ class PaymentFailureObject $this->company = $company; - $this->payment_hash = $payment_hash; + $this->amount = $amount; $this->company = $company; @@ -55,7 +55,7 @@ class PaymentFailureObject public function build() { - $this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); + // $this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); $mail_obj = new stdClass; $mail_obj->amount = $this->getAmount(); @@ -70,7 +70,7 @@ class PaymentFailureObject private function getAmount() { - return array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; + return $this->amount; } diff --git a/config/ninja.php b/config/ninja.php index 9f868a7a5b1d..407fcb0b25de 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -14,7 +14,7 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '5.1.34', + 'app_version' => '5.1.35', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false),