Skip to content

(fix) Test Setup Placement and Actual Test #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: bch-admin-ui-updates
Choose a base branch
from

Conversation

thisisayush
Copy link
Collaborator

This PR fixes Multi Crypto Testing and Layout issues. Extends #128

@thisisayush
Copy link
Collaborator Author

image

@thisisayush
Copy link
Collaborator Author

Updated Test Setup Script and Frontend to send single request to test all enabled ceyptos.

Current Issues:

  • While clicking "Test Setup" in frontend, the backend will still test for previously enabled cryptos only and will not take new changes in enabled cryptos into account. Possible Solutions: Pass the new cryptos as parameters, or disable test setup button on crypto status change unless save is clicked.

return $test_results;
}

public function test_one_currency($new_api, $currency)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_one_currency can be renamed to test_one_crypto and refactored to match the latest woocommerce structure, which makes the code easier to read:
https://github.com/blockonomics/woocommerce-plugin/blob/master/php/Blockonomics.php#L343-L357
https://github.com/blockonomics/woocommerce-plugin/blob/master/php/Blockonomics.php#L193-L208

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though so too, but in the plugin code, crypto is being referred as currency in every function, changing it to crypto might cause confusions and human errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be best to use currency for the fiat currency linked to each order and crypto for the blockonomics cryptocurrencies.

Moving forward lets use this standard. I have opened a new issue for us to correct any existing functions that do not adhere to this #131.

$response->errorStr = $error;
if (isset($error) && count($error) != 0) {
if (count(array_filter($error, function($item) { return $item != false; })) != 0) {
$response->error = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$response->error can be removed as the errorStr will be an empty array if there are no errors

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

@thisisayush
Copy link
Collaborator Author

Updated and removed the new API Key check and extra params from response.

if (isset($newApi)) {
$blockonomics = new Blockonomics();
$response = array();
$error = array();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not required as testSetup returns an empty array if there are no errors. The checks below which count the error length can also be removed. The following code should be enough as we check the error array later:

$blockonomics = new Blockonomics();
$error = $blockonomics->testSetup();
echo json_encode($error);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@thisisayush
Copy link
Collaborator Author

Refactored the testSetup functionality to individual methods corresponding to Woocommerce Plugin.

@thisisayush thisisayush mentioned this pull request Oct 19, 2021
@thisisayush
Copy link
Collaborator Author

thisisayush commented Oct 25, 2021

Added:

  • Checks to see if at least one crypto is enabled
  • Make BTC Enabled by default
  • Remove Underline and add cursor pointer in Advanced Settings Button/Link.

@thisisayush
Copy link
Collaborator Author

Added:

  • Check for Empty API Key
  • Prevent testsetup to run on protocol mismatch
  • Default Error Message in getNewAddress
  • Make Automatic Selection of currency incase of single currency dynamic in payment page

}
$callback_secret = $this->getCallbackSecret();
$callback_url = $this->getCallbackUrl($callback_secret);
$base_url = preg_replace('/https?:\/\//', '', substr($callback_url, 0, -48));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-48 is a very hacky way, please use length of secret instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Comment on lines 799 to 803
if (count($response->data) == 1) {
$error_str = $_BLOCKLANG['testSetup']['existingCallbackUrl'];
} else {
$error_str = $_BLOCKLANG['testSetup']['multipleXpubs'];
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not matching woocommerce code . please check

Copy link
Collaborator Author

@thisisayush thisisayush Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Because Woocommerce only returns Please add a new store on blockonomics website while WHMCS Plugin returned You have an existing callback URL. Refer instructions on integrating multiple websites and Your have an existing callback URL or multiple xPubs. Refer instructions on integrating multiple websites based on whether user has single or multiple stores.

We can change it to the same as Woocommerce i.e. Single Message for both cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 59 to 60
$_BLOCKLANG['testSetup']['noXpub'] = 'You have not entered an xpub';
$_BLOCKLANG['testSetup']['existingCallbackUrl'] = 'Your have an existing callback URL. Refer instructions on integrating multiple websites';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for messages 59-61. Note the changes in wocoomerce. There is only one message that we use everywhere
https://github.com/blockonomics/woocommerce-plugin/blob/master/php/Blockonomics.php#L141
https://github.com/blockonomics/woocommerce-plugin/blob/master/php/Blockonomics.php#L187

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@thisisayush
Copy link
Collaborator Author

Updated:

  • Merged Error Messages as per WooCommerce Plugin
  • Make extraction of base_url from callback better by replacing constant -48 with actual string length calculation

@@ -760,7 +760,7 @@ public function examine_server_callback_urls($response, $currency)

$callback_secret = $this->getCallbackSecret();
$callback_url = $this->getCallbackUrl($callback_secret);
$base_url = preg_replace('/https?:\/\//', '', substr($callback_url, 0, -48));
$base_url = preg_replace('/https?:\/\//', '', substr($callback_url, 0, -1 * (strlen($callback_secret) + 8)));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the 8 added. Please add a code comment so that this code is more understandable

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the extraction logic to use strtok instead of manually working on it. it'll now split the string before ? and give the callback URL without needing to use substr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants