Skip to content

Commit

Permalink
Prevision a new version to be compatible with Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
aemaddin committed Nov 12, 2024
1 parent 0658672 commit 55c9fa3
Show file tree
Hide file tree
Showing 44 changed files with 226 additions and 469 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ phpunit.xml
build
coverage
docs
/vendor
/phpunit.xml
37 changes: 13 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,19 @@
],
"homepage": "https://github.com/asciisd/cashier-tap",
"require": {
"php": "^8.2",
"ext-json": "*",
"ext-intl": "*",
"dompdf/dompdf": "^2.0.1",
"illuminate/console": "^9.0|^10.0",
"illuminate/contracts": "^9.0|^10.0",
"illuminate/database": "^9.0|^10.0",
"illuminate/http": "^9.0|^10.0",
"illuminate/log": "^9.0|^10.0",
"illuminate/notifications": "^9.0|^10.0",
"illuminate/routing": "^9.0|^10.0",
"illuminate/support": "^9.0|^10.0",
"illuminate/view": "^9.0|^10.0",
"php": "^8.3",
"dompdf/dompdf": "^2.0",
"moneyphp/money": "^4.0",
"nesbot/carbon": "^2.0",
"symfony/http-kernel": "^6.0",
"symfony/polyfill-intl-icu": "^1.22.1",
"asciisd/tap-php": "^2.0"
"asciisd/tap-php": "^2.0",
"ext-intl": "*"
},
"require-dev": {
"ext-json": "*",
"laravel/framework": "^10.0|^11.0",
"mockery/mockery": "^1.0",
"orchestra/testbench": "^6.0|^7.0",
"phpunit/phpunit": "^9.0|^10.0"
"orchestra/testbench": "^8.18|^9.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.4"
},
"suggest": {
"ext-intl": "Allows for more locales besides the default \"en\" when formatting money values."
Expand All @@ -64,12 +54,11 @@
]
}
},
"scripts": {
"test": "vendor/bin/phpunit --colors=always",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
Expand Down
13 changes: 0 additions & 13 deletions config/cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@

'redirect_url' => env('CASHIER_REDIRECT_URL', '/tap/receipt'),

/*
|--------------------------------------------------------------------------
| Cashier Model
|--------------------------------------------------------------------------
|
| This is the model in your application that implements the Billable trait
| provided by Cashier. It will serve as the primary model you use while
| interacting with Cashier related methods, subscriptions, and so on.
|
*/

'model' => env('CASHIER_MODEL', App\Models\User::class),

/*
|--------------------------------------------------------------------------
| Currency Locale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCustomerColumns extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
if (!Schema::hasColumn('users', 'first_name')) {
Expand Down Expand Up @@ -45,10 +43,8 @@ public function up()

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn([
Expand All @@ -59,4 +55,4 @@ public function down()
]);
});
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSubscriptionsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('subscriptions', function (Blueprint $table) {
$table->bigIncrements('id');
Expand All @@ -31,11 +29,9 @@ public function up()

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('subscriptions');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSubscriptionItemsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('subscription_items', function (Blueprint $table) {
$table->bigIncrements('id');
Expand All @@ -27,11 +25,9 @@ public function up()

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('subscription_items');
}
}
};
16 changes: 1 addition & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<phpunit colors="true">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
Expand All @@ -24,9 +12,7 @@
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

<env name="CASHIER_MODEL" value="Asciisd\Cashier\Tests\Fixtures\User"/>

<env name="TAP_API_KEY" value="sk_test_XKokBfNWv6FIYuTMg5sLPjhJ"/>
</php>
</phpunit>
14 changes: 0 additions & 14 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@
use Asciisd\Cashier\Concerns\ManagesSubscriptions;
use Asciisd\Cashier\Concerns\PerformsCharges;

/**
* Trait Billable
*
* @property integer $tap_id
* @property string $email
* @property string $phone
* @property string $phone_code
* @property string $first_name
* @property string $last_name
* @property string $card_brand
* @property string $trial_ends_at
*
* @package Asciisd\Cashier
*/
trait Billable
{
use ManagesCustomer;
Expand Down
58 changes: 27 additions & 31 deletions src/Cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ class Cashier

/**
* The Cashier library version.
*
* @var string
*/
const VERSION = '2.1.1';
const string VERSION = '3.0.0';

/**
* The Tap API version.
*
* @var string
*/
const TAP_VERSION = 'v2';
const string TAP_VERSION = 'v2';

/**
* The custom currency formatter.
Expand All @@ -39,36 +35,33 @@ class Cashier

/**
* Indicates if Cashier migrations will be run.
*
* @var bool
*/
public static bool $runsMigrations = true;

/**
* Indicates if Cashier routes will be registered.
*
* @var bool
*/
public static bool $registersRoutes = true;

/**
* The default customer model class name.
*/
public static string $customerModel = 'App\\Models\\User';


/**
* Get the default Tap API options.
*
* @param array $options
* @return array
*/
public static function tapOptions(array $options = []): array
{
return array_merge([
'api_key' => config('cashier.secret'),
'api_key' => config('cashier.secret'),
'tap_version' => static::TAP_VERSION,
], $options);
}

/**
* Configure Cashier to not register its migrations.
*
* @return static
*/
public static function ignoreMigrations(): static
{
Expand All @@ -79,8 +72,6 @@ public static function ignoreMigrations(): static

/**
* Configure Cashier to not register its routes.
*
* @return static
*/
public static function ignoreRoutes(): static
{
Expand All @@ -89,13 +80,16 @@ public static function ignoreRoutes(): static
return new static;
}

/**
* Set the custom currency formatter.
*/
public static function formatCurrencyUsing(callable $callback): void
{
static::$formatCurrencyUsing = $callback;
}

/**
* Format the given amount into a displayable currency.
*
* @param int $amount
* @param string|null $currency
* @param int $multiply_by
* @return string
*/
public static function formatAmount(int $amount, string $currency = null, int $multiply_by = 100): string
{
Expand All @@ -113,29 +107,31 @@ public static function formatAmount(int $amount, string $currency = null, int $m

/**
* generate receipt link to show the charge receipt on web
*
* @param $receipt_id
* @return string
*/
public static function receipt($receipt_id): string
{
return config('cashier.redirect_url') . '?tap_id=' . $receipt_id;
return config('cashier.redirect_url').'?tap_id='.$receipt_id;
}

/**
* Get the billable entity instance by Stripe ID.
*
* @param string $tapId
* @return ?Billable
*/
public static function findBillable(string $tapId): ?Billable
{
if ($tapId == null) {
return null;
}

$model = config('cashier.model');
$model = static::$customerModel;

return (new $model)->where('tap_id', $tapId)->first();
}

/**
* Set the customer model class name.
*/
public static function useCustomerModel(string $customerModel): void
{
static::$customerModel = $customerModel;
}
}
Loading

0 comments on commit 55c9fa3

Please sign in to comment.