From 528cb46bc272da1003d4c23418cea528b5cd5814 Mon Sep 17 00:00:00 2001 From: Polash Mahmud Date: Fri, 15 Sep 2023 12:37:17 +0600 Subject: [PATCH] class 4 --- app/Models/User.php | 3 +- composer.json | 1 + composer.lock | 326 +++++++++++++++++- ...9_05_03_000001_create_customer_columns.php | 36 ++ ...5_03_000002_create_subscriptions_table.php | 37 ++ ...000003_create_subscription_items_table.php | 34 ++ 6 files changed, 435 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2019_05_03_000001_create_customer_columns.php create mode 100644 database/migrations/2019_05_03_000002_create_subscriptions_table.php create mode 100644 database/migrations/2019_05_03_000003_create_subscription_items_table.php diff --git a/app/Models/User.php b/app/Models/User.php index 4d7f70f..406e7c0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,11 +6,12 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use Laravel\Cashier\Billable; use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable { - use HasApiTokens, HasFactory, Notifiable; + use HasApiTokens, HasFactory, Notifiable, Billable; /** * The attributes that are mass assignable. diff --git a/composer.json b/composer.json index 0efa9d3..9dbb165 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^8.1", "guzzlehttp/guzzle": "^7.2", + "laravel/cashier": "^14.12", "laravel/framework": "^10.10", "laravel/sanctum": "^3.2", "laravel/tinker": "^2.8" diff --git a/composer.lock b/composer.lock index 339da04..45e89bd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "03d1ef0b4c68f9b53f2bc27cd259e542", + "content-hash": "4420f813d2a101c48f819477dd583512", "packages": [ { "name": "brick/math", @@ -970,6 +970,93 @@ ], "time": "2023-08-27T10:19:19+00:00" }, + { + "name": "laravel/cashier", + "version": "v14.12.6", + "source": { + "type": "git", + "url": "https://github.com/laravel/cashier-stripe.git", + "reference": "264100d22ff5842564ddf7090e6b5b6c6bcfae08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/cashier-stripe/zipball/264100d22ff5842564ddf7090e6b5b6c6bcfae08", + "reference": "264100d22ff5842564ddf7090e6b5b6c6bcfae08", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/console": "^9.21|^10.0", + "illuminate/contracts": "^9.21|^10.0", + "illuminate/database": "^9.21|^10.0", + "illuminate/http": "^9.21|^10.0", + "illuminate/log": "^9.21|^10.0", + "illuminate/notifications": "^9.21|^10.0", + "illuminate/pagination": "^9.21|^10.0", + "illuminate/routing": "^9.21|^10.0", + "illuminate/support": "^9.21|^10.0", + "illuminate/view": "^9.21|^10.0", + "moneyphp/money": "^4.0", + "nesbot/carbon": "^2.0", + "php": "^8.0", + "stripe/stripe-php": "^7.39|^8.0|^9.0|^10.0", + "symfony/http-kernel": "^6.0", + "symfony/polyfill-intl-icu": "^1.22.1" + }, + "require-dev": { + "dompdf/dompdf": "^2.0", + "mockery/mockery": "^1.0", + "orchestra/testbench": "^7.0|^8.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.0" + }, + "suggest": { + "dompdf/dompdf": "Required when generating and downloading invoice PDF's using Dompdf (^1.0.1|^2.0).", + "ext-intl": "Allows for more locales besides the default \"en\" when formatting money values." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "14.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Cashier\\CashierServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Cashier\\": "src/", + "Laravel\\Cashier\\Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + }, + { + "name": "Dries Vints", + "email": "dries@laravel.com" + } + ], + "description": "Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.", + "keywords": [ + "billing", + "laravel", + "stripe" + ], + "support": { + "issues": "https://github.com/laravel/cashier/issues", + "source": "https://github.com/laravel/cashier" + }, + "time": "2023-09-08T05:36:55+00:00" + }, { "name": "laravel/framework", "version": "v10.23.1", @@ -1807,6 +1894,95 @@ ], "time": "2023-08-05T12:09:49+00:00" }, + { + "name": "moneyphp/money", + "version": "v4.2.0", + "source": { + "type": "git", + "url": "https://github.com/moneyphp/money.git", + "reference": "f660ab7f1d7a4c2ffdd30f50c55ed2c95c26fc3f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/moneyphp/money/zipball/f660ab7f1d7a4c2ffdd30f50c55ed2c95c26fc3f", + "reference": "f660ab7f1d7a4c2ffdd30f50c55ed2c95c26fc3f", + "shasum": "" + }, + "require": { + "ext-bcmath": "*", + "ext-filter": "*", + "ext-json": "*", + "php": "~8.0.0 || ~8.1.0 || ~8.2.0" + }, + "require-dev": { + "cache/taggable-cache": "^1.1.0", + "doctrine/coding-standard": "^9.0", + "doctrine/instantiator": "^1.4.0", + "ext-gmp": "*", + "ext-intl": "*", + "florianv/exchanger": "^2.6.3", + "florianv/swap": "^4.3.0", + "moneyphp/crypto-currencies": "^1.0.0", + "moneyphp/iso-currencies": "^3.2.1", + "php-http/message": "^1.11.0", + "php-http/mock-client": "^1.4.1", + "phpbench/phpbench": "^1.2.5", + "phpspec/phpspec": "^7.3", + "phpunit/phpunit": "^9.5.4", + "psalm/plugin-phpunit": "^0.18.4", + "psr/cache": "^1.0.1", + "vimeo/psalm": "~5.3.0" + }, + "suggest": { + "ext-gmp": "Calculate without integer limits", + "ext-intl": "Format Money objects with intl", + "florianv/exchanger": "Exchange rates library for PHP", + "florianv/swap": "Exchange rates library for PHP", + "psr/cache-implementation": "Used for Currency caching" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Money\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mathias Verraes", + "email": "mathias@verraes.net", + "homepage": "http://verraes.net" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + }, + { + "name": "Frederik Bosch", + "email": "f.bosch@genkgo.nl" + } + ], + "description": "PHP implementation of Fowler's Money pattern", + "homepage": "http://moneyphp.org", + "keywords": [ + "Value Object", + "money", + "vo" + ], + "support": { + "issues": "https://github.com/moneyphp/money/issues", + "source": "https://github.com/moneyphp/money/tree/v4.2.0" + }, + "time": "2023-08-16T14:31:24+00:00" + }, { "name": "monolog/monolog", "version": "3.4.0", @@ -3093,6 +3269,67 @@ ], "time": "2023-04-15T23:01:58+00:00" }, + { + "name": "stripe/stripe-php", + "version": "v10.21.0", + "source": { + "type": "git", + "url": "https://github.com/stripe/stripe-php.git", + "reference": "b4ab319731958077227fad1874a3671458c5d593" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stripe/stripe-php/zipball/b4ab319731958077227fad1874a3671458c5d593", + "reference": "b4ab319731958077227fad1874a3671458c5d593", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=5.6.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "3.5.0", + "php-coveralls/php-coveralls": "^2.5", + "phpstan/phpstan": "^1.2", + "phpunit/phpunit": "^5.7 || ^9.0", + "squizlabs/php_codesniffer": "^3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Stripe\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stripe and contributors", + "homepage": "https://github.com/stripe/stripe-php/contributors" + } + ], + "description": "Stripe PHP Library", + "homepage": "https://stripe.com/", + "keywords": [ + "api", + "payment processing", + "stripe" + ], + "support": { + "issues": "https://github.com/stripe/stripe-php/issues", + "source": "https://github.com/stripe/stripe-php/tree/v10.21.0" + }, + "time": "2023-08-11T00:23:24+00:00" + }, { "name": "symfony/console", "version": "v6.3.4", @@ -4126,6 +4363,93 @@ ], "time": "2023-01-26T09:26:14+00:00" }, + { + "name": "symfony/polyfill-intl-icu", + "version": "v1.28.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-icu.git", + "reference": "e46b4da57951a16053cd751f63f4a24292788157" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-icu/zipball/e46b4da57951a16053cd751f63f4a24292788157", + "reference": "e46b4da57951a16053cd751f63f4a24292788157", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance and support of other locales than \"en\"" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.28-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Icu\\": "" + }, + "classmap": [ + "Resources/stubs" + ], + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's ICU-related data and classes", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "icu", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-icu/tree/v1.28.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-03-21T17:27:24+00:00" + }, { "name": "symfony/polyfill-intl-idn", "version": "v1.28.0", diff --git a/database/migrations/2019_05_03_000001_create_customer_columns.php b/database/migrations/2019_05_03_000001_create_customer_columns.php new file mode 100644 index 0000000..bd17cfe --- /dev/null +++ b/database/migrations/2019_05_03_000001_create_customer_columns.php @@ -0,0 +1,36 @@ +string('stripe_id')->nullable()->index(); + $table->string('pm_type')->nullable(); + $table->string('pm_last_four', 4)->nullable(); + $table->timestamp('trial_ends_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn([ + 'stripe_id', + 'pm_type', + 'pm_last_four', + 'trial_ends_at', + ]); + }); + } +}; diff --git a/database/migrations/2019_05_03_000002_create_subscriptions_table.php b/database/migrations/2019_05_03_000002_create_subscriptions_table.php new file mode 100644 index 0000000..951363f --- /dev/null +++ b/database/migrations/2019_05_03_000002_create_subscriptions_table.php @@ -0,0 +1,37 @@ +id(); + $table->foreignId('user_id'); + $table->string('name'); + $table->string('stripe_id')->unique(); + $table->string('stripe_status'); + $table->string('stripe_price')->nullable(); + $table->integer('quantity')->nullable(); + $table->timestamp('trial_ends_at')->nullable(); + $table->timestamp('ends_at')->nullable(); + $table->timestamps(); + + $table->index(['user_id', 'stripe_status']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('subscriptions'); + } +}; diff --git a/database/migrations/2019_05_03_000003_create_subscription_items_table.php b/database/migrations/2019_05_03_000003_create_subscription_items_table.php new file mode 100644 index 0000000..c81bd55 --- /dev/null +++ b/database/migrations/2019_05_03_000003_create_subscription_items_table.php @@ -0,0 +1,34 @@ +id(); + $table->foreignId('subscription_id'); + $table->string('stripe_id')->unique(); + $table->string('stripe_product'); + $table->string('stripe_price'); + $table->integer('quantity')->nullable(); + $table->timestamps(); + + $table->unique(['subscription_id', 'stripe_price']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('subscription_items'); + } +};