This commit is contained in:
David Bomba 2024-09-19 07:45:00 +10:00
parent 6f7cb38e37
commit 632be20326
2 changed files with 10 additions and 18 deletions

View File

@ -133,6 +133,6 @@ class Blockonomics implements MethodInterface
// Not supported yet // Not supported yet
public function refund(Payment $payment, $amount) public function refund(Payment $payment, $amount)
{ {
return;
} }
} }

View File

@ -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 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 $BASE_URL = 'https://www.blockonomics.co';
public $NEW_ADDRESS_URL = 'https://www.blockonomics.co/api/new_address'; public $NEW_ADDRESS_URL = 'https://www.blockonomics.co/api/new_address';
public $PRICE_URL = 'https://www.blockonomics.co/api/price'; public $PRICE_URL = 'https://www.blockonomics.co/api/price';
public $api_key; public $api_key;
public $callback_url;
public $callback_secret; public $callback_secret;
public function init() public function init()
{ {
$this->api_key = $this->company_gateway->getConfigField('apiKey'); $this->api_key = $this->company_gateway->getConfigField('apiKey');
$this->callback_url = $this->company_gateway->getConfigField('callbackUrl');
$this->callback_secret = $this->company_gateway->getConfigField('callbackSecret'); $this->callback_secret = $this->company_gateway->getConfigField('callbackSecret');
return $this; /* This is where you boot the gateway with your auth credentials*/ 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 */ /* Returns an array of gateway types for the payment gateway */
public function gatewayTypes(): array public function gatewayTypes(): array
{ {
@ -103,14 +93,14 @@ class BlockonomicsPaymentDriver extends BaseDriver
public function processWebhookRequest(PaymentWebhookRequest $request) public function processWebhookRequest(PaymentWebhookRequest $request)
{ {
nlog($request->all());
$company = $request->getCompany();
$url_callback_secret = $request->secret; $url_callback_secret = $request->secret;
$db_callback_secret = $this->company_gateway->getConfigField('callbackSecret'); $db_callback_secret = $this->company_gateway->getConfigField('callbackSecret');
if ($url_callback_secret != $db_callback_secret) { if ($url_callback_secret != $db_callback_secret) {
throw new PaymentFailed('Secret does not match'); throw new PaymentFailed('Secret does not match');
return;
} }
$txid = $request->txid; $txid = $request->txid;
@ -118,12 +108,18 @@ class BlockonomicsPaymentDriver extends BaseDriver
$status = $request->status; $status = $request->status;
$addr = $request->addr; $addr = $request->addr;
$payment = $this->getPaymentByTxid($txid); $payment = Payment::query()
->where('company_id', $company->id)
->where('transaction_reference', $txid)
->firstOrFail();
if (!$payment) { 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 // 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) { switch ($status) {
case 0: case 0:
$statusId = Payment::STATUS_PENDING; $statusId = Payment::STATUS_PENDING;
@ -138,15 +134,11 @@ class BlockonomicsPaymentDriver extends BaseDriver
if($payment->status_id == $statusId) { if($payment->status_id == $statusId) {
return response()->json([], 200); return response()->json([], 200);
// header('HTTP/1.1 200 OK');
// echo "No change in payment status";
} else { } else {
$payment->status_id = $statusId; $payment->status_id = $statusId;
$payment->save(); $payment->save();
return response()->json([], 200); return response()->json([], 200);
// header('HTTP/1.1 200 OK');
// echo "Payment status updated successfully";
} }
} }