Skip to content

Commit

Permalink
update form and new features
Browse files Browse the repository at this point in the history
  • Loading branch information
leviothan committed Feb 26, 2018
1 parent aa0546c commit 7ab96b2
Show file tree
Hide file tree
Showing 10 changed files with 800 additions and 232 deletions.
93 changes: 69 additions & 24 deletions admin/controller/extension/payment/paybear.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ class ControllerExtensionPaymentPaybear extends Controller
public function index()
{
$this->load->model('setting/setting');
$this->load->model('extension/payment/paybear');
$this->load->language('extension/payment/paybear');

$installedVersion = $this->config->get('payment_paybear_version');
if (!$installedVersion) {
$installedVersion = '0.2.0';
}
$currentVersion = $this->model_extension_payment_paybear->getVersion();

if (version_compare($currentVersion, $installedVersion) > 0) {
$this->model_extension_payment_paybear->upgrade($installedVersion);
$this->model_setting_setting->editSettingValue('payment_paybear', 'payment_paybear_version', $currentVersion);
}

$this->document->setTitle($this->language->get('heading_title'));

$this->load->model('setting/setting');
Expand All @@ -24,6 +36,7 @@ public function index()
$data['log_filename'] = 'paybear.log';
$data['log_lines'] = $this->readLastLines(DIR_LOGS . $data['log_filename'], 500);
$data['clear_log'] = str_replace('&', '&', $this->url->link('extension/payment/paybear/clearlog', 'user_token=' . $this->session->data['user_token'], true));
$data['default_currency'] = $this->config->get('config_currency');

if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
Expand Down Expand Up @@ -69,6 +82,9 @@ public function index()
'payment_paybear_late_payment_status_id',
'payment_paybear_status',
'payment_paybear_debug',
'payment_paybear_max_underpayment',
'payment_paybear_min_overpayment',
'payment_paybear_version'
);

foreach ($fields as $field) {
Expand Down Expand Up @@ -98,43 +114,72 @@ public function install()
$langs = $this->model_localisation_language->getLanguages();

$defaultParams = [
'payment_paybear_version' => '0.3.0',
'payment_paybear_status' => 1,
'payment_paybear_title' => 'Crypto Payments (BTC/ETH/LTC and others)',
'payment_paybear_exchange_rate_locktime' => 15,
'payment_paybear_max_underpayment' => 0.01,
'payment_paybear_min_overpayment' => 1,
];

$orderStatuses = $this->model_localisation_order_status->getOrderStatuses();
foreach ($orderStatuses as $status) {
if ($status['name'] == 'PayBear: Payment Accepted') {
$defaultParams['payment_paybear_completed_status_id'] = $status['order_status_id'];
}
if ($status['name'] == 'PayBear: Awaiting Confirmations') {
$defaultParams['payment_paybear_awaiting_confirmations_status_id'] = $status['order_status_id'];
}
if ($status['name'] == 'PayBear: Mispaid') {
$defaultParams['payment_paybear_mispaid_status_id'] = $status['order_status_id'];
}
if ($status['name'] == 'PayBear: Late Payment') {
$defaultParams['payment_paybear_late_payment_status_id'] = $status['order_status_id'];
}
}


foreach ($langs as $lang) {
$this->model_localisation_order_status->addOrderStatus([
'order_status' => [
$lang['language_id'] => ['name' => 'PayBear: Payment Accepted']
]
]);
if (!isset($defaultParams['payment_paybear_completed_status_id'])) {
$this->model_localisation_order_status->addOrderStatus([
'order_status' => [
$lang['language_id'] => ['name' => 'PayBear: Payment Accepted']
]
]);

$defaultParams['payment_paybear_completed_status_id'] = $this->db->getLastId();
}

$defaultParams['payment_paybear_completed_status_id'] = $this->db->getLastId();
if (!isset($defaultParams['payment_paybear_awaiting_confirmations_status_id'])) {
$this->model_localisation_order_status->addOrderStatus([
'order_status' => [
$lang['language_id'] => ['name' => 'PayBear: Awaiting Confirmations']
]
]);

$this->model_localisation_order_status->addOrderStatus([
'order_status' => [
$lang['language_id'] => ['name' => 'PayBear: Awaiting Confirmations']
]
]);
$defaultParams['payment_paybear_awaiting_confirmations_status_id'] = $this->db->getLastId();
}

$defaultParams['payment_paybear_awaiting_confirmations_status_id'] = $this->db->getLastId();
if (!isset($defaultParams['payment_paybear_mispaid_status_id'])) {
$this->model_localisation_order_status->addOrderStatus([
'order_status' => [
$lang['language_id'] => ['name' => 'PayBear: Mispaid']
]
]);

$this->model_localisation_order_status->addOrderStatus([
'order_status' => [
$lang['language_id'] => ['name' => 'PayBear: Mispaid']
]
]);
$defaultParams['payment_paybear_mispaid_status_id'] = $this->db->getLastId();
}

$defaultParams['payment_paybear_mispaid_status_id'] = $this->db->getLastId();
if (!isset($defaultParams['payment_paybear_late_payment_status_id'])) {
$this->model_localisation_order_status->addOrderStatus([
'order_status' => [
$lang['language_id'] => ['name' => 'PayBear: Late Payment']
]
]);

$this->model_localisation_order_status->addOrderStatus([
'order_status' => [
$lang['language_id'] => ['name' => 'PayBear: Late Payment']
]
]);
$defaultParams['payment_paybear_late_payment_status_id'] = $this->db->getLastId();
}

$defaultParams['payment_paybear_late_payment_status_id'] = $this->db->getLastId();
break;
}

Expand Down
2 changes: 2 additions & 0 deletions admin/language/en-gb/extension/payment/paybear.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
//$_['help_notify_customer_success'] = 'Will send email with status update if payment success';
$_['help_debug'] = 'Logs additional information to the payment log';
$_['help_total'] = 'The checkout total the order must reach before this payment method becomes active';
$_['help_underpayment'] = 'The client will be notified and required to pay the balance owed for underpayments greater than this specified amount';
$_['help_overpayment'] = 'The client will be notified about their overpayment if it is greater than this amount. You will then need to issue the overpayment refund. ';

// Error
$_['error_permission'] = 'Warning: You do not have permission to modify payment PayBear!';
Expand Down
114 changes: 109 additions & 5 deletions admin/model/extension/payment/paybear.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,128 @@

class ModelExtensionPaymentPaybear extends Model
{
public $version = '0.3.0';

public function getVersion()
{
return $this->version;
}

public function install()
{
$this->db->query("
CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "paybear` (
`paybear_id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`order_id` INT(11) NOT NULL,
`token` VARCHAR(256) NULL DEFAULT NULL,
`address` VARCHAR(256),
`invoice` VARCHAR(256),
`token` VARCHAR(255) NULL DEFAULT NULL,
`address` VARCHAR(255),
`invoice` VARCHAR(255),
`amount` DECIMAL(20, 8),
`confirmations` INT(2) NULL DEFAULT NULL,
`max_confirmations` INT(2) NULL DEFAULT NULL,
`date_added` DATETIME NULL DEFAULT NULL,
`date_modified` DATETIME NULL DEFAULT NULL,
`payment_added` DATETIME NULL DEFAULT NULL,
KEY `order_id` (`order_id`),
KEY `token` (`token`)
) ENGINE=MyISAM DEFAULT COLLATE=utf8_general_ci;
");
");

$this->db->query("
CREATE TABLE IF NOT EXISTS `". DB_PREFIX ."paybear_transaction` (
`paybear_transaction_id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`order_id` VARCHAR(9) NOT NULL,
`invoice` VARCHAR(255) NULL DEFAULT NULL,
`blockchain` VARCHAR(255) NULL DEFAULT NULL,
`address` VARCHAR(255) NULL DEFAULT NULL,
`amount` DECIMAL(20, 8),
`currency` VARCHAR(255) NULL DEFAULT NULL,
`rate` DECIMAL(20, 8) NULL DEFAULT NULL,
`transaction_hash` VARCHAR(255) NULL DEFAULT NULL,
`confirmations` INT(2) NULL DEFAULT NULL,
`max_confirmations` INT(2) NULL DEFAULT NULL,
`date_added` DATETIME NULL DEFAULT NULL,
`date_modified` DATETIME NULL DEFAULT NULL,
KEY `order_id` (`order_id`),
KEY `blockchain` (`blockchain`),
KEY `transaction_hash` (`transaction_hash`)
) ENGINE = MyISAM DEFAULT COLLATE=utf8_general_ci;
");
}

public function upgrade($fromVersion)
{
$allMethods = get_class_methods($this);
$methodsToRun = [];
foreach ($allMethods as $method) {
if (strstr($method, 'upgrade_')) {
$methodVersion = str_replace('_', '.', str_replace('upgrade_', '', $method));
if (version_compare($methodVersion, $fromVersion) > 0) {
$methodsToRun[$methodVersion] = $method;
}
}
}
uasort($methodsToRun, 'version_compare');

foreach ($methodsToRun as $method) {
call_user_func([$this, $method]);
}

}

public function upgrade_0_3_0()
{
$oldData = $this->db->query("SELECT * FROM `" . DB_PREFIX . "paybear`");

$this->db->query("
CREATE TABLE IF NOT EXISTS `". DB_PREFIX ."paybear_transaction` (
`paybear_transaction_id` INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`order_id` VARCHAR(9) NOT NULL,
`invoice` VARCHAR(255) NULL DEFAULT NULL,
`blockchain` VARCHAR(255) NULL DEFAULT NULL,
`address` VARCHAR(255) NULL DEFAULT NULL,
`amount` DECIMAL(20, 8),
`currency` VARCHAR(255) NULL DEFAULT NULL,
`rate` DECIMAL(20, 8) NULL DEFAULT NULL,
`transaction_hash` VARCHAR(255) NULL DEFAULT NULL,
`confirmations` INT(2) NULL DEFAULT NULL,
`max_confirmations` INT(2) NULL DEFAULT NULL,
`date_added` DATETIME NULL DEFAULT NULL,
`date_modified` DATETIME NULL DEFAULT NULL,
KEY `order_id` (`order_id`),
KEY `blockchain` (`blockchain`),
KEY `transaction_hash` (`transaction_hash`)
) ENGINE = MyISAM DEFAULT COLLATE=utf8_general_ci;
");

foreach ($oldData->rows as $row) {
$order = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_id = " . $row['order_id'])->row;
if ($order['order_status_id'] != $this->config->get('payment_paybear_completed_status_id')) {
continue;
}

$transactionData = [
'order_id' => $order['order_id'],
'invoice' => $row['invoice'],
'blockchain' => $row['token'],
'address' => $row['address'],
'amount' => $row['amount'],
'confirmations' => $row['confirmations'],
'max_confirmations' => $row['max_confirmations'],
'date_added' => $row['payment_added'],
'date_modified' => $row['payment_added']
];

$valuesStrings = [];
foreach ($transactionData as $field => $value) {
if (empty($value) && ($value !== 0 || $value !== '0')) {
continue;
}

$valuesStrings[] = sprintf('%s = "%s"', $field, $value);
}

$this->db->query("INSERT INTO " . DB_PREFIX . "paybear_transaction SET " . implode(', ', $valuesStrings));

}
}
}
Loading

0 comments on commit 7ab96b2

Please sign in to comment.