-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZwWebPaymentBitcoinCash.php
executable file
·162 lines (132 loc) · 6.24 KB
/
ZwWebPaymentBitcoinCash.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/*
* (c) LX <[email protected]>
* (c) 2017 Miguel Padilla <[email protected]>
* Donations: BCH:1L81xy6FoMHpNWxFtKTKGbsz9Sye1sSpSp BTC:1kD11aS83Du87EigaCodD8HVYmurHgT6i ETH:0x8F2E4fd2f76235f38188C2077978F3a0B278a453
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ZwWebPaymentBitcoinCash;
use Doctrine\ORM\Tools\SchemaTool;
use Shopware\Components\Plugin;
use ZwWebPaymentBitcoinCash\Components\BitcoinCash\AddressValidator;
use Shopware\Bundle\AttributeBundle\Service\DataLoader;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UninstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
class ZwWebPaymentBitcoinCash extends Plugin
{
public static function getSubscribedEvents()
{
return array(
'Enlight_Controller_Dispatcher_ControllerPath_Frontend_PaymentBitcoinCash' => 'onGetControllerPathFrontend',
'Enlight_Controller_Dispatcher_ControllerPath_Backend_PaymentBitcoinCash' => 'onGetControllerPathBackend',
);
}
public function install(InstallContext $context)
{
$sql_a = "CREATE TABLE IF NOT EXISTS `zwilla_free_bitcoincash_address` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_order` int(11),
`value_in_BCH` double NOT NULL,
`address` varchar(64) NOT NULL,
`status` enum('Pending','AwaitingConfirmations','UnderPaid','Paid','OverPaid') NOT NULL DEFAULT 'Pending',
`crdate` datetime NOT NULL,
`update` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `id_order` (`id_order`),
UNIQUE KEY `address` (`address`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
Shopware()->Db()->exec($sql_a);
$sql_b = "CREATE TABLE IF NOT EXISTS `zwilla_free_bitcoincash_transaction` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`transaction_hash` varchar(255) NOT NULL,
`address` varchar(64) NOT NULL,
`confirmations` tinyint(3) unsigned NOT NULL DEFAULT '0',
`value_in_satoshi` double NOT NULL,
`crdate` datetime NOT NULL,
`update` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `transaction_hash` (`transaction_hash`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
Shopware()->Db()->exec($sql_b);
$database_name = Shopware()->Db()->fetchOne('SELECT DATABASE()');
$database_engine = Shopware()->Db()->fetchOne("SELECT `ENGINE` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA`='".$database_name."' AND `TABLE_NAME`='zwilla_free_bitcoincash_address'");
if ($database_engine == 'InnoDB') {
$result1 = Shopware()->Db()->fetchOne("SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` WHERE `TABLE_NAME` = 'zwilla_free_bitcoincash_address' AND `CONSTRAINT_NAME` = 'zwilla_free_bitcoincash_address_ibfk_1' AND `TABLE_SCHEMA` = '".$database_name."'");
if (empty($result1)) {
Shopware()->Db()->exec("ALTER IGNORE TABLE `zwilla_free_bitcoincash_address` ADD CONSTRAINT `zwilla_free_bitcoincash_address_ibfk_1` FOREIGN KEY (`id_order`) REFERENCES `s_order_attributes` (`orderID`) ON DELETE CASCADE ON UPDATE CASCADE");
}
$result2 = Shopware()->Db()->fetchOne("SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` WHERE `TABLE_NAME` = 'zwilla_free_bitcoincash_transaction' AND `CONSTRAINT_NAME` = 'zwilla_free_bitcoincash_transaction_ibfk_1' AND `TABLE_SCHEMA` = '".$database_name."'");
if (empty($result2)) {
Shopware()->Db()->exec("ALTER IGNORE TABLE `zwilla_free_bitcoincash_transaction` ADD CONSTRAINT `zwilla_free_bitcoincash_transaction_ibfk_1` FOREIGN KEY (`address`) REFERENCES `zwilla_free_bitcoincash_address` (`address`) ON DELETE CASCADE ON UPDATE CASCADE");
}
}
$this->createMyPayment();
parent::install($context);
}
/**
* @inheritdoc
*/
public function uninstall(UninstallContext $context)
{
parent::uninstall($context);
}
/**
* @param UpdateContext $contex
* @return array|bool
* @internal param string $version
*/
public function update(UpdateContext $contex)
{
$version ='0.0.2';
if ($version == '0.0.1') {
return false;
}
parent::update($context);
}
/**
* Returns the path to a frontend controller for an event.
*
* @return string
*/
public function onGetControllerPathFrontend(\Enlight_Event_EventArgs $args)
{
Shopware()->Template()->addTemplateDir($this->getPath() . '/Views/');
return $this->getPath() . '/Controllers/Frontend/PaymentBitcoinCash.php';
}
/**
* Returns the path to a backend controller for an event.
*
* @return string
*/
public function onGetControllerPathBackend(\Enlight_Event_EventArgs $args)
{
Shopware()->Template()->addTemplateDir($this->getPath() . '/Views/');
Shopware()->Snippets()->addConfigDir($this->getPath() . '/Snippets/');
return $this->getPath() . '/Controllers/Backend/PaymentBitcoinCash.php';
}
/**
* Creates and save the payment row.
*/
private function createMyPayment()
{
$options = array(
'name' => 'zwillaweb_payment_bitcoincash',
'description' => 'BitcoinCash',
'action' => 'payment_bitcoincash',
'active' => 1,
'position' => 0,
'additionalDescription' => 'Pay save and secured with BitcoinCash.'
);
$payment = Shopware()->Models()->getRepository('Shopware\Models\Payment\Payment')->findOneBy(array('name' => 'zwillaweb_payment_bitcoincash'));
if ($payment === null) {
$payment = new \Shopware\Models\Payment\Payment();
$payment->setName($options['name']);
Shopware()->Models()->persist($payment);
};
$payment->fromArray($options);
Shopware()->Models()->flush($payment);
return $payment;
}
}