Skip to content

Commit

Permalink
Merge branch '1.x' of https://github.com/payavel/checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Apr 27, 2023
2 parents 27fe94d + f9ad819 commit b8e3dfb
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ assignees: ''
### **Describe the bug.** :bug:
🟩 Is it green? 🦵 How many legs does it have? ☠️ Is it poisonous?

### **Which version(s) should this be pointed at?**
Keep in mind, it could be a bug for one but a feature of another.

### **Is this bug related to any existing issues?** :link:
Link any issues this could possibly be related to.
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ A description of what the problem this would solve.
### **Additional context** :speech_balloon:
Add any other context or screenshots about the enhancement here.

### **Which version(s) should this be pointed at?**
Determine if this should be released in the next minor or major version.

### **Is this request related to any existing issues?** :link:
Link any issues this could possibly be related to.
3 changes: 0 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
### **What does this PR do?** :robot:
Provide a description of the problems and/or bugs this will solve.

### **Where should the reviewer start?** :round_pushpin:
Provide a good starting point for the reviewer to act as the end-user and replicate the scenario.

### **How should this be tested?** :microscope:
Provide all the details on how this should be tested step by step.

Expand Down
8 changes: 6 additions & 2 deletions src/Drivers/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class DatabaseDriver extends PaymentServiceDriver
public function resolveProvider($provider)
{
if (! $provider instanceof PaymentProvider) {
$provider = PaymentProvider::find($provider);
$paymentProvider = config('payment.models.' . PaymentProvider::class, PaymentProvider::class);

$provider = $paymentProvider::find($provider);
}

if (is_null($provider) || (! $provider->exists)) {
Expand Down Expand Up @@ -52,7 +54,9 @@ public function getDefaultProvider(Merchantable $merchant = null)
public function resolveMerchant($merchant)
{
if (! $merchant instanceof PaymentMerchant) {
$merchant = PaymentMerchant::find($merchant);
$paymentMerchant = config('payment.models.' . PaymentMerchant::class, PaymentMerchant::class);

$merchant = $paymentMerchant::find($merchant);
}

if (is_null($merchant) || (! $merchant->exists)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ trait Billable
*/
public function wallets()
{
return $this->morphMany(Wallet::class, 'billable');
return $this->morphMany(config('payment.models.' . Wallet::class, Wallet::class), 'billable');
}
}
36 changes: 0 additions & 36 deletions tests/GatewayTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace Payavel\Checkout\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Payavel\Checkout\Contracts\Billable;
use Payavel\Checkout\Models\PaymentMerchant;
Expand All @@ -16,7 +12,6 @@
use Payavel\Checkout\PaymentRequest;
use Payavel\Checkout\PaymentResponse;
use Payavel\Checkout\PaymentStatus;
use Payavel\Checkout\Traits\Billable as BillableTrait;

abstract class GatewayTestCase extends TestCase
{
Expand All @@ -34,13 +29,6 @@ protected function setUp(): void
parent::setUp();

$this->{"{$this->driver}DriverSetUp"}();

Schema::create('users', function ($table) {
$table->id();
$table->string('email')->unique();
$table->string('password');
$table->timestamps();
});
}

protected function getEnvironmentSetUp($app)
Expand Down Expand Up @@ -274,27 +262,3 @@ public function getStatusCode()
return PaymentStatus::DECLINED;
}
}

class User extends Model implements Billable
{
use BillableTrait,
HasFactory;

protected static function newFactory()
{
return UserFactory::new();
}
}

class UserFactory extends Factory
{
protected $model = User::class;

public function definition()
{
return [
'email' => $this->faker->email(),
'password' => $this->faker->password(),
];
}
}
47 changes: 47 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

namespace Payavel\Checkout\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Schema;
use Payavel\Checkout\Contracts\Billable;
use Payavel\Checkout\PaymentServiceProvider;
use Payavel\Checkout\Traits\Billable as BillableTrait;

abstract class TestCase extends \Orchestra\Testbench\TestCase
{
Expand Down Expand Up @@ -39,4 +45,45 @@ protected function afterRefreshingDatabase()
$this->artisan('migrate');
}
}

/**
* Setup the test environment.
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();

Schema::create('users', function ($table) {
$table->id();
$table->string('email')->unique();
$table->string('password');
$table->timestamps();
});
}
}

class User extends Model implements Billable
{
use BillableTrait,
HasFactory;

protected static function newFactory()
{
return UserFactory::new();
}
}

class UserFactory extends Factory
{
protected $model = User::class;

public function definition()
{
return [
'email' => $this->faker->email(),
'password' => $this->faker->password(),
];
}
}
52 changes: 52 additions & 0 deletions tests/Unit/BillableTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Payavel\Checkout\Tests\Unit;

use Illuminate\Support\Facades\Config;
use Payavel\Checkout\Models\Wallet as WalletModel;
use Payavel\Checkout\Tests\TestCase;
use Payavel\Checkout\Tests\User;

class BillableTraitTest extends TestCase
{
/**
* Setup the test environment.
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();

$this->artisan('vendor:publish', [
'--provider' => 'Payavel\\Checkout\\PaymentServiceProvider',
'--tag' => 'payavel-migrations'
]);

$this->artisan('migrate');
}

/** @test */
public function retrieve_billable_wallets()
{
Config::set('payment.models.' . WalletModel::class, Wallet::class);

$billable = User::factory()
->hasWallets(
$totalWallets = rand(1, 3),
['provider_id' => 'fake', 'merchant_id' => 'faker']
)
->create();

$this->assertCount($totalWallets, $billable->wallets);

$billable->wallets->each(function ($wallet) {
$this->assertTrue($wallet->isLocalModel);
});
}
}

class Wallet extends WalletModel
{
public $isLocalModel = true;
}

0 comments on commit b8e3dfb

Please sign in to comment.