Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: subscribe with the customer portal instead of stripe #6049

Draft
wants to merge 48 commits into
base: 4.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b475659
feat: subscribe with the customer portal instead of stripe
djaiss Mar 9, 2022
2cf35f6
Apply fixes from StyleCI
StyleCIBot Mar 9, 2022
7f16190
wip
djaiss Mar 9, 2022
1956aa1
Apply fixes from StyleCI
StyleCIBot Mar 9, 2022
fd4e04f
wip
djaiss Mar 9, 2022
736acae
Apply fixes from StyleCI
StyleCIBot Mar 9, 2022
af214e8
wip
djaiss Mar 9, 2022
b316fac
Apply fixes from StyleCI
StyleCIBot Mar 9, 2022
d313412
Merge branch 'main' into 2022-03-07-billing
djaiss Mar 9, 2022
0af387c
Update package.json
djaiss Mar 11, 2022
0ddd47b
Update composer.lock
djaiss Mar 11, 2022
2e93998
Update app/Services/Account/Subscription/ActivateLicenceKey.php
djaiss May 14, 2022
8778755
Apply fixes from StyleCI
StyleCIBot May 14, 2022
6e43528
Update resources/views/settings/subscriptions/blank.blade.php
djaiss May 15, 2022
0289cfe
Update resources/views/settings/subscriptions/blank.blade.php
djaiss May 15, 2022
5163375
Update app/Services/Account/Subscription/ActivateLicenceKey.php
djaiss May 15, 2022
d05d621
Update app/Services/Account/Subscription/ActivateLicenceKey.php
djaiss May 15, 2022
fecc952
Update app/Services/Account/Subscription/ActivateLicenceKey.php
djaiss May 15, 2022
444113e
Update app/Jobs/Settings/CheckLicenceKeys.php
djaiss May 15, 2022
c64e5d3
Update app/Models/Account/Account.php
djaiss May 15, 2022
cc37c80
Update app/Services/Account/Subscription/ActivateLicenceKey.php
djaiss May 15, 2022
f22a05e
changes
djaiss May 15, 2022
8a01c7e
adapt with last monicahq/customers changes
asbiin May 16, 2022
25f022c
Apply fixes from StyleCI
StyleCIBot May 16, 2022
4c74f4f
add tests
asbiin May 16, 2022
d806e91
Merge branch '2022-03-07-billing' of github.com:monicahq/monica into …
asbiin May 16, 2022
b5615db
Apply fixes from StyleCI
StyleCIBot May 16, 2022
94a3159
more tests
asbiin May 16, 2022
2df3c55
Apply fixes from StyleCI
StyleCIBot May 16, 2022
58af6db
Merge remote-tracking branch 'origin/main' into 2022-03-07-billing
asbiin May 16, 2022
0af744e
split decodeAndStoreKey
asbiin May 20, 2022
0b68cca
Apply fixes from StyleCI
StyleCIBot May 20, 2022
a9c6c64
Merge branch 'main' into 2022-03-07-billing
djaiss Jul 23, 2022
f8d6f42
Merge branch 'main' into 2022-03-07-billing
djaiss Aug 22, 2022
57f569b
Update AppServiceProvider.php
djaiss Aug 23, 2022
44ae474
Update AccountSubscriptionTest.php
djaiss Aug 23, 2022
ecb82c1
fixes
djaiss Aug 24, 2022
773b853
Delete AccountSubscriptionTest.php
djaiss Aug 25, 2022
7542222
fixes
djaiss Oct 2, 2022
a4fef9c
Merge branch 'main' into 2022-03-07-billing
djaiss Oct 2, 2022
30d9f99
Apply fixes from StyleCI
StyleCIBot Oct 2, 2022
fa6b646
fix
djaiss Oct 2, 2022
258c427
use MissingPrivateKeyException
asbiin Oct 18, 2022
9db1975
Apply fixes from StyleCI
StyleCIBot Oct 18, 2022
964972e
Merge remote-tracking branch 'origin/main' into 2022-03-07-billing
asbiin Oct 19, 2022
9884708
get next_check_at from api call
asbiin Oct 19, 2022
c6ac38e
fix job schedule
asbiin Oct 20, 2022
25a1916
update change and cancel links
asbiin Oct 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Expand Up @@ -79,7 +79,7 @@ jobs:
mkdir -p public/js public/css results/coverage
{\
echo "{"; \
for f in app.js manifest.js vendor.js app-ltr.css app-rtl.css stripe.js stripe.css; do \
for f in app.js manifest.js vendor.js app-ltr.css app-rtl.css; do \
[[ $first == 1 ]] && echo -n "," || first=1; \
k=${f##*.}/$f; \
echo "\"/$k\": \"/$k\""; \
Expand Down
3 changes: 3 additions & 0 deletions app/Console/Kernel.php
Expand Up @@ -3,6 +3,7 @@
namespace App\Console;

use App\Console\Scheduling\CronEvent;
use App\Jobs\Settings\CheckLicenceKeys;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand Down Expand Up @@ -54,6 +55,8 @@ protected function schedule(Schedule $schedule)
$this->scheduleCommand($schedule, 'cloudflare:reload', 'daily');
}
$this->scheduleCommand($schedule, 'model:prune', 'daily');

$schedule->job(new CheckLicenceKeys)->everySixHours();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use the scheduleCommand command, see above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if it's a not a command but a job?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On some installation, schedule can't be done exactly at xx:00 hours. Laravel doesn't really support that.

}

/**
Expand Down
9 changes: 9 additions & 0 deletions app/Exceptions/NoCustomerPortalSetException.php
@@ -0,0 +1,9 @@
<?php

namespace App\Exceptions;

use RuntimeException;

class NoCustomerPortalSetException extends RuntimeException
{
}
9 changes: 9 additions & 0 deletions app/Exceptions/NoLicenceKeyEncryptionSetException.php
@@ -0,0 +1,9 @@
<?php

namespace App\Exceptions;

use RuntimeException;

class NoLicenceKeyEncryptionSetException extends RuntimeException
{
}
17 changes: 0 additions & 17 deletions app/Helpers/DateHelper.php
Expand Up @@ -265,23 +265,6 @@ public static function getMonthAndYear(int $month): string
return $date->translatedFormat($format) ?: '';
}

/**
* Gets the next theoritical billing date.
* This is used on the Upgrade page to tell the user when the next billing
* date would be if he subscribed.
*
* @param string $interval
* @return Carbon
*/
public static function getNextTheoriticalBillingDate(string $interval): Carbon
{
if ($interval == 'monthly') {
return now(static::getTimezone())->addMonth();
}

return now(static::getTimezone())->addYear();
}

/**
* Gets a list of all the year from min to max (0 is the current year).
*
Expand Down
53 changes: 0 additions & 53 deletions app/Helpers/InstanceHelper.php
Expand Up @@ -2,26 +2,13 @@

namespace App\Helpers;

use Carbon\Carbon;
use function Safe\json_decode;
use App\Models\Account\Account;
use App\Models\Instance\Instance;
use App\Models\Settings\Currency;
use Illuminate\Support\Facades\DB;
use function Safe\file_get_contents;

class InstanceHelper
{
/**
* Get the number of paid accounts in the instance.
*
* @return int
*/
public static function getNumberOfPaidSubscribers()
{
return Account::where('stripe_id', '!=', null)->count();
}

/**
* Get the plan information for the given time period.
*
Expand All @@ -48,46 +35,6 @@ public static function getPlanInformationFromConfig(string $timePeriod): ?array
];
}

/**
* Get the plan information for the given time period.
*
* @param \Laravel\Cashier\Subscription $subscription
* @return array|null
*/
public static function getPlanInformationFromSubscription(\Laravel\Cashier\Subscription $subscription): ?array
{
try {
$stripeSubscription = $subscription->asStripeSubscription();
$plan = $stripeSubscription->plan;
} catch (\Stripe\Exception\ApiErrorException $e) {
$stripeSubscription = null;
$plan = null;
}

if (is_null($stripeSubscription) || is_null($plan)) {
return [
'type' => $subscription->stripe_plan,
'name' => $subscription->name,
'id' => $subscription->stripe_id,
'price' => '?',
'friendlyPrice' => '?',
'nextBillingDate' => '',
];
}

$currency = Currency::where('iso', strtoupper($plan->currency))->first();
$amount = MoneyHelper::format($plan->amount, $currency);

return [
'type' => $plan->interval === 'month' ? 'monthly' : 'annual',
'name' => $subscription->name,
'id' => $plan->id,
'price' => $plan->amount,
'friendlyPrice' => $amount,
'nextBillingDate' => DateHelper::getFullDate(Carbon::createFromTimestamp($stripeSubscription->current_period_end)),
];
}

/**
* Get changelogs entries.
*
Expand Down