• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-mirakl-connector / 46022462439

27 Nov 2026 03:10PM UTC coverage: 91.289% (+0.4%) from 90.9%
46022462439

Pull #164

github

ruoltean
fix repo flush
Pull Request #164: Bugfix/c 3556/capture payments

204 of 220 new or added lines in 22 files covered. (92.73%)

1 existing line in 1 file now uncovered.

2924 of 3203 relevant lines covered (91.29%)

12.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.74
/src/Handler/ProcessPayoutHandler.php
1
<?php
2

3
namespace App\Handler;
4

5
use App\Entity\StripePayout;
6
use App\Message\ProcessPayoutMessage;
7
use App\Repository\StripePayoutRepository;
8
use App\Service\StripeClient;
9
use Psr\Log\LoggerAwareInterface;
10
use Psr\Log\LoggerAwareTrait;
11
use Stripe\Exception\ApiErrorException;
12
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
13

14
#[AsMessageHandler]
15
class ProcessPayoutHandler implements LoggerAwareInterface
16
{
17
    use LoggerAwareTrait;
18

19
    /**
20
     * @var StripeClient
21
     */
22
    private $stripeClient;
23

24
    /**
25
     * @var StripePayoutRepository
26
     */
27
    private $stripePayoutRepository;
28

29
    public function __construct(
4 ✔
30
        StripeClient $stripeClient,
31
        StripePayoutRepository $stripePayoutRepository
32
    ) {
33
        $this->stripeClient = $stripeClient;
4 ✔
34
        $this->stripePayoutRepository = $stripePayoutRepository;
4 ✔
35
    }
36

37
    public function __invoke(ProcessPayoutMessage $message): void
4 ✔
38
    {
39
        $payout = $this->stripePayoutRepository->findOneBy([
4 ✔
40
            'id' => $message->getStripePayoutId(),
4 ✔
41
        ]);
4 ✔
42
        if (
43
            null === $payout
4 ✔
44
            || StripePayout::PAYOUT_PENDING !== $payout->getStatus()
4 ✔
45
            || null === $payout->getAccountMapping()
4 ✔
46
            || (
47
                null !== $message->getAttempt()
4 ✔
48
                && $message->getAttempt() !== $payout->getStripeRequestAttempt()
4 ✔
49
            )
50
        ) {
51
            $this->logger->info('Ignoring stale or incomplete payout message.', [
2 ✔
52
                'stripe_payout_id' => $message->getStripePayoutId(),
2 ✔
53
                'status' => $payout?->getStatus(),
2 ✔
54
            ]);
2 ✔
55

56
            return;
2 ✔
57
        }
58

59
        if (null !== $payout->getPayoutId()) {
3 ✔
NEW
60
            $payout->setStatus(StripePayout::PAYOUT_CREATED);
×
NEW
61
            $payout->setStatusReason(null);
×
NEW
62
            $this->stripePayoutRepository->flush();
×
63

NEW
64
            return;
×
65
        }
66

67
        $accountMapping = $payout->getAccountMapping();
3 ✔
68
        try {
69
            $response = $this->stripeClient->createPayout(
3 ✔
70
                (string) $payout->getCurrency(),
3 ✔
71
                (int) $payout->getAmount(),
3 ✔
72
                $accountMapping->getStripeAccountId(),
3 ✔
73
                [
3 ✔
74
                    'miraklShopId' => $accountMapping->getMiraklShopId(),
3 ✔
75
                    'invoiceId' => $payout->getMiraklInvoiceId(),
3 ✔
76
                ],
3 ✔
77
                sprintf(
3 ✔
78
                    'mirakl-payout-%s-attempt-%d',
3 ✔
79
                    $payout->getId(),
3 ✔
80
                    $payout->getStripeRequestAttempt()
3 ✔
81
                )
3 ✔
82
            );
3 ✔
83

84
            $payout->setPayoutId($response->id);
1 ✔
85
            $payout->setStatus(StripePayout::PAYOUT_CREATED);
1 ✔
86
            $payout->setStatusReason(null);
1 ✔
87
        } catch (ApiErrorException $e) {
2 ✔
88
            $this->logger->error(
2 ✔
89
                sprintf('Could not create Stripe Payout: %s.', $e->getMessage()),
2 ✔
90
                [
2 ✔
91
                    'miraklShopId' => $accountMapping->getMiraklShopId(),
2 ✔
92
                    'stripePayoutId' => $payout->getMiraklInvoiceId(),
2 ✔
93
                    'stripeErrorCode' => $e->getStripeCode(),
2 ✔
94
                ]
2 ✔
95
            );
2 ✔
96

97
            $payout->setStatus(StripePayout::PAYOUT_FAILED);
2 ✔
98
            $payout->setStatusReason(substr($e->getMessage(), 0, 1024));
2 ✔
99
            if (!$this->stripeClient->isAmbiguousStripeFailure($e)) {
2 ✔
NEW
100
                $payout->startNewStripeRequestAttempt();
×
101
            }
102
        }
103

104
        $this->stripePayoutRepository->flush();
3 ✔
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc