Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Lunar transactions to use payment checks DTO #1767

Merged

Conversation

alecritson
Copy link
Collaborator

Currently there isn't a standard way for Lunar to show what payment checks were successful, such as Address checks or Security code checks. Although it does make somewhat of an attempt, due to all payment providers being different it is leading to a lot of false positives.

This PR looks to introduce PaymentChecks and PaymentCheck Data Transfer Objects which allow each payment driver to return what payment checks have taken place, what the message was and whether it was successful.

Usage is via the Transaction model like so:

foreach($transaction->paymentChecks() as $check) {
    $check->successful; // true/false
    $check->message; // Matched
    $check->label; // PostalCode
}

For developers who have implemented their own payment type they will need to implement the getPaymentChecks method and interpret the meta data on the transaction accordingly. If a payment driver doesn't store this information they don't need to do anything since a base method is implements in the AbstractPaymentDriver.

An implementation may look like the following (snippet from Stripe payment driver):

use Lunar\Base\DataTransferObjects\PaymentCheck;
use Lunar\Base\DataTransferObjects\PaymentChecks;

// ...

public function getPaymentChecks(Transaction $transaction): PaymentChecks
{
    $meta = $transaction->meta;

    $checks = new PaymentChecks;

    if (isset($meta['address_line1_check'])) {
        $checks->addCheck(
            new PaymentCheck(
                successful: $meta['address_line1_check'] == 'pass',
                label: 'Address Line 1',
                message: $meta['address_line1_check'],
            )
        );
    }

    // ...

   return $checks;
}

Copy link

vercel bot commented May 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2024 7:31am

@glennjacobs
Copy link
Contributor

@alecritson I think we need an entry in the upgrade docs, as I presume this will be breaking if someone has made their own payment driver?

@glennjacobs
Copy link
Contributor

@alecritson I think we need an entry in the upgrade docs, as I presume this will be breaking if someone has made their own payment driver?

Scrap that, I can see it's on the abstract class. So not needed.

@glennjacobs
Copy link
Contributor

An old test order, but this has a cross but is matched on the security code.

image

@alecritson
Copy link
Collaborator Author

An old test order, but this has a cross but is matched on the security code.

image

This should be patched

@alecritson alecritson merged commit fe6108a into 1.x May 23, 2024
23 checks passed
@alecritson alecritson deleted the lun-70-opayo-transactions-not-showing-correct-information branch May 23, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants