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] Fix bug in tests. #61

Merged
merged 23 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions database/factories/PaymentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ public function configure()
return $this->afterMaking(function (Payment $payment) {
if (is_null($payment->provider_id)) {
$provider = ! is_null($payment->instrument_id)
? $payment->instrument->provider
? $payment->instrument->wallet->getProvider()
: Provider::whereHas(
'accounts',
fn ($query) => $query->where('accounts.id', $payment->account_id)
)->inRandomOrder()->firstOr(
fn () => Provider::factory()->create()
);

$payment->provider_id = $provider->id;
$payment->provider_id = $provider->getId();
}

if (is_null($payment->account_id)) {
$account = ! is_null($payment->instrument_id)
? $payment->instrument->account
? $payment->instrument->wallet->getAccount()
: Account::whereHas(
'providers',
fn ($query) => $query->where('providers.id', $payment->provider_id)
Expand All @@ -67,7 +67,7 @@ public function configure()
return $account;
});

$payment->account_id = $account->id;
$payment->account_id = $account->getId();
}

if (is_null($payment->rail_id)) {
Expand Down
2 changes: 1 addition & 1 deletion database/factories/TransactionEventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function configure()

return $this->afterMaking(function (TransactionEvent $transactionEvent) {
if (is_null($transactionEvent->payment_id)) {
$transactionEvent->payment_id = Payment::factory()->create()->id;
$transactionEvent->payment_id = $transactionEvent->transactionable_type === Payment::class ? $transactionEvent->transactionable_id : Payment::factory()->create()->id;
}

if (is_null($transactionEvent->amount)) {
Expand Down
20 changes: 0 additions & 20 deletions src/Models/Dispute.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,6 @@ protected static function getFactoryNamespace()
return 'Payavel\\Checkout\\Database\\Factories';
}

/**
* Get the dispute's provider.
*
* @return \Payavel\Orchestration\Models\Provider
*/
public function getProviderAttribute()
{
return $this->payment->provider;
}

/**
* Get the dispute's account.
*
* @return \Payavel\Orchestration\Models\Account
*/
public function getAccountAttribute()
{
return $this->payment->account;
}

/**
* Get the payment that is being disputed.
*
Expand Down
20 changes: 14 additions & 6 deletions src/Models/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace Payavel\Checkout\Models;

use Illuminate\Database\Eloquent\Model;
use Payavel\Checkout\Traits\ConfiguresCheckoutGateway;
use Payavel\Orchestration\Contracts\Orchestrable;
use Payavel\Orchestration\Models\Account;
use Payavel\Orchestration\Models\Provider;
use Payavel\Orchestration\Support\ServiceConfig;
use Payavel\Orchestration\Traits\OrchestratesService;
use Payavel\Orchestration\Traits\HasFactory;

class Payment extends Model
class Payment extends Model implements Orchestrable
{
use ConfiguresCheckoutGateway;
use HasFactory;
use OrchestratesService;

/**
* The attributes that aren't mass assignable.
Expand All @@ -39,6 +40,13 @@
'details' => 'array',
];

/**
* The orchestra's service id.
*
* @var string
*/
protected $serviceId = 'checkout';

/**
* Custom factory namespace fallback.
*
Expand Down Expand Up @@ -116,7 +124,7 @@
*/
public function fetch()
{
return $this->gateway->getTransaction($this);
return $this->service->getTransaction($this);

Check warning on line 127 in src/Models/Payment.php

View check run for this annotation

Codecov / codecov/patch

src/Models/Payment.php#L127

Added line #L127 was not covered by tests
}

/**
Expand All @@ -127,7 +135,7 @@
*/
public function void($data = [])
{
return $this->gateway->void($this, $data);
return $this->service->void($this, $data);

Check warning on line 138 in src/Models/Payment.php

View check run for this annotation

Codecov / codecov/patch

src/Models/Payment.php#L138

Added line #L138 was not covered by tests
}

/**
Expand All @@ -138,6 +146,6 @@
*/
public function refund($data = [])
{
return $this->gateway->refund($this, $data);
return $this->service->refund($this, $data);

Check warning on line 149 in src/Models/Payment.php

View check run for this annotation

Codecov / codecov/patch

src/Models/Payment.php#L149

Added line #L149 was not covered by tests
}
}
28 changes: 3 additions & 25 deletions src/Models/PaymentInstrument.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace Payavel\Checkout\Models;

use Illuminate\Database\Eloquent\Model;
use Payavel\Checkout\Traits\ConfiguresCheckoutGateway;
use Payavel\Orchestration\Support\ServiceConfig;
use Payavel\Orchestration\Traits\HasFactory;

class PaymentInstrument extends Model
{
use ConfiguresCheckoutGateway;
use HasFactory;

/**
Expand Down Expand Up @@ -48,26 +46,6 @@
return 'Payavel\\Checkout\\Database\\Factories';
}

/**
* Get the payment instrument's provider.
*
* @return \Payavel\Orchestration\Models\Provider
*/
public function getProviderAttribute()
{
return $this->wallet->provider;
}

/**
* Get the payment instrument's account.
*
* @return \Payavel\Orchestration\Models\Account
*/
public function getAccountAttribute()
{
return $this->wallet->account;
}

/**
* Get the wallet the payment instrument belongs to.
*
Expand Down Expand Up @@ -105,7 +83,7 @@
*/
public function fetch()
{
return $this->gateway->getPaymentInstrument($this);
return $this->wallet->service->getPaymentInstrument($this);

Check warning on line 86 in src/Models/PaymentInstrument.php

View check run for this annotation

Codecov / codecov/patch

src/Models/PaymentInstrument.php#L86

Added line #L86 was not covered by tests
}

/**
Expand All @@ -116,7 +94,7 @@
*/
public function patch($data)
{
return $this->gateway->updatePaymentInstrument($this, $data);
return $this->wallet->service->updatePaymentInstrument($this, $data);

Check warning on line 97 in src/Models/PaymentInstrument.php

View check run for this annotation

Codecov / codecov/patch

src/Models/PaymentInstrument.php#L97

Added line #L97 was not covered by tests
}

/**
Expand All @@ -126,6 +104,6 @@
*/
public function disable()
{
return $this->gateway->deletePaymentInstrument($this);
return $this->wallet->service->deletePaymentInstrument($this);

Check warning on line 107 in src/Models/PaymentInstrument.php

View check run for this annotation

Codecov / codecov/patch

src/Models/PaymentInstrument.php#L107

Added line #L107 was not covered by tests
}
}
20 changes: 0 additions & 20 deletions src/Models/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,6 @@ protected static function getFactoryNamespace()
return 'Payavel\\Checkout\\Database\\Factories';
}

/**
* Get the refund's provider.
*
* @return \Payavel\Orchestration\Models\Provider
*/
public function getProviderAttribute()
{
return $this->payment->provider;
}

/**
* Get the refund's account.
*
* @return \Payavel\Orchestration\Models\Account
*/
public function getAccountAttribute()
{
return $this->payment->account;
}

/**
* Get the payment that is being refunded.
*
Expand Down
16 changes: 12 additions & 4 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace Payavel\Checkout\Models;

use Illuminate\Database\Eloquent\Model;
use Payavel\Checkout\Traits\ConfiguresCheckoutGateway;
use Payavel\Orchestration\Contracts\Orchestrable;
use Payavel\Orchestration\Traits\OrchestratesService;
use Payavel\Orchestration\Models\Account;
use Payavel\Orchestration\Models\Provider;
use Payavel\Orchestration\Support\ServiceConfig;
use Payavel\Orchestration\Traits\HasFactory;

class Wallet extends Model
class Wallet extends Model implements Orchestrable
{
use ConfiguresCheckoutGateway;
use HasFactory;
use OrchestratesService;

/**
* The attributes that aren't mass assignable.
Expand All @@ -28,6 +29,13 @@
*/
protected $hidden = ['reference'];

/**
* The orchestra's service id.
*
* @var string
*/
protected $serviceId = 'checkout';

/**
* Custom factory namespace fallback.
*
Expand Down Expand Up @@ -85,6 +93,6 @@
*/
public function fetch()
{
return $this->gateway->getWallet($this);
return $this->service->getWallet($this);

Check warning on line 96 in src/Models/Wallet.php

View check run for this annotation

Codecov / codecov/patch

src/Models/Wallet.php#L96

Added line #L96 was not covered by tests
}
}
31 changes: 0 additions & 31 deletions src/Traits/ConfiguresCheckoutGateway.php

This file was deleted.

37 changes: 0 additions & 37 deletions tests/Unit/BillableTraitTest.php

This file was deleted.

13 changes: 13 additions & 0 deletions tests/Unit/Config/BillableTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Payavel\Checkout\Tests\Unit\Config;

use Payavel\Checkout\Tests\Unit\TestBillableTrait;
use Payavel\Orchestration\Tests\Traits\CreatesConfigServiceables;
use Payavel\Orchestration\Tests\Traits\SetsConfigDriver;

class BillableTraitTest extends TestBillableTrait
{
use CreatesConfigServiceables;
use SetsConfigDriver;
}
13 changes: 13 additions & 0 deletions tests/Unit/Config/CheckoutGatewayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Payavel\Checkout\Tests\Unit\Config;

use Payavel\Checkout\Tests\Unit\TestCheckoutGateway;
use Payavel\Orchestration\Tests\Traits\CreatesConfigServiceables;
use Payavel\Orchestration\Tests\Traits\SetsConfigDriver;

class CheckoutGatewayTest extends TestCheckoutGateway
{
use CreatesConfigServiceables;
use SetsConfigDriver;
}
13 changes: 13 additions & 0 deletions tests/Unit/Config/DisputeModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Payavel\Checkout\Tests\Unit\Config;

use Payavel\Checkout\Tests\Unit\TestDisputeModel;
use Payavel\Orchestration\Tests\Traits\CreatesConfigServiceables;
use Payavel\Orchestration\Tests\Traits\SetsConfigDriver;

class DisputeModelTest extends TestDisputeModel
{
use CreatesConfigServiceables;
use SetsConfigDriver;
}
13 changes: 13 additions & 0 deletions tests/Unit/Config/PaymentInstrumentModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Payavel\Checkout\Tests\Unit\Config;

use Payavel\Checkout\Tests\Unit\TestPaymentInstrumentModel;
use Payavel\Orchestration\Tests\Traits\CreatesConfigServiceables;
use Payavel\Orchestration\Tests\Traits\SetsConfigDriver;

class PaymentInstrumentModelTest extends TestPaymentInstrumentModel
{
use CreatesConfigServiceables;
use SetsConfigDriver;
}
Loading
Loading