Refactor Blockonomics payment handling to use instance variable for test transaction ID and update payment retrieval logic
This commit is contained in:
parent
b8c3049886
commit
5ef9b2c2d3
|
|
@ -29,7 +29,7 @@ use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
|||
class Blockonomics implements LivewireMethodInterface
|
||||
{
|
||||
use MakesHash;
|
||||
private const TEST_TXID = 'WarningThisIsAGeneratedTestPaymentAndNotARealBitcoinTransaction';
|
||||
private string $test_txid = 'WarningThisIsAGeneratedTestPaymentAndNotARealBitcoinTransaction';
|
||||
|
||||
public function __construct(public BlockonomicsPaymentDriver $blockonomics)
|
||||
{
|
||||
|
|
@ -47,12 +47,6 @@ class Blockonomics implements LivewireMethodInterface
|
|||
{
|
||||
}
|
||||
|
||||
public static function getTestTxid()
|
||||
{
|
||||
return self::TEST_TXID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getBTCAddress(): array
|
||||
{
|
||||
|
|
@ -160,7 +154,7 @@ class Blockonomics implements LivewireMethodInterface
|
|||
// Append a random value to the transaction reference for test payments
|
||||
// to prevent duplicate entries in the database.
|
||||
// This ensures the payment hashed_id remains unique.
|
||||
$testTxid = $this->getTestTxid();
|
||||
$testTxid = $this->test_txid;
|
||||
$data['transaction_reference'] = ($request->txid === $testTxid)
|
||||
? $request->txid . bin2hex(random_bytes(16))
|
||||
: $request->txid;
|
||||
|
|
@ -182,9 +176,7 @@ class Blockonomics implements LivewireMethodInterface
|
|||
}
|
||||
|
||||
$payment = $this->blockonomics->createPayment($data, $statusId);
|
||||
$payment->custom_value1 = $request->txid;
|
||||
$payment->custom_value2 = $request->btc_address;
|
||||
$payment->custom_value3 = $request->btc_amount;
|
||||
$payment->private_notes = "{$request->btc_address} - {$request->btc_amount}";
|
||||
$payment->save();
|
||||
|
||||
SystemLogger::dispatch(
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||
public $NEW_ADDRESS_URL = 'https://www.blockonomics.co/api/new_address';
|
||||
public $PRICE_URL = 'https://www.blockonomics.co/api/price';
|
||||
public $STORES_URL = 'https://www.blockonomics.co/api/v2/stores';
|
||||
private string $test_txid = 'WarningThisIsAGeneratedTestPaymentAndNotARealBitcoinTransaction';
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
|
@ -106,13 +107,10 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||
$status = $request->status;
|
||||
$addr = $request->addr;
|
||||
|
||||
$test_txid = Blockonomics::getTestTxid();
|
||||
|
||||
if ($txid === $test_txid) {
|
||||
if ($txid === $this->test_txid) {
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('custom_value1', $txid)
|
||||
->where('custom_value2', $addr)
|
||||
->where('private_notes', "$addr - $value")
|
||||
->firstOrFail();
|
||||
} else {
|
||||
$payment = Payment::query()
|
||||
|
|
|
|||
Loading…
Reference in New Issue