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

[2.x] Extract service module into payavel/orchestration package. #36

Merged
merged 54 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
04534c5
Require payavel/service
r-kujawa May 17, 2023
dcc2902
Require serviceable
r-kujawa Aug 10, 2023
207eee9
Replace checkout's providable with serviceable one
r-kujawa Aug 14, 2023
417e0e2
Update missed comment
r-kujawa Aug 14, 2023
10b5194
Replace checkout merchantable with serviceable one
r-kujawa Aug 14, 2023
dacecf6
Remove DTO's
r-kujawa Aug 15, 2023
d64a2c8
Remove PaymentMerchant
r-kujawa Aug 17, 2023
2a4cc16
Remove PaymentProvider
r-kujawa Aug 17, 2023
6f7dacd
Fix some factories
r-kujawa Aug 17, 2023
7994117
Use Service over PaymentService
r-kujawa Aug 17, 2023
174f382
Kill the drivers
r-kujawa Aug 17, 2023
355f7bc
Update merchants in tests
r-kujawa Aug 17, 2023
71215a3
Delete PaymentServiceDriver.php
r-kujawa Aug 17, 2023
ef476d2
Update migration
r-kujawa Aug 17, 2023
6947350
ThrowsRuntimeException
r-kujawa Aug 17, 2023
24f0007
SimulateAttributes
r-kujawa Aug 17, 2023
94e1528
Reuse service:install command
r-kujawa Aug 17, 2023
a5eb6b4
Reuse service:provider command
r-kujawa Aug 17, 2023
2a42f32
Delete unused traits
r-kujawa Aug 17, 2023
0733b92
Forgot some files
r-kujawa Aug 18, 2023
a4b1dd3
Fix install command tests by killing them
r-kujawa Aug 18, 2023
c2586ec
Align tests with exception messages
r-kujawa Aug 18, 2023
64cb30f
Try extending the command?
r-kujawa Aug 18, 2023
f936b59
Try extending instead of calling?
r-kujawa Aug 18, 2023
8697b2a
Replace payment with checkout
r-kujawa Aug 18, 2023
7868fae
Finish fixing tests
r-kujawa Aug 18, 2023
e7adba6
Test checkout:provider command
r-kujawa Aug 24, 2023
9f211b8
Test checkout:install command
r-kujawa Aug 24, 2023
a45e660
Update Serviceable to Orchestration
r-kujawa Dec 7, 2023
3497670
Update payavel/orchestration
r-kujawa Apr 12, 2024
7bb973f
Fix workflow format
r-kujawa Apr 12, 2024
34a5530
Extend from orchestration TestCase
r-kujawa Apr 12, 2024
543bcea
Refactor checkout:install command test
r-kujawa Apr 12, 2024
41ebf1a
Refactor checkout:provider command test
r-kujawa Apr 14, 2024
8b4813c
Fix the checkout:install test
r-kujawa Apr 14, 2024
da47b92
Fix checkout:provider test
r-kujawa Apr 14, 2024
d34a186
Update phpunit.xml
r-kujawa Apr 14, 2024
9d540f3
Fix phpunit deprecations
r-kujawa Apr 14, 2024
d8d1691
Move database out of src
r-kujawa Apr 14, 2024
893c73c
Fix Billable trait test
r-kujawa Apr 14, 2024
d76386f
Remove orchestration tests
r-kujawa Apr 14, 2024
9d3f54d
Set up checkout gateway test using orchestration
r-kujawa Apr 14, 2024
b52af0b
Rename merchant to account
r-kujawa Apr 15, 2024
5049e32
Upgrade to anonymous migrations
r-kujawa Apr 15, 2024
c72903f
Remove GatewayTestCase
r-kujawa Apr 15, 2024
cc41572
Remove the stubs
r-kujawa Apr 15, 2024
29d8a0d
Move config
r-kujawa Apr 17, 2024
78a2877
Add id option to ensure checkout id is not modified
r-kujawa Apr 17, 2024
b7c5d70
Inherit from orchestration
r-kujawa Apr 17, 2024
511f567
Update payment.php config
r-kujawa Apr 17, 2024
8e3d57f
:violin: Use orchestration's HasFactory
r-kujawa Apr 17, 2024
5a024e2
Update models & factories
r-kujawa Apr 19, 2024
3c5adf7
Fix test
r-kujawa Apr 19, 2024
ff225d3
Update orchestration to master
r-kujawa Apr 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.4, 8.0, 8.1, 8.2]
laravel: [8.*, 9.*]
php: [8.1, 8.2, 8.3]
laravel: [10.*, 11.*]
dependency-version: [prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 9.*
testbench: 7.*
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 8.*
php: 8.2
- laravel: 9.*
php: 7.4
- laravel: 11.*
php: 8.1

steps:
- name: Checkout code
Expand All @@ -50,3 +48,5 @@ jobs:

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@
"email": "[email protected]"
}
],
"require-dev": {
"orchestra/testbench": "^6.0|^7.0"
},
"autoload": {
"psr-4": {
"Payavel\\Checkout\\": "src/",
"Payavel\\Checkout\\Database\\Factories\\": "src/database/factories/",
"Payavel\\Checkout\\Database\\Seeders\\": "src/database/seeders/"
"Payavel\\Checkout\\Database\\Factories\\": "database/factories/",
"Payavel\\Checkout\\Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Payavel\\Checkout\\Tests\\": "tests/",
"Payavel\\Checkout\\Tests\\App\\": "tests/app/"
"Payavel\\Orchestration\\Tests\\": "vendor/payavel/orchestration/tests/"
}
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"require": {
"payavel/orchestration": "dev-master"
},
"require-dev": {
"orchestra/testbench": "^8.0|^9.0"
},
"extra": {
"laravel": {
"providers": [
Expand Down
31 changes: 31 additions & 0 deletions config/checkout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

return [

'name' => 'Checkout',

/*
|--------------------------------------------------------------------------
| Checkout Test Mode
|--------------------------------------------------------------------------
|
| When set to true, the provider & account will be shared with the fake payment
| request so you can mock your responses as you wish. This is very useful for
| local & testing environments where a sandbox is limited or non-existent.
|
*/
'test_mode' => env('PAYMENT_TEST_MODE', false),

/*
|--------------------------------------------------------------------------
| Checkout Testing
|--------------------------------------------------------------------------
|
| This option allows you to define the location of the fake payment
| request & response classes you would like to leverage when test_mode
| is set to true. Also, feel free to add any other settings here.
|
*/
'test_gateway' => \App\Services\Payment\FakePaymentRequest::class,

];
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
use Payavel\Checkout\Models\Wallet;
use Payavel\Checkout\Models\PaymentMethod;
use Payavel\Checkout\Models\PaymentType;
use Payavel\Orchestration\Support\ServiceConfig;

class PaymentMethodFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @return string
* @var string
*/
public function modelName()
{
return config('payment.models.' . PaymentMethod::class, PaymentMethod::class);
}
protected $model = PaymentMethod::class;

/**
* Define the model's default state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ class PaymentTransactionEventFactory extends Factory
/**
* The name of the factory's corresponding model.
*
* @return string
* @var string
*/
public function modelName()
{
return config('payment.models.' . PaymentTransactionEvent::class, PaymentTransactionEvent::class);
}

protected $model = PaymentTransactionEvent::class;

/**
* Define the model's default state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
namespace Payavel\Checkout\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Payavel\Checkout\Models\PaymentMerchant;
use Payavel\Checkout\Models\PaymentProvider;
use Payavel\Checkout\Models\PaymentTransaction;
use Payavel\Checkout\PaymentStatus;
use Payavel\Orchestration\Models\Account;
use Payavel\Orchestration\Models\Provider;

class PaymentTransactionFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @return string
* @var string
*/
public function modelName()
{
return config('payment.models.' . PaymentTransaction::class, PaymentTransaction::class);
}
protected $model = PaymentTransaction::class;

/**
* Define the model's default state.
Expand Down Expand Up @@ -46,29 +43,29 @@ public function configure()
if (is_null($transaction->provider_id)) {
$provider = ! is_null($transaction->payment_method_id)
? $transaction->paymentMethod->provider
: PaymentProvider::whereHas('merchants', function ($query) use ($transaction) {
$query->where('payment_merchants.id', $transaction->merchant_id);
})->inRandomOrder()->firstOr(function () {
return PaymentProvider::factory()->create();
: Provider::whereHas('accounts', function ($query) use ($transaction) {
$query->where('payment_accounts.id', $transaction->account_id);
})->inRandomOrder()->firstOr(function () {
return Provider::factory()->create();
});

$transaction->provider_id = $provider->id;
}

if (is_null($transaction->merchant_id)) {
$merchant = ! is_null($transaction->payment_method_id)
? $transaction->paymentMethod->merchant
: PaymentMerchant::whereHas('providers', function ($query) use ($transaction) {
if (is_null($transaction->account_id)) {
$account = ! is_null($transaction->payment_method_id)
? $transaction->paymentMethod->account
: Account::whereHas('providers', function ($query) use ($transaction) {
$query->where('payment_providers.id', $transaction->provider_id);
})->inRandomOrder()->firstOr(function () use ($transaction) {
$merchant = PaymentMerchant::factory()->create();
$account = Account::factory()->create();

$merchant->providers()->attach($transaction->provider_id, ['is_default' => true]);
$account->providers()->attach($transaction->provider_id, ['is_default' => true]);

return $merchant;
return $account;
});

$transaction->merchant_id = $merchant->id;
$transaction->account_id = $account->id;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ class PaymentTypeFactory extends Factory
/**
* The name of the factory's corresponding model.
*
* @return string
* @var string
*/
public function modelName()
{
return config('payment.models.' . PaymentType::class, PaymentType::class);
}
protected $model = PaymentType::class;

public const DEFAULTS = [
[
Expand Down Expand Up @@ -80,8 +77,7 @@ public function real()
return $this->state(function () {
$type = collect(static::DEFAULTS)->whereNotIn('slug', PaymentType::all()->pluck('slug'))->first();

if (is_null($type))
{
if (is_null($type)) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@
namespace Payavel\Checkout\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Payavel\Checkout\Models\PaymentMerchant;
use Payavel\Checkout\Models\PaymentProvider;
use Payavel\Checkout\Models\Wallet;
use Payavel\Orchestration\Models\Account;
use Payavel\Orchestration\Models\Provider;

class WalletFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @return string
* @var string
*/
public function modelName()
{
return config('payment.models.' . Wallet::class, Wallet::class);
}
protected $model = Wallet::class;

/**
* Define the model's default state.
Expand All @@ -40,27 +37,27 @@ public function configure()
{
return $this->afterMaking(function (Wallet $wallet) {
if (is_null($wallet->provider_id)) {
$provider = PaymentProvider::whereHas('merchants', function ($query) use ($wallet) {
$query->where('payment_merchants.id', $wallet->merchant_id);
$provider = Provider::whereHas('accounts', function ($query) use ($wallet) {
$query->where('payment_accounts.id', $wallet->account_id);
})->inRandomOrder()->firstOr(function () {
return PaymentProvider::factory()->create();
return Provider::factory()->create();
});

$wallet->provider_id = $provider->id;
}

if (is_null($wallet->merchant_id)) {
$merchant = PaymentMerchant::whereHas('providers', function ($query) use ($wallet) {
if (is_null($wallet->account_id)) {
$account = Account::whereHas('providers', function ($query) use ($wallet) {
$query->where('payment_providers.id', $wallet->provider_id);
})->inRandomOrder()->firstOr(function () use ($wallet) {
$merchant = PaymentMerchant::factory()->create();
$account = Account::factory()->create();

$merchant->providers()->attach($wallet->provider_id, ['is_default' => true]);
$account->providers()->attach($wallet->provider_id, ['is_default' => true]);

return $merchant;
return $account;
});

$wallet->merchant_id = $merchant->id;
$wallet->account_id = $account->id;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,17 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Payavel\Orchestration\Support\ServiceConfig;

class CreateBasePaymentTables extends Migration
{
return new class () extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$usingDatabaseDriver = config('payment.defaults.driver') === 'database';

if ($usingDatabaseDriver) {
Schema::create('payment_providers', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->string('request_class');
$table->string('response_class');
$table->timestamps();
});

Schema::create('payment_merchants', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->timestamps();
});

Schema::create('payment_merchant_provider', function (Blueprint $table) {
$table->increments('id');
$table->string('merchant_id');
$table->string('provider_id');
$table->boolean('is_default')->default(false);
$table->json('config')->nullable();
$table->timestamps();

$table->foreign('merchant_id')->references('id')->on('payment_merchants')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('provider_id')->references('id')->on('payment_providers')->onUpdate('cascade')->onDelete('cascade');
});
}
$usingDatabaseDriver = ServiceConfig::get('checkout', 'defaults.driver') === 'database';

Schema::create('payment_types', function (Blueprint $table) {
$table->smallIncrements('id');
Expand All @@ -55,13 +27,13 @@ public function up()
$table->unsignedBigInteger('billable_id')->nullable();
$table->string('billable_type')->nullable();
$table->string('provider_id');
$table->string('merchant_id');
$table->string('account_id');
$table->string('token');
$table->timestamps();

if ($usingDatabaseDriver) {
$table->foreign('provider_id')->references('id')->on('payment_providers')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('merchant_id')->references('id')->on('payment_merchants')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('provider_id')->references('id')->on('providers')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('account_id')->references('id')->on('accounts')->onUpdate('cascade')->onDelete('cascade');
}
});

Expand All @@ -80,7 +52,7 @@ public function up()
Schema::create('payment_transactions', function (Blueprint $table) use ($usingDatabaseDriver) {
$table->bigIncrements('id');
$table->string('provider_id');
$table->string('merchant_id');
$table->string('account_id');
$table->string('reference');
$table->unsignedInteger('amount');
$table->char('currency', 3)->default('USD');
Expand All @@ -90,8 +62,8 @@ public function up()
$table->timestamps();

if ($usingDatabaseDriver) {
$table->foreign('provider_id')->references('id')->on('payment_providers')->onUpdate('cascade')->onDelete('set null');
$table->foreign('merchant_id')->references('id')->on('payment_merchants')->onUpdate('cascade')->onDelete('set null');
$table->foreign('provider_id')->references('id')->on('providers')->onUpdate('cascade')->onDelete('set null');
$table->foreign('account_id')->references('id')->on('accounts')->onUpdate('cascade')->onDelete('set null');
}

$table->foreign('payment_method_id')->references('id')->on('payment_methods')->onDelete('set null');
Expand Down Expand Up @@ -122,8 +94,5 @@ public function down()
Schema::dropIfExists('payment_methods');
Schema::dropIfExists('payment_types');
Schema::dropIfExists('wallets');
Schema::dropIfExists('payment_merchant_provider');
Schema::dropIfExists('payment_merchants');
Schema::dropIfExists('payment_providers');
}
}
};
Loading
Loading