Skip to content

Commit

Permalink
Use Service over PaymentService
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Aug 17, 2023
1 parent 6f7dacd commit 7994117
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 230 deletions.
3 changes: 2 additions & 1 deletion src/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
use Payavel\Checkout\Models\PaymentMethod;
use Payavel\Checkout\Models\PaymentTransaction;
use Payavel\Checkout\Models\Wallet;
use Payavel\Serviceable\Service;

class PaymentGateway extends PaymentService implements PaymentRequestor
class PaymentGateway extends Service implements PaymentRequestor
{
/**
* Retrieve the wallet's details from the provider.
Expand Down
220 changes: 0 additions & 220 deletions src/PaymentService.php

This file was deleted.

4 changes: 3 additions & 1 deletion src/PaymentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Payavel\Checkout;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use Payavel\Checkout\Console\Commands\Install;
use Payavel\Checkout\Console\Commands\MakeProvider;
use Payavel\Serviceable\Service;

class PaymentServiceProvider extends ServiceProvider
{
Expand All @@ -24,7 +26,7 @@ public function boot()
public function register()
{
$this->app->singleton(PaymentGateway::class, function ($app) {
return new PaymentGateway();
return new PaymentGateway(Service::find('checkout'));
});

$this->mergeConfigFrom(
Expand Down
29 changes: 21 additions & 8 deletions tests/GatewayTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Payavel\Checkout\PaymentStatus;
use Payavel\Serviceable\Models\Merchant;
use Payavel\Serviceable\Models\Provider;
use Payavel\Serviceable\Models\Service;

abstract class GatewayTestCase extends TestCase
{
Expand All @@ -35,10 +36,17 @@ protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);

$app['config']->set('payment.defaults', [
'driver' => $this->driver,
'provider' => $this->provider,
'merchant' => $this->merchant,
config([
'serviceable.defaults.driver' => $this->driver,
'serviceable.services.checkout' => [
'name' => 'Checkout',
'config' => 'payment',
],
'payment.defaults' => [
'driver' => $this->driver,
'provider' => $this->provider,
'merchant' => $this->merchant,
],
]);
}

Expand Down Expand Up @@ -77,9 +85,14 @@ protected function configDriverSetUp()

protected function databaseDriverSetUp()
{
$provider = PaymentProvider::create([
$service = Service::create([
'id' => 'checkout',
'name' => 'Checkout',
]);

$provider = Provider::create([
'id' => $this->provider,
'service_id' => $service->id,
'name' => Str::headline($this->provider),
'request_class' => TestPaymentRequest::class,
'response_class' => TestPaymentResponse::class,
Expand All @@ -90,11 +103,11 @@ protected function databaseDriverSetUp()
'name' => 'Tester',
]);

$merchant->providers()->attach($provider->id, ['is_default' => true]);
$merchant->providers()->attach($provider->id, ['default' => true]);

$alternativeProvider = PaymentProvider::create([
$alternativeProvider = Provider::create([
'id' => 'alternative',
'service_id' => $service->id,
'name' => 'Alternative',
'request_class' => AlternativePaymentRequest::class,
'response_class' => AlternativePaymentResponse::class,
Expand All @@ -105,7 +118,7 @@ protected function databaseDriverSetUp()
'name' => 'Alternate',
]);

$alternateMerchant->providers()->attach($alternativeProvider->id, ['is_default' => true]);
$alternateMerchant->providers()->attach($alternativeProvider->id, ['default' => true]);
$alternateMerchant->providers()->attach($provider->id);

}
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Payavel\Checkout\Contracts\Billable;
use Payavel\Checkout\PaymentServiceProvider;
use Payavel\Checkout\Traits\Billable as BillableTrait;
use Payavel\Serviceable\ServiceableServiceProvider;

abstract class TestCase extends \Orchestra\Testbench\TestCase
{
Expand All @@ -19,6 +20,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
protected function getPackageProviders($app)
{
return [
ServiceableServiceProvider::class,
PaymentServiceProvider::class,
];
}
Expand Down

0 comments on commit 7994117

Please sign in to comment.