Skip to content

Commit

Permalink
Rename merchant to account
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Apr 15, 2024
1 parent 9d3f54d commit b52af0b
Show file tree
Hide file tree
Showing 17 changed files with 130 additions and 130 deletions.
24 changes: 12 additions & 12 deletions database/factories/PaymentTransactionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Factories\Factory;
use Payavel\Checkout\Models\PaymentTransaction;
use Payavel\Checkout\PaymentStatus;
use Payavel\Orchestration\Models\Merchant;
use Payavel\Orchestration\Models\Account;
use Payavel\Orchestration\Models\Provider;

class PaymentTransactionFactory extends Factory
Expand Down Expand Up @@ -46,29 +46,29 @@ public function configure()
if (is_null($transaction->provider_id)) {
$provider = ! is_null($transaction->payment_method_id)
? $transaction->paymentMethod->provider
: Provider::whereHas('merchants', function ($query) use ($transaction) {
$query->where('payment_merchants.id', $transaction->merchant_id);
})->inRandomOrder()->firstOr(function () {
: 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
: Merchant::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 = Merchant::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
18 changes: 9 additions & 9 deletions database/factories/WalletFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

class WalletFactory extends Factory
Expand Down Expand Up @@ -40,27 +40,27 @@ public function configure()
{
return $this->afterMaking(function (Wallet $wallet) {
if (is_null($wallet->provider_id)) {
$provider = Provider::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 Provider::factory()->create();
});

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

if (is_null($wallet->merchant_id)) {
$merchant = Merchant::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 = Merchant::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 @@ -28,13 +28,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('providers')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('merchant_id')->references('id')->on('merchants')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('account_id')->references('id')->on('accounts')->onUpdate('cascade')->onDelete('cascade');
}
});

Expand All @@ -53,7 +53,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 @@ -64,7 +64,7 @@ public function up()

if ($usingDatabaseDriver) {
$table->foreign('provider_id')->references('id')->on('providers')->onUpdate('cascade')->onDelete('set null');
$table->foreign('merchant_id')->references('id')->on('merchants')->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
10 changes: 5 additions & 5 deletions src/Facades/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* @method static \Payavel\Orchestration\Contracts\Providable getProvider()
* @method static void setProvider($provider)
* @method static string|int|\Payavel\Orchestration\Contracts\Providable getDefaultProvider()
* @method static \Payavel\Checkout\PaymentGateway merchant($merchant)
* @method static \Payavel\Orchestration\Contracts\Merchantable getMerchant()
* @method static void setMerchant($merchant, $strict = true)
* @method static \Payavel\Checkout\PaymentGateway account($account)
* @method static \Payavel\Orchestration\Contracts\Accountable getAccount()
* @method static void setAccount($account, $strict = true)
* @method static void reset()
* @method static string|int|\Payavel\Orchestration\Contracts\Merchantable getDefaultMerchant()
* @method static string|int|\Payavel\Orchestration\Contracts\Accountable getDefaultAccount()
* @method static \Payavel\Checkout\PaymentResponse getWallet(\Payavel\Checkout\Models\Wallet $wallet)
* @method static \Payavel\Checkout\PaymentResponse getPaymentMethod(\Payavel\Checkout\Models\PaymentMethod $paymentMethod)
* @method static \Payavel\Checkout\PaymentResponse tokenizePaymentMethod(\Payavel\Checkout\Contracts\Billable $billable, $data)
Expand All @@ -25,7 +25,7 @@
* @method static \Payavel\Checkout\PaymentResponse getTransaction(\Payavel\Checkout\Models\PaymentTransaction $transaction)
* @method static \Payavel\Checkout\PaymentResponse void(\Payavel\Checkout\Models\PaymentTransaction $transaction, $data = [])
* @method static \Payavel\Checkout\PaymentResponse refund(\Payavel\Checkout\Models\PaymentTransaction $transaction, $data = [])
*
*
* @see \Payavel\Checkout\PaymentGateway
*/
class Payment extends Facade
Expand Down
12 changes: 6 additions & 6 deletions src/Models/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

class PaymentMethod extends Model
{
use HasFactory,
PaymentMethodRequests;
use HasFactory;
use PaymentMethodRequests;

/**
* The attributes that aren't mass assignable.
Expand Down Expand Up @@ -59,13 +59,13 @@ public function getProviderAttribute()
}

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

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Models/PaymentTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
use Illuminate\Database\Eloquent\Model;
use Payavel\Checkout\Database\Factories\PaymentTransactionFactory;
use Payavel\Checkout\Models\Traits\PaymentTransactionRequests;
use Payavel\Orchestration\Models\Merchant;
use Payavel\Orchestration\Models\Account;
use Payavel\Orchestration\Models\Provider;

class PaymentTransaction extends Model
{
use HasFactory,
PaymentTransactionRequests;
use HasFactory;
use PaymentTransactionRequests;

/**
* The attributes that aren't mass assignable.
Expand Down Expand Up @@ -70,13 +70,13 @@ public function provider()
}

/**
* Get the merchant the transaction belongs to.
* Get the account the transaction belongs to.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function merchant()
public function account()
{
return $this->belongsTo(config('payment.models.' . Merchant::class, Merchant::class));
return $this->belongsTo(config('payment.models.' . Account::class, Account::class));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Traits/ConfiguresPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ trait ConfiguresPaymentGateway
public function getGatewayAttribute()
{
if (! isset($this->paymentGateway)) {
$this->paymentGateway = (new PaymentGateway)
$this->paymentGateway = (new PaymentGateway())
->provider($this->provider)
->merchant($this->merchant);
->account($this->account);
}

return $this->paymentGateway;
Expand Down
12 changes: 6 additions & 6 deletions src/Models/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
use Illuminate\Database\Eloquent\Model;
use Payavel\Checkout\Database\Factories\WalletFactory;
use Payavel\Checkout\Models\Traits\WalletRequests;
use Payavel\Orchestration\Models\Merchant;
use Payavel\Orchestration\Models\Account;
use Payavel\Orchestration\Models\Provider;

class Wallet extends Model
{
use HasFactory,
WalletRequests;
use HasFactory;
use WalletRequests;

/**
* The attributes that aren't mass assignable.
Expand Down Expand Up @@ -59,13 +59,13 @@ public function provider()
}

/**
* Get the merchant the wallet belongs to.
* Get the account the wallet belongs to.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function merchant()
public function account()
{
return $this->belongsTo(config('payment.models.' . Merchant::class, Merchant::class));
return $this->belongsTo(config('payment.models.' . Account::class, Account::class));
}

/**
Expand Down
Loading

0 comments on commit b52af0b

Please sign in to comment.