Conditions | 5 |
Paths | 10 |
Total Lines | 18 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
26 | public function handle(BtcpayWebhookReceived $event): void |
||
27 | { |
||
28 | $payload = $event->payload; |
||
29 | if ($payload['event']['code'] === BtcPayConstants::INVOICE_WEBHOOK_CODES) { |
||
30 | // We have received a payment for an invoice and user should be upgraded to a paid plan based on order |
||
31 | try { |
||
32 | $invoice = LaravelBtcpay::getInvoice($payload['data']['id']); |
||
33 | $invoice_status = $invoice->getStatus(); |
||
34 | if ($invoice_status === 'Settled') { |
||
35 | preg_match('/(?P<role>\w+(\+\+)?)[ ](?P<addYears>\d+)/i', $invoice->getData()['metadata']['itemDesc'], $matches); |
||
36 | $user = User::query()->where('email', '=', $invoice->getData()['metadata']['buyerEmail'])->first(); |
||
37 | if ($user) { |
||
38 | User::updateUserRole($user->id, $matches['role']); |
||
39 | User::updateUserRoleChangeDate($user->id, null, $matches['addYears']); |
||
40 | } |
||
41 | } |
||
42 | } catch (BTCPayException $e) { |
||
43 | Log::error($e->getMessage()); |
||
44 | } |
||
48 |