Skip to content

Commit

Permalink
refactor(helpers): extract helpers to separate classes because of bad…
Browse files Browse the repository at this point in the history
… support of psr-4 in XenForo
  • Loading branch information
021-projects committed Sep 15, 2024
1 parent 08bbe2c commit 324895c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
11 changes: 11 additions & 0 deletions src/addons/BS/BtcPayProvider/Helpers/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace BS\BtcPayProvider\Helpers;

class Data
{
public static function get(array $arr, mixed $key, mixed $default = null): mixed
{
return $arr[$key] ?? $default;
}
}
13 changes: 6 additions & 7 deletions src/addons/BS/BtcPayProvider/Payment/Concerns/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use BTCPayServer\Client\Invoice;
use XF\Payment\CallbackState;

use function BS\BtcPayProvider\Helpers\data_get;
use BS\BtcPayProvider\Helpers\Data;

trait Webhook
{
Expand All @@ -23,7 +22,7 @@ protected function getWebhookPaymentResult(CallbackState $state): ?int
return CallbackState::PAYMENT_RECEIVED;

case 'InvoicePaymentSettled':
if (! data_get($state->purchaseRequest->extra_data, 'invoiceExpired')) {
if (! Data::get($state->purchaseRequest->extra_data, 'invoiceExpired')) {
$state->logType = 'info';
$state->logMessage = 'Invoice (partial) payment settled.';
return null;
Expand All @@ -40,7 +39,7 @@ protected function getWebhookPaymentResult(CallbackState $state): ?int

case 'InvoiceReceivedPayment':
$state->logType = 'info';
if (data_get($payload, 'afterExpiration')) {
if (Data::get($payload, 'afterExpiration')) {
$state->logMessage = 'Invoice (partial) payment incoming (unconfirmed) after invoice was already expired.';
} else {
$state->logMessage = 'Invoice (partial) payment incoming (unconfirmed). Waiting for settlement.';
Expand All @@ -49,7 +48,7 @@ protected function getWebhookPaymentResult(CallbackState $state): ?int

case 'InvoiceProcessing':
$state->logType = 'info';
if (data_get($payload, 'overPaid')) {
if (Data::get($payload, 'overPaid')) {
$state->logMessage = 'Invoice payment received fully with overpayment, waiting for settlement.';
} else {
$state->logMessage = 'Invoice payment received fully, waiting for settlement.';
Expand All @@ -58,7 +57,7 @@ protected function getWebhookPaymentResult(CallbackState $state): ?int

case 'InvoiceExpired':
$state->logType = 'info';
if (data_get($payload, 'partiallyPaid')) {
if (Data::get($payload, 'partiallyPaid')) {
$state->logMessage = 'Invoice expired but was paid partially, please check.';
} else {
$state->logMessage = 'Invoice expired. No action to take.';
Expand All @@ -68,7 +67,7 @@ protected function getWebhookPaymentResult(CallbackState $state): ?int

case 'InvoiceInvalid':
$state->logType = 'info';
if (data_get($payload, 'manuallyMarked')) {
if (Data::get($payload, 'manuallyMarked')) {
$state->logMessage = 'Invoice manually marked invalid.';
} else {
$state->logMessage = 'Invoice became invalid.';
Expand Down
8 changes: 0 additions & 8 deletions src/addons/BS/BtcPayProvider/helpers.php

This file was deleted.

0 comments on commit 324895c

Please sign in to comment.