Refactor Blockonomics payment handling to improve transaction reference uniqueness and update payment retrieval logic
This commit is contained in:
parent
d080f6db11
commit
e2c07c52c8
|
|
@ -144,19 +144,21 @@ class Blockonomics implements LivewireMethodInterface
|
|||
|
||||
try {
|
||||
$data = [];
|
||||
$fiat_amount = round(($request->btc_price * $request->btc_amount), 2) / 100000000;
|
||||
$fiat_amount = round(($request->btc_price * $request->btc_amount / 100000000), 2);
|
||||
$data['amount'] = $fiat_amount;
|
||||
$data['payment_method_id'] = $request->payment_method_id;
|
||||
$data['payment_type'] = PaymentType::CRYPTO;
|
||||
$data['gateway_type_id'] = GatewayType::CRYPTO;
|
||||
// Randomize the transaction reference if the txid is a test payment
|
||||
// to avoid duplicate transaction references in the database.
|
||||
// Otherwise the payment hashed_id will not be unique.
|
||||
if ($request->txid == 'WarningThisIsAGeneratedTestPaymentAndNotARealBitcoinTransaction') {
|
||||
$data['transaction_reference'] = $request->txid . bin2hex(random_bytes(16));
|
||||
} else {
|
||||
$data['transaction_reference'] = $request->txid;
|
||||
}
|
||||
|
||||
|
||||
define('TEST_TXID', 'WarningThisIsAGeneratedTestPaymentAndNotARealBitcoinTransaction');
|
||||
// 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.
|
||||
$data['transaction_reference'] = ($request->txid === TEST_TXID)
|
||||
? $request->txid . bin2hex(random_bytes(16))
|
||||
: $request->txid;
|
||||
|
||||
$statusId;
|
||||
|
||||
switch ($request->status) {
|
||||
|
|
@ -174,7 +176,8 @@ class Blockonomics implements LivewireMethodInterface
|
|||
}
|
||||
|
||||
$payment = $this->blockonomics->createPayment($data, $statusId);
|
||||
$payment->custom_value1 = $request->btc_address;
|
||||
$payment->custom_value1 = $request->txid;
|
||||
$payment->custom_value2 = $request->btc_address;
|
||||
$payment->save();
|
||||
|
||||
SystemLogger::dispatch(
|
||||
|
|
|
|||
|
|
@ -108,7 +108,8 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||
|
||||
$payment = Payment::query()
|
||||
->where('company_id', $company->id)
|
||||
->where('transaction_reference', $txid)
|
||||
->where('custom_value1', $txid)
|
||||
->where('custom_value2', $addr)
|
||||
->firstOrFail();
|
||||
|
||||
// Already completed payment, no need to update status
|
||||
|
|
|
|||
Loading…
Reference in New Issue