concretecms-community-store / community_store

An open, free and community developed eCommerce system for Concrete CMS
https://concretecms-community-store.github.io/community_store/
MIT License
106 stars 66 forks source link

Add dashboard page to list details of payments? #877

Closed mlocati closed 1 month ago

mlocati commented 1 month ago

I developed two payment methods (this and this) that store the details of the payment messages associated to every order (e.g. the data sent to the payment servers and the data received back from them).

At the moment, the only way to check these messages is by accessing the database directly.

What about adding to Community Store a new dashboard page where users can see the details of such messages?

I was thinking about something like this:

  1. in the on_start method of packages providing payment methods, we could introduce some code like this:

    use Concrete\Package\CommunityStore\Src\CommunityStore\Payment\LogProviderFactory;
    
    public funciton on_start()
    {
       $this->app->extend(LogProviderFactory::class, function(LogProviderFactory $factory) {
           $factory->registerProvider($this->app->make(ThisPaymentMethodLogProvider::class));
           return $factory;
       });
    }
  2. the new dashboard page would query the registered log providers, displaying the details of the messages (by date or for a specific order)
  3. in the details page of an order, we could add a link to that new dashboard page, passing it the order we want the log for

If that's ok, I can create a pull request that implements this new feature.

mlocati commented 1 month ago

The log providers could implement an interface like this:

<?php

declare(strict_types=1);

namespace Concrete\Package\CommunityStore\Src\CommunityStore\Payment;

use Concrete\Package\CommunityStore\Src\CommunityStore\Order\Order;
use DateTimeInterface;

interface LogProvider
{
    /**
     * Get the handle that uniquely identifies this log provider.
     */
    public function getHandle(): string;

    /**
     * Get the display name of this log provider.
     */
    public function getName(): string;

    /**
     * Find the log entries in the specified date/time range.
     *
     * @return \Concrete\Package\CommunityStore\Src\CommunityStore\Payment\LogEntry[]
     */
    public function findByDate(DateTimeInterface $from, DateTimeInterface $to): array;

    /**
     * Find the log entries associated to a specific order.
     *
     * @return \Concrete\Package\CommunityStore\Src\CommunityStore\Payment\LogEntry[]
     */
    public function findByOrder(Order $order): array;
}
Mesuva commented 1 month ago

Is the main benefit of this that it's a different log 'channel'? Im just looking to understand why we'd use this, and not just standard logs.

mlocati commented 1 month ago

It'd be rather hard to find order-specific entries in the standard logs...

Mesuva commented 1 month ago

That makes sense. Would you then suggest that once this is place that all payment gateways should be adjusted to work with logs the same way?

mlocati commented 1 month ago

That's just an opt-in feature, which requires that the payment gateways store the data of each step.

Of course that'd be nice.

And here's an example of a session of the code I'm developing:

Mesuva commented 1 month ago

That's very cool - I see what you're looking to do here. With there being so many different ways that payment gateways work, each one has their own quirks and sometimes fiddly ways to debug.

mlocati commented 1 month ago

And here it is: #878