mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
add logic about secrets
This commit is contained in:
parent
34830bc9ab
commit
19e99f300d
@ -18,6 +18,7 @@ use App\Models\GatewayType;
|
|||||||
use App\PaymentDrivers\Blockonomics\Blockonomics;
|
use App\PaymentDrivers\Blockonomics\Blockonomics;
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
use App\Models\Gateway;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Exceptions\PaymentFailed;
|
use App\Exceptions\PaymentFailed;
|
||||||
use App\Models\PaymentType;
|
use App\Models\PaymentType;
|
||||||
@ -54,16 +55,26 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||||||
$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_url = $this->company_gateway->getConfigField('callbackUrl');
|
||||||
$this->callback_secret = $this->company_gateway->getConfigField('callbackSecret');
|
$this->callback_secret = $this->company_gateway->getConfigField('callbackSecret');
|
||||||
// $this->setCallbackUrl();
|
|
||||||
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 findPaymentByTxid($txid)
|
public function getPaymentByTxid($txid)
|
||||||
{
|
{
|
||||||
return Payment::whereRaw('BINARY `transaction_reference` LIKE ?', ["%txid: " . $txid])->firstOrFail();
|
return Payment::whereRaw('BINARY `transaction_reference` LIKE ?', ["%txid: " . $txid])->firstOrFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCallbackSecret()
|
||||||
|
{
|
||||||
|
$blockonomicsGatewayData = Gateway::find(64);
|
||||||
|
$intialData = json_decode($blockonomicsGatewayData, true);
|
||||||
|
$jsonString = $intialData['fields'];
|
||||||
|
$blockonomicsFields = json_decode($jsonString, true);
|
||||||
|
|
||||||
|
// Access the value of callbackSecret
|
||||||
|
$callbackSecret = $blockonomicsFields['callbackSecret'];
|
||||||
|
return $callbackSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Returns an array of gateway types for the payment gateway */
|
/* Returns an array of gateway types for the payment gateway */
|
||||||
@ -95,28 +106,25 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
public function processWebhookRequest()
|
public function processWebhookRequest()
|
||||||
{
|
{
|
||||||
// TODO: Figure out why init does not work
|
|
||||||
$this->init();
|
|
||||||
$secret = $this->callback_secret;
|
|
||||||
//Match secret for security
|
|
||||||
if ($_GET['secret'] != $secret) {
|
|
||||||
echo "Invalid Secret";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$txid = $_GET['txid'];
|
$txid = $_GET['txid'];
|
||||||
$value = $_GET['value'];
|
$value = $_GET['value'];
|
||||||
$status = $_GET['status'];
|
$status = $_GET['status'];
|
||||||
$addr = $_GET['addr'];
|
$addr = $_GET['addr'];
|
||||||
|
|
||||||
|
$payment = $this->getPaymentByTxid($txid);
|
||||||
|
$callbackSecret = $this->getCallbackSecret();
|
||||||
|
|
||||||
|
//Match secret for security
|
||||||
|
if ($_GET['secret'] != $callbackSecret) {
|
||||||
|
throw new PaymentFailed('Secret does not match');
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Only accept confirmed transactions
|
// Only accept confirmed transactions
|
||||||
if ($status != 2) {
|
if ($status != 2) {
|
||||||
throw new PaymentFailed('Transaction not confirmed');
|
throw new PaymentFailed('Transaction not confirmed');
|
||||||
}
|
}
|
||||||
|
|
||||||
$payment = $this->findPaymentByTxid($txid);
|
|
||||||
// $payment_hash = $this->findPaymentHashInTransactionReference($payment->transaction_reference);
|
|
||||||
|
|
||||||
switch ($status) {
|
switch ($status) {
|
||||||
case 0:
|
case 0:
|
||||||
$statusId = Payment::STATUS_PENDING;
|
$statusId = Payment::STATUS_PENDING;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
use App\Http\Controllers\SubscriptionStepsController;
|
use App\Http\Controllers\SubscriptionStepsController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\Gateways\BlockonomicsController;
|
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
use App\Http\Controllers\BrevoController;
|
use App\Http\Controllers\BrevoController;
|
||||||
use App\Http\Controllers\PingController;
|
use App\Http\Controllers\PingController;
|
||||||
@ -99,6 +98,7 @@ use App\Http\Controllers\Reports\ClientReportController;
|
|||||||
use App\Http\Controllers\Reports\CreditReportController;
|
use App\Http\Controllers\Reports\CreditReportController;
|
||||||
use App\Http\Controllers\Reports\ReportExportController;
|
use App\Http\Controllers\Reports\ReportExportController;
|
||||||
use App\Http\Controllers\Reports\VendorReportController;
|
use App\Http\Controllers\Reports\VendorReportController;
|
||||||
|
use App\Http\Controllers\Gateways\BlockonomicsController;
|
||||||
use App\Http\Controllers\Reports\ExpenseReportController;
|
use App\Http\Controllers\Reports\ExpenseReportController;
|
||||||
use App\Http\Controllers\Reports\InvoiceReportController;
|
use App\Http\Controllers\Reports\InvoiceReportController;
|
||||||
use App\Http\Controllers\Reports\PaymentReportController;
|
use App\Http\Controllers\Reports\PaymentReportController;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user