|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace DuncanMcClean\Cargo\Payments\Gateways; |
| 4 | + |
| 5 | +use DuncanMcClean\Cargo\Cargo; |
| 6 | +use DuncanMcClean\Cargo\Contracts\Cart\Cart; |
| 7 | +use DuncanMcClean\Cargo\Contracts\Orders\Order; |
| 8 | +use DuncanMcClean\Cargo\Orders\TimelineEvent; |
| 9 | +use DuncanMcClean\Cargo\Orders\TimelineEventTypes\OrderStatusChanged; |
| 10 | +use DuncanMcClean\Cargo\Support\Money; |
| 11 | +use Illuminate\Http\Request; |
| 12 | +use Illuminate\Http\Response; |
| 13 | + |
| 14 | +class PayOnDelivery extends PaymentGateway |
| 15 | +{ |
| 16 | + protected static $title = 'Pay on delivery'; |
| 17 | + |
| 18 | + public function isAvailable(Cart $cart): bool |
| 19 | + { |
| 20 | + return $cart->shippingOption()?->acceptsPaymentOnDelivery() ?? false; |
| 21 | + } |
| 22 | + |
| 23 | + public function setup(Cart $cart): array |
| 24 | + { |
| 25 | + return []; |
| 26 | + } |
| 27 | + |
| 28 | + public function process(Order $order): void |
| 29 | + { |
| 30 | + // |
| 31 | + } |
| 32 | + |
| 33 | + public function capture(Order $order): void |
| 34 | + { |
| 35 | + // |
| 36 | + } |
| 37 | + |
| 38 | + public function cancel(Cart $cart): void |
| 39 | + { |
| 40 | + // |
| 41 | + } |
| 42 | + |
| 43 | + public function webhook(Request $request): Response |
| 44 | + { |
| 45 | + return response(); |
| 46 | + } |
| 47 | + |
| 48 | + public function refund(Order $order, int $amount): void |
| 49 | + { |
| 50 | + $order->set('amount_refunded', $amount)->save(); |
| 51 | + } |
| 52 | + |
| 53 | + public function logo(): ?string |
| 54 | + { |
| 55 | + return Cargo::svg('cargo-mark'); |
| 56 | + } |
| 57 | + |
| 58 | + public function fieldtypeDetails(Order $order): array |
| 59 | + { |
| 60 | + $paymentReceivedEvent = $order->timelineEvents() |
| 61 | + ->filter(function (TimelineEvent $timelineEvent): bool { |
| 62 | + return get_class($timelineEvent->type()) === OrderStatusChanged::class |
| 63 | + && $timelineEvent->metadata()->get('New Status') === 'payment_received'; |
| 64 | + }) |
| 65 | + ->first(); |
| 66 | + |
| 67 | + return [ |
| 68 | + __('Amount') => Money::format($order->grandTotal(), $order->site()), |
| 69 | + __('Payment Date') => $paymentReceivedEvent |
| 70 | + ? __(':datetime UTC', ['datetime' => $paymentReceivedEvent->datetime()->format('Y-m-d H:i:s')]) |
| 71 | + : __('Awaiting Payment'), |
| 72 | + ]; |
| 73 | + } |
| 74 | +} |
0 commit comments