Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
| CodDriver | |
85.71% |
6 / 7 |
|
85.71% |
6 / 7 |
7.14 | |
0.00% |
0 / 1 |
| key | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| label | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| configSchema | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| charge | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| verify | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| refund | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isImplemented | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Services\Payment\Drivers; |
| 4 | |
| 5 | use App\Models\Order; |
| 6 | use App\Models\Payment; |
| 7 | use App\Services\Payment\PaymentResult; |
| 8 | use Illuminate\Http\Request; |
| 9 | |
| 10 | /** |
| 11 | * Cash on Delivery — the only gateway a fresh install has, matching the |
| 12 | * storefront's behaviour before Phase 8 existed: no redirect, no external |
| 13 | * call, the order is just placed with payment collected on delivery. |
| 14 | */ |
| 15 | class CodDriver extends AbstractDriver |
| 16 | { |
| 17 | public function key(): string |
| 18 | { |
| 19 | return 'cod'; |
| 20 | } |
| 21 | |
| 22 | public function label(): string |
| 23 | { |
| 24 | return 'Cash on Delivery'; |
| 25 | } |
| 26 | |
| 27 | public function configSchema(): array |
| 28 | { |
| 29 | return []; // nothing to configure — always available |
| 30 | } |
| 31 | |
| 32 | public function charge(Order $order, array $config): PaymentResult |
| 33 | { |
| 34 | return PaymentResult::pending('Payment due on delivery.'); |
| 35 | } |
| 36 | |
| 37 | public function verify(Request $request, array $config): PaymentResult |
| 38 | { |
| 39 | // COD never redirects off-site, so there's nothing to verify a |
| 40 | // return from — nothing should ever call this for 'cod'. |
| 41 | return PaymentResult::pending(); |
| 42 | } |
| 43 | |
| 44 | public function refund(Payment $payment, float $amount, array $config): bool |
| 45 | { |
| 46 | // A COD refund is a real-world cash handback the operator does |
| 47 | // themselves — the app has nothing to call. Marking it refunded in |
| 48 | // the admin (PaymentController) doesn't need this driver's help. |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | public function isImplemented(): bool |
| 53 | { |
| 54 | return true; |
| 55 | } |
| 56 | } |