Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Mar 20, 2024
1 parent b73d7db commit fd50ef7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 60 deletions.
40 changes: 1 addition & 39 deletions src/Gateway/CashDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,10 @@

namespace Cone\Bazar\Gateway;

use Cone\Bazar\Models\Order;
use Cone\Bazar\Models\Transaction;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class CashDriver extends Driver
class CashDriver extends ManualDriver
{
/**
* The driver name.
*/
protected string $name = 'cash';

/**
* Process the payment.
*/
public function pay(Order $order, ?float $amount = null, array $attributes = []): Transaction
{
$transaction = parent::pay($order, $amount, array_merge(['key' => Str::random()], $attributes));

$transaction->markAsCompleted();

return $transaction;
}

/**
* Process the refund.
*/
public function refund(Order $order, ?float $amount = null, array $attributes = []): Transaction
{
$transaction = parent::refund($order, $amount, array_merge(['key' => Str::random()], $attributes));

$transaction->markAsCompleted();

return $transaction;
}

/**
* Handle the notification request.
*/
public function handleNotification(Request $request): Response
{
throw new Exception('This payment gateway does not support payment notifications.');
}
}
5 changes: 3 additions & 2 deletions src/Gateway/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Http\Response as HttpResponse;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
use Throwable;

abstract class Driver extends BaseDriver
Expand All @@ -27,15 +28,15 @@ abstract class Driver extends BaseDriver
*/
public function pay(Order $order, ?float $amount = null, array $attributes = []): Transaction
{
return $order->pay($amount, $this->name, $attributes);
return $order->pay($amount, $this->name, array_merge(['key' => Str::random()], $attributes));
}

/**
* Process the refund.
*/
public function refund(Order $order, ?float $amount = null, array $attributes = []): Transaction
{
return $order->refund($amount, $this->name, $attributes);
return $order->refund($amount, $this->name, array_merge(['key' => Str::random()], $attributes));
}

/**
Expand Down
48 changes: 48 additions & 0 deletions src/Gateway/ManualDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Cone\Bazar\Gateway;

use Cone\Bazar\Models\Order;
use Cone\Bazar\Models\Transaction;
use Exception;
use Illuminate\Http\Request;

class ManualDriver extends Driver
{
/**
* The driver name.
*/
protected string $name = 'manual';

/**
* Process the payment.
*/
public function pay(Order $order, ?float $amount = null, array $attributes = []): Transaction
{
$transaction = parent::pay($order, $amount, $attributes);

$transaction->markAsCompleted();

return $transaction;
}

/**
* Process the refund.
*/
public function refund(Order $order, ?float $amount = null, array $attributes = []): Transaction
{
$transaction = parent::refund($order, $amount, $attributes);

$transaction->markAsCompleted();

return $transaction;
}

/**
* Handle the notification request.
*/
public function handleNotification(Request $request): Response
{
throw new Exception('This payment gateway does not support payment notifications.');
}
}
19 changes: 0 additions & 19 deletions src/Gateway/TransferDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace Cone\Bazar\Gateway;

use Cone\Bazar\Models\Order;
use Cone\Bazar\Models\Transaction;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class TransferDriver extends Driver
{
Expand All @@ -15,22 +12,6 @@ class TransferDriver extends Driver
*/
protected string $name = 'transfer';

/**
* {@inheritdoc}
*/
public function pay(Order $order, ?float $amount = null, array $attributes = []): Transaction
{
return parent::pay($order, $amount, array_merge(['key' => Str::random()], $attributes));
}

/**
* {@inheritdoc}
*/
public function refund(Order $order, ?float $amount = null, array $attributes = []): Transaction
{
return parent::refund($order, $amount, array_merge(['key' => Str::random()], $attributes));
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit fd50ef7

Please sign in to comment.