diff --git a/app/PaymentDrivers/Blockonomics/Blockonomics.php b/app/PaymentDrivers/Blockonomics/Blockonomics.php index 1452f72d0ee3..cbf057cc3bcc 100644 --- a/app/PaymentDrivers/Blockonomics/Blockonomics.php +++ b/app/PaymentDrivers/Blockonomics/Blockonomics.php @@ -133,6 +133,6 @@ class Blockonomics implements MethodInterface // Not supported yet public function refund(Payment $payment, $amount) { - + return; } } diff --git a/app/PaymentDrivers/BlockonomicsPaymentDriver.php b/app/PaymentDrivers/BlockonomicsPaymentDriver.php index 6bc00f5dc720..c49256727248 100644 --- a/app/PaymentDrivers/BlockonomicsPaymentDriver.php +++ b/app/PaymentDrivers/BlockonomicsPaymentDriver.php @@ -45,30 +45,20 @@ class BlockonomicsPaymentDriver extends BaseDriver public const SYSTEM_LOG_TYPE = SystemLog::TYPE_CHECKOUT; //define a constant for your gateway ie TYPE_YOUR_CUSTOM_GATEWAY - set the const in the SystemLog model - public $blockonomics; public $BASE_URL = 'https://www.blockonomics.co'; public $NEW_ADDRESS_URL = 'https://www.blockonomics.co/api/new_address'; public $PRICE_URL = 'https://www.blockonomics.co/api/price'; public $api_key; - public $callback_url; public $callback_secret; public function init() { $this->api_key = $this->company_gateway->getConfigField('apiKey'); - $this->callback_url = $this->company_gateway->getConfigField('callbackUrl'); $this->callback_secret = $this->company_gateway->getConfigField('callbackSecret'); return $this; /* This is where you boot the gateway with your auth credentials*/ } - - public function getPaymentByTxid($txid) - { - return Payment::where('transaction_reference', $txid) - ->firstOrFail(); - } - /* Returns an array of gateway types for the payment gateway */ public function gatewayTypes(): array { @@ -103,14 +93,14 @@ class BlockonomicsPaymentDriver extends BaseDriver public function processWebhookRequest(PaymentWebhookRequest $request) { - nlog($request->all()); + $company = $request->getCompany(); + $url_callback_secret = $request->secret; $db_callback_secret = $this->company_gateway->getConfigField('callbackSecret'); if ($url_callback_secret != $db_callback_secret) { throw new PaymentFailed('Secret does not match'); - return; } $txid = $request->txid; @@ -118,12 +108,18 @@ class BlockonomicsPaymentDriver extends BaseDriver $status = $request->status; $addr = $request->addr; - $payment = $this->getPaymentByTxid($txid); + $payment = Payment::query() + ->where('company_id', $company->id) + ->where('transaction_reference', $txid) + ->firstOrFail(); if (!$payment) { + return response()->json([], 200); // TODO: Implement logic to create new payment in case user sends payment to the address after closing the payment page } + $statusId = Payment::STATUS_PENDING; + switch ($status) { case 0: $statusId = Payment::STATUS_PENDING; @@ -138,15 +134,11 @@ class BlockonomicsPaymentDriver extends BaseDriver if($payment->status_id == $statusId) { return response()->json([], 200); - // header('HTTP/1.1 200 OK'); - // echo "No change in payment status"; } else { $payment->status_id = $statusId; $payment->save(); return response()->json([], 200); - // header('HTTP/1.1 200 OK'); - // echo "Payment status updated successfully"; } }