Merge pull request #10785 from cnohall/improve-blockonomics-health-check-messages
Improve Blockonomics Health Checkup Message
This commit is contained in:
commit
aaf1daed19
|
|
@ -49,6 +49,7 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
||||||
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 $STORES_URL = 'https://www.blockonomics.co/api/v2/stores';
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
|
|
@ -146,17 +147,89 @@ class BlockonomicsPaymentDriver extends BaseDriver
|
||||||
return $this->payment_method->refund($payment, $amount); //this is your custom implementation from here
|
return $this->payment_method->refund($payment, $amount); //this is your custom implementation from here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNewAddressGen($crypto = 'btc', $response): string
|
||||||
|
{
|
||||||
|
$api_key = $this->company_gateway->getConfigField('apiKey');
|
||||||
|
$new_address_reset_url = $this->NEW_ADDRESS_URL . '?reset=1';
|
||||||
|
$new_address_response = Http::withToken($api_key)
|
||||||
|
->post($new_address_reset_url, []);
|
||||||
|
if ($new_address_response->response_code != 200) {
|
||||||
|
return isset($new_address_response->response_message) && $new_address_response->response_message
|
||||||
|
? $new_address_response->response_message
|
||||||
|
: 'Could not generate new address';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($new_address_response->address)) {
|
||||||
|
return 'No address returned from Blockonomics API';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'ok';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkStores($stores): string
|
||||||
|
{
|
||||||
|
if (empty($stores['data'])) {
|
||||||
|
return "Please add a store to your Blockonomics' account";
|
||||||
|
}
|
||||||
|
|
||||||
|
$invoice_ninja_callback_url = $this->company_gateway->webhookUrl();
|
||||||
|
|
||||||
|
$matching_store = null;
|
||||||
|
$store_without_callback = null;
|
||||||
|
$partial_match_store = null;
|
||||||
|
|
||||||
|
foreach ($stores['data'] as $store) {
|
||||||
|
if ($store['http_callback'] === $invoice_ninja_callback_url) {
|
||||||
|
$matching_store = $store;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (empty($store['http_callback'])) {
|
||||||
|
$store_without_callback = $store;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Check for partial match - only secret or protocol differs
|
||||||
|
// TODO: Implement logic for updating partial matches
|
||||||
|
$store_base_url = preg_replace('/https?:\/\//', '', $store['http_callback']);
|
||||||
|
if (strpos($store_base_url, $invoice_ninja_callback_url) === 0) {
|
||||||
|
$partial_match_store = $store;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($matching_store) {
|
||||||
|
$matching_store_wallet = $matching_store['wallets'];
|
||||||
|
if (empty($matching_store_wallet)) {
|
||||||
|
return 'Please add a wallet to your Blockonomics store';
|
||||||
|
}
|
||||||
|
return 'ok';
|
||||||
|
}
|
||||||
|
return "No callback URL from your Blockonomics stores matches your Invoice Ninja webhook";
|
||||||
|
}
|
||||||
|
|
||||||
public function auth(): string
|
public function auth(): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$api_key = $this->company_gateway->getConfigField('apiKey');
|
$api_key = $this->company_gateway->getConfigField('apiKey');
|
||||||
$url = $this->NEW_ADDRESS_URL . '?reset=1';
|
|
||||||
$response = Http::withToken($api_key)
|
if(!$api_key) {
|
||||||
->post($url, []);
|
return 'No API Key';
|
||||||
if($response->successful()) {
|
|
||||||
return 'ok';
|
|
||||||
}
|
}
|
||||||
return 'error';
|
$get_stores_response = Http::withToken($api_key)
|
||||||
|
->get($this->STORES_URL, ['wallets' => 'true']);
|
||||||
|
$get_stores_response_status = $get_stores_response->status();
|
||||||
|
|
||||||
|
if($get_stores_response_status == 401) {
|
||||||
|
return 'API Key is incorrect';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!$get_stores_response || $get_stores_response_status !== 200) {
|
||||||
|
return 'Could not connect to Blockonomics API';
|
||||||
|
}
|
||||||
|
|
||||||
|
$stores = $get_stores_response->json();
|
||||||
|
$stores_check_result = $this->checkStores($stores);
|
||||||
|
|
||||||
|
return $stores_check_result;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue