Created
May 10, 2024 03:57
-
-
Save AhmedHdeawy/be8c19a485c2f958e1922f38c06b1f72 to your computer and use it in GitHub Desktop.
Action for processing a payment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Services\Payment\PaymentDetails; | |
use App\Actions\PaymentAction; | |
use App\Models\Order; | |
class CheckoutController extends Controller | |
{ | |
public function processPayment(Order $order, PaymentDetails $paymentDetails, PaymentAction $paymentAction) | |
{ | |
// Delegate payment processing to PaymentAction | |
$paymentAction($order, $paymentDetails); | |
// Redirect or return response | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Actions; | |
use App\Services\Payment\PaymentGateway; | |
use App\Services\Payment\PaymentDetails; | |
use App\Models\Order; | |
class PaymentAction { | |
public function __construct(protected PaymentGateway $paymentGateway) | |
{ | |
} | |
public function __invoke(Order $order, PaymentDetails $paymentDetails) | |
{ | |
// Process payment using the injected payment gateway | |
$this->paymentGateway->process($order, $paymentDetails); | |
// Update order status, send email notifications, etc. | |
$order->update(['status' => 'paid']); | |
// Additional logic... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment