Skip to content

Commit

Permalink
Merge pull request #20 from blockonomics/version-0.2.2-updates
Browse files Browse the repository at this point in the history
Version 0.2.2 updates
  • Loading branch information
blockonomics authored Feb 4, 2021
2 parents ed33194 + dbce354 commit 728ac9b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 110 deletions.
37 changes: 8 additions & 29 deletions admin/controller/extension/payment/blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function __construct($registry) {
public function index() {
// Saving settings
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->request->post['action'] === 'save' && $this->validate()) {

$this->session->data['success'] = $this->language->get('text_success');
$this->setting('geo_zone_id', $this->request->post['payment_blockonomics_geo_zone_id']);
$this->setting('status', $this->request->post['payment_blockonomics_status']);
Expand All @@ -42,8 +41,6 @@ public function index() {
$this->setting('callback_url', $this->request->post['payment_blockonomics_callback_url']);
$this->setting('api_key', $this->request->post['payment_blockonomics_api_key']);
$this->setting('underpayment_slack', $this->request->post['payment_blockonomics_underpayment_slack']);
$this->setting('paid_status', $this->request->post['payment_blockonomics_paid_status']);
$this->setting('confirmed_status', $this->request->post['payment_blockonomics_confirmed_status']);
$this->setting('complete_status', $this->request->post['payment_blockonomics_complete_status']);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/payment/blockonomics', 'user_token=' . $this->session->data['user_token'], true));
Expand All @@ -61,13 +58,7 @@ public function index() {
$data['entry_api_key'] = $this->language->get('entry_api_key');
$data['entry_underpayment_slack'] = $this->language->get('entry_underpayment_slack');
$data['entry_callback_secret'] = $this->language->get('entry_callback_secret');
$data['entry_paid_status'] = $this->language->get('entry_paid_status');
$data['entry_confirmed_status'] = $this->language->get('entry_confirmed_status');
$data['entry_complete_status'] = $this->language->get('entry_complete_status');

$data['help_paid_status'] = $this->language->get('help_paid_status');
$data['help_confirmed_status'] = $this->language->get('help_confirmed_status');
$data['help_complete_status'] = $this->language->get('help_complete_status');
$data['entry_complete_status'] = $this->language->get('entry_complete_status');

$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
Expand Down Expand Up @@ -113,9 +104,7 @@ public function index() {
// #ORDER STATUSES
$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
$data['blockonomics_paid_status'] = (isset($this->request->post['blockonomics_paid_status'])) ? $this->request->post['blockonomics_paid_status'] : $this->setting('paid_status');
$data['blockonomics_confirmed_status'] = (isset($this->request->post['blockonomics_confirmed_status'])) ? $this->request->post['blockonomics_confirmed_status'] : $this->setting('confirmed_status');
$data['blockonomics_complete_status'] = (isset($this->request->post['blockonomics_complete_status'])) ? $this->request->post['blockonomics_complete_status'] : $this->setting('complete_status');
$data['blockonomics_complete_status'] = (isset($this->request->post['blockonomics_complete_status'])) ? $this->request->post['blockonomics_complete_status'] : $this->setting('complete_status');

// #LAYOUT
$data['header'] = $this->load->controller('common/header');
Expand Down Expand Up @@ -243,25 +232,17 @@ private function validate() {
*/
public function install() {

$this->load->model('localisation/order_status');
$this->load->model('localisation/order_status');
$order_statuses = $this->model_localisation_order_status->getOrderStatuses();
$default_paid = null;
$default_confirmed = null;
$default_complete= null;
$default_complete_status = null;

foreach ($order_statuses as $order_status) {
if ($order_status['name'] == 'Processing') {
$default_paid = $order_status['order_status_id'];
} elseif ($order_status['name'] == 'Processed') {
$default_confirmed = $order_status['order_status_id'];
} elseif ($order_status['name'] == 'Complete') {
$default_complete = $order_status['order_status_id'];
$default_complete_status = $order_status['order_status_id'];
}
}
}

$this->blockonomics->log("info", $default_paid );
$this->blockonomics->log("info", $default_confirmed );
$this->blockonomics->log("info", $default_complete );
$this->blockonomics->log("info", $default_complete_status );

//Generate callback secret
$secret = md5(uniqid(rand(), true));
Expand All @@ -285,9 +266,7 @@ public function install() {
'payment_blockonomics_api_key' => null,
'payment_blockonomics_underpayment_slack' => '0',
'payment_blockonomics_version' => $this->blockonomics->version,
'payment_blockonomics_paid_status' => $default_paid,
'payment_blockonomics_confirmed_status' => $default_confirmed,
'payment_blockonomics_complete_status' => $default_complete
'payment_blockonomics_complete_status' => $default_complete_status
);
$this->model_setting_setting->editSetting('payment_blockonomics', $default_settings);

Expand Down
17 changes: 4 additions & 13 deletions admin/language/en-gb/extension/payment/blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
$_['text_changes'] = 'There are unsaved changes.';
$_['text_blockonomics'] = '<a onclick="window.open(\'https://www.blockonomics.co/\');"><img src="view/image/payment/blockonomics.png" alt="Blockonomics" title="blockonomics" style="border: 1px solid #EEEEEE;" /></a>';
$_['text_general'] = 'General';
$_['text_statuses'] = 'Order Statuses';
$_['text_advanced'] = 'Advanced';
$_['text_statuses'] = 'Order Statuses';
$_['text_advanced'] = 'Blockonomics';
$_['text_all_geo_zones'] = 'All Geo Zones';
$_['text_yes'] = 'Yes';
$_['text_no'] = 'No';
Expand All @@ -37,11 +35,9 @@
$_['entry_sort_order'] = 'Sort Order';
$_['entry_callback_secret'] = 'Callback Secret';
$_['entry_test_setup'] = 'Test Setup';
$_['entry_paid_status'] = 'Paid Status';
$_['entry_confirmed_status'] = 'Confirmed Status';
$_['entry_complete_status'] = 'Complete Status';
$_['entry_callback_url'] = 'Callback URL';
$_['entry_api_key'] = 'Blockonomics API Key';
$_['entry_complete_status'] = 'Order Status';
$_['entry_callback_url'] = 'Callback URL';
$_['entry_api_key'] = 'API Key';
$_['entry_underpayment_slack'] = 'Underpayment Slack %';
$_['entry_debug'] = 'Debug Logging';
$_['entry_name'] = 'Name';
Expand All @@ -52,11 +48,6 @@
$_['entry_send_server_info'] = 'Send Server Information';

// Help
$_['help_paid_status'] = 'A fully paid invoice awaiting confirmation';
$_['help_confirmed_status'] = 'Once confirmed Bitcoin transaction order status';
$_['help_complete_status'] = 'An invoice that has been credited to your account';
$_['help_callback_url'] = 'Blockonomics&#8217;s IPN will post invoice status updates to this URL';
$_['help_api_key'] = 'Blockonimcs will provide API KEY in its settings to do API calls';
$_['help_underpayment_slack'] = 'Allow payments that are off by a small percentage';

// Warning
Expand Down
88 changes: 32 additions & 56 deletions admin/view/template/extension/payment/blockonomics.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@
<div class="panel-body">
<form action="{{ url_action }}" method="post" enctype="multipart/form-data" id="form-blockonomics-account" class="form-horizontal">
<input type="hidden" name="action" value="save">
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-settings" data-toggle="tab">{{ tab_settings }}</a></li>
</ul>


<div class="tab-content">
<div class="tab-pane active" id="tab-settings">

Expand Down Expand Up @@ -99,39 +96,8 @@
</div>
</div>


<br>
<h3 class="col-sm-10 col-sm-offset-2">{{ text_statuses }}</h3>
<div class="form-group">
<label class="col-sm-2 control-label"><span data-toggle="tooltip" title="{{ help_paid_status }}">{{ entry_paid_status }}</span></label>
<div class="col-sm-10">
<select name="payment_blockonomics_paid_status" class="form-control">
{% for order_status in order_statuses %}
{% if order_status['order_status_id'] == blockonomics_paid_status %}
<option value="{{ order_status['order_status_id'] }}" selected="selected">{{ order_status['name'] }}</option>
{% else %}
<option value="{{ order_status['order_status_id'] }}">{{ order_status['name'] }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span data-toggle="tooltip" title="{{ help_confirmed_status }}">{{ entry_confirmed_status }}</span></label>
<div class="col-sm-10">
<select name="payment_blockonomics_confirmed_status" class="form-control">
{% for order_status in order_statuses %}
{% if order_status['order_status_id'] == blockonomics_confirmed_status %}
<option value="{{ order_status['order_status_id'] }}" selected="selected">{{ order_status['name'] }}</option>
{% else %}
<option value="{{ order_status['order_status_id'] }}">{{ order_status['name'] }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"><span data-toggle="tooltip" title="{{ help_complete_status }}">{{ entry_complete_status }}</span></label>
<label class="col-sm-2 control-label">{{ entry_complete_status }}</label>
<div class="col-sm-10">
<select name="payment_blockonomics_complete_status" class="form-control">
{% for order_status in order_statuses %}
Expand All @@ -147,6 +113,17 @@

<br>
<h3 class="col-sm-10 col-sm-offset-2">{{ text_advanced }}</h3>
<input type="hidden" id="blockonomics_api_updated" value="false">
<div class="form-group">
<label class="col-sm-2 control-label" for="blockonomics_api_key">{{ entry_api_key }}</label>
<div class="col-sm-10">
<input type="text" name="payment_blockonomics_api_key" id="blockonomics_api_key" value="{{ blockonomics_api_key }}" placeholder="{{ default_api_key }}" class="form-control" onchange="valueChanged()" />
{% if error_api_key %}
<div class="text-danger">{{ error_api_key }}</div>
{% endif %}
</div>
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="input-callback-secret">{{ entry_callback_secret }}</label>
<div class="col-sm-7">
Expand All @@ -159,7 +136,7 @@
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="input-notify-url"><span data-toggle="tooltip" title="{{ help_callback_url }}">{{ entry_callback_url }}</span></label>
<label class="col-sm-2 control-label" for="input-notify-url">{{ entry_callback_url }}</label>
<div class="col-sm-10">
<div class="input-group"> <span class="input-group-addon"><i class="fa fa-link fa-fw"></i></span>
<input readonly type="url" name="payment_blockonomics_callback_url" id="input-notify-url" value="{{ blockonomics_callback_url }}" placeholder="{{ default_callback_url }}" class="form-control" />
Expand All @@ -171,34 +148,25 @@
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="input-api-key"><span data-toggle="tooltip" title="{{ help_api_key }}">{{ entry_api_key }}</span></label>
<label class="col-sm-2 control-label" for="input-underpayment-slack"><span data-toggle="tooltip" title="{{ help_underpayment_slack }}">{{ entry_underpayment_slack }}</span></label>
<div class="col-sm-10">
<input type="text" name="payment_blockonomics_api_key" id="input-api-key" value="{{ blockonomics_api_key }}" placeholder="{{ default_api_key }}" class="form-control" />
{% if error_api_key %}
<div class="text-danger">{{ error_api_key }}</div>
{% if blockonomics_underpayment_slack != "" %}
<input type="number" min="0" max="4" step="0.01" name="payment_blockonomics_underpayment_slack" id="input-underpayment-slack" value="{{ blockonomics_underpayment_slack }}" class="form-control" />
{% else %}
<input type="number" min="0" max="4" step="0.01" name="payment_blockonomics_underpayment_slack" id="input-underpayment-slack" value="{{ default_underpayment_slack }}" class="form-control" />
{% endif %}
</div>
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="input-callback-secret">{{ entry_test_setup }}</label>
<div class="col-sm-3">
<a href="{{ url_test_setup }}" data-toggle="tooltip" title="{{ text_test_setup }}" class="btn
<div id="url_test_setup" data-url="{{ url_test_setup }}"></div>
<a onclick="checkForAPIKeyChange();" data-toggle="tooltip" title="{{ text_test_setup }}" class="btn
btn-primary">{{ text_test_setup }}</a>
</div>
</div>

<div class="form-group">
<label class="col-sm-2 control-label" for="input-underpayment-slack"><span data-toggle="tooltip" title="{{ help_underpayment_slack }}">{{ entry_underpayment_slack }}</span></label>
<div class="col-sm-10">
{% if blockonomics_underpayment_slack != "" %}
<input type="number" min="0" max="4" step="0.01" name="payment_blockonomics_underpayment_slack" id="input-underpayment-slack" value="{{ blockonomics_underpayment_slack }}" class="form-control" />
{% else %}
<input type="number" min="0" max="4" step="0.01" name="payment_blockonomics_underpayment_slack" id="input-underpayment-slack" value="{{ default_underpayment_slack }}" class="form-control" />
{% endif %}
</div>
</div>

</div>
</div>
</form>
Expand Down Expand Up @@ -250,8 +218,16 @@
}
</style>
<script type="text/javascript">
function genSecret(){
}
function valueChanged() {
document.getElementById('blockonomics_api_updated').value = 'true';
}
function checkForAPIKeyChange() {
if (document.getElementById('blockonomics_api_updated').value == 'true') {
alert('Settings have changed, click on Save first');
} else {
var apiUrl = document.getElementById("url_test_setup").dataset.url;
window.location = apiUrl;
}
}
</script>
{{ footer }}
15 changes: 6 additions & 9 deletions catalog/controller/extension/payment/blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function invoice() {
// If there is no existing order in database, generate Bitcoin address
if(!isset($order['id_order'])){
$response = $this->blockonomics->getNewAddress();
if(!isset($response->error)) {
if($response->response_code == 200) {
$btc_address=$response->address;
$data['btc_address'] = $btc_address;
$data['btc_href'] = "bitcoin:".$btc_address."?amount=".$satoshi_amount;
Expand Down Expand Up @@ -283,39 +283,36 @@ public function callback() {

switch ($status) {
case 0:
$order_status_id = $this->setting('paid_status');
$order_message = $this->language->get('text_progress_paid');
$order_status_id = '1';
$comment = "Waiting for Confirmation on Bitcoin network<br>" .
"Bitcoin transaction id: $txid <br>" .
"You can view the transaction at: <br>" .
"<a href='https://www.blockonomics.co/api/tx?txid=$txid&addr=$addr' target='_blank'>https://www.blockonomics.co/api/tx?txid=$txid&addr=$addr</a>";
// Progress the order status
$this->model_checkout_order->addOrderHistory($order['id_order'], $order_status_id, $comment, true);
break;
case 1:
$order_status_id = $this->setting('confirmed_status');
$order_message = $this->language->get('text_progress_confirmed');
break;
case 2:
if ($paid < $expected) {
$order_status_id = '7'; // 7 = Canceled
$order_message = 'Canceled';
$comment = "<b>Warning: Invoice canceled as Paid Amount was less than expected</b><br>";
} else {
$order_status_id = $this->setting('complete_status');
$order_message = $this->language->get('text_progress_complete');
}
$comment .= "Bitcoin transaction id: $txid\r" .
"Expected amount: $expected BTC\r" .
"Paid amount: $real_paid BTC\r" .
"You can view the transaction at:\r" .
"<a href='https://www.blockonomics.co/api/tx?txid=$txid&addr=$addr' target='_blank'>https://www.blockonomics.co/api/tx?txid=$txid&addr=$addr</a>";
// Progress the order status
$this->model_checkout_order->addOrderHistory($order['id_order'], $order_status_id, $comment, true);
break;
default:
$this->log('info', 'Status is not paid/confirmed/complete. Redirecting to checkout/checkout');
$this->response->redirect($this->url->link('checkout/checkout'));
return;
}

// Progress the order status
$this->model_checkout_order->addOrderHistory($order['id_order'], $order_status_id, $comment, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

<div id="content" class="{{ class }}">
{{ content_top }}
<h1>{{ heading_title }}</h1>

{% if address_error == "" %}
<div id="payment-view">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

<div id="content" class="{{ class }}">
{{ content_top }}
<h1>{{ heading_title }}</h1>

<h3 class="red">Payment expired</h3>
<p>The maximum time of 10 minutes during payment was reached. The order has been put on hold.</p>
Expand Down
2 changes: 1 addition & 1 deletion system/library/blockonomics.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Blockonomics {

/** @var int $version */
public $version = '0.2.0';
public $version = '0.2.2';

/** @var Registry $registry */
private $registry;
Expand Down

0 comments on commit 728ac9b

Please sign in to comment.