16
16
use App \Models \Invoice \InvoicePayment ;
17
17
use App \Models \Invoice \InvoicePaymentCurrency ;
18
18
use App \Models \Invoice \InvoiceRepositoryInterface ;
19
+ use App \Shared \Exceptions \SignatureVerificationFailed ;
19
20
20
21
class UpdateInvoiceUsingBitPayIpn
21
22
{
@@ -45,7 +46,7 @@ public function __construct(
45
46
$ this ->bitPayConfiguration = $ bitPayConfiguration ;
46
47
}
47
48
48
- public function execute (string $ uuid , array $ data ): void
49
+ public function execute (string $ uuid , array $ data, array $ headers ): void
49
50
{
50
51
$ invoice = $ this ->invoiceRepository ->findOneByUuid ($ uuid );
51
52
if (!$ invoice ) {
@@ -54,18 +55,24 @@ public function execute(string $uuid, array $data): void
54
55
55
56
try {
56
57
$ client = $ this ->bitPayClientFactory ->create ();
58
+
57
59
$ bitPayInvoice = $ client ->getInvoice (
58
60
$ invoice ->getBitpayId (),
59
61
$ this ->bitPayConfiguration ->getFacade (),
60
62
$ this ->bitPayConfiguration ->isSignRequest ()
61
63
);
62
64
63
65
$ updateInvoiceData = $ this ->bitPayUpdateMapper ->execute ($ data )->toArray ();
64
- $ this ->updateInvoiceValidator ->execute ($ data , $ bitPayInvoice );
66
+ $ this ->updateInvoiceValidator ->execute ($ data , $ bitPayInvoice, $ headers );
65
67
66
68
$ this ->updateInvoice ($ invoice , $ updateInvoiceData );
67
69
68
70
$ this ->sendUpdateInvoiceNotification ->execute ($ invoice , $ data ['event ' ] ?? null );
71
+ } catch (SignatureVerificationFailed $ e ) {
72
+ $ this ->logger ->error ('SIGNATURE_VERIFICATION_FAIL ' , $ e ->getMessage (), [
73
+ 'id ' => $ invoice ->id
74
+ ]);
75
+ throw $ e ;
69
76
} catch (\Exception | \TypeError $ e ) {
70
77
$ this ->logger ->error ('INVOICE_UPDATE_FAIL ' , 'Failed to update invoice ' , [
71
78
'id ' => $ invoice ->id
0 commit comments