Skip to content

Commit c24aba6

Browse files
Merge branch 'master' of github.com:PaystackHQ/plugin-magento-2 into master
2 parents d22555b + cbb291b commit c24aba6

12 files changed

Lines changed: 159 additions & 65 deletions

.env.sample

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
MYSQL_HOST=mysql
2+
MYSQL_ROOT_PASSWORD=somemagento
3+
MYSQL_DATABASE=magento
4+
MYSQL_USER=magento
5+
MYSQL_PASSWORD=magento
6+
7+
MAGENTO_URL=http://localhost:8000
8+
MAGENTO_BACKEND_FRONTNAME=****************
9+
MAGENTO_USE_SECURE=0
10+
MAGENTO_BASE_URL_SECURE=0
11+
MAGENTO_USE_SECURE_ADMIN=0
12+
MAGENTO_ADMIN_FIRSTNAME=Admin
13+
MAGENTO_ADMIN_LASTNAME=MyStore
14+
MAGENTO_ADMIN_EMAIL=****************
15+
MAGENTO_ADMIN_USERNAME=****************
16+
MAGENTO_ADMIN_PASSWORD=****************
17+
magento_username=****************
18+
magento_password=****************

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ composer.phar
1111
# Random files
1212
*~
1313
\#*
14-
/nbproject/
14+
/nbproject/
15+
16+
.env

Controller/Payment/Webhook.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@
2424

2525

2626
use Magento\Sales\Model\Order;
27-
use Magento\Framework\App\CsrfAwareActionInterface;
28-
29-
include_once realpath(dirname(__FILE__)) . '/class-paystack-plugin-tracker.php';
30-
class Webhook extends AbstractPaystackStandard implements CsrfAwareActionInterface
3127

28+
class Webhook extends AbstractPaystackStandard
3229
{
3330

3431
public function execute() {
@@ -76,9 +73,8 @@ public function execute() {
7673

7774

7875
$reference = $transactionDetails->data->reference;
79-
//PSTK LOGGER HERE
80-
$pstk_logger = new magento_2_paystack_plugin_tracker('magento-2',$this->configProvider->getPublicKey());
81-
$pstk_logger.log_transaction_success($reference);
76+
//PSTK_LOGGER HERE
77+
log_transaction_success($reference);
8278
//------------------------
8379
$order = $this->orderInterface->loadByIncrementId($reference);
8480

@@ -104,13 +100,42 @@ public function execute() {
104100
return $resultFactory;
105101
}
106102
}
103+
}
107104
break;
108105
}
106+
}
109107
} catch (Exception $exc) {
110108
$finalMessage = $exc->getMessage();
111109
}
112110

113111
$resultFactory->setContents($finalMessage);
114112
return $resultFactory;
115113
}
114+
115+
function log_transaction_success($trx_ref){
116+
//send reference to logger along with plugin name and public key
117+
$url = "https://plugin-tracker.paystackintegrations.com/log/charge_success";
118+
$plugin_name = 'magento-2';
119+
$public_key = $this->configProvider->getPublicKey();
120+
121+
$fields = [
122+
'plugin_name' => $plugin_name,
123+
'transaction_reference' => $trx_ref,
124+
'public_key' => $public_key
125+
];
126+
127+
$fields_string = http_build_query($fields);
128+
129+
$ch = curl_init();
130+
131+
curl_setopt($ch,CURLOPT_URL, $url);
132+
curl_setopt($ch,CURLOPT_POST, true);
133+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
134+
135+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
136+
137+
//execute post
138+
$result = curl_exec($ch);
139+
// echo $result;
140+
}
116141
}

Controller/Payment/class-paystack-plugin-tracker.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM alexcheng/magento2
2+
3+
WORKDIR /var/www/html/
4+
5+
COPY ./setup_magento /usr/local/bin/setup_magento
6+
7+
RUN chmod +x /usr/local/bin/setup_magento
8+
9+
ARG magento_username
10+
11+
ARG magento_password
12+
13+
# setting up authentication credentials for magento
14+
COPY ./auth.json var/composer_home/auth.json
15+
16+
RUN sed -i -e "s/user_placeholder/$magento_username/g" var/composer_home/auth.json && sed -i -e "s/pass_placeholder/$magento_password/g" var/composer_home/auth.json
17+
18+
RUN chown -R www-data:www-data /var/www/html/var/composer_home
19+
20+
# We change to the www-data user who is the magento file system owner.
21+
# Visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/file-sys-perms-over.html for more information
22+
USER www-data
23+
24+
RUN /var/www/html/bin/magento sampledata:deploy
25+
26+
USER root
27+
28+
ENTRYPOINT [ "setup_magento" ]

Observer/ObserverAfterPaymentVerify.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@
88
class ObserverAfterPaymentVerify implements ObserverInterface
99
{
1010
/**
11-
* @var \Magento\Sales\Model\OrderFactory $_orderFactory
11+
* @var \Magento\Sales\Model\Order\Email\Sender\OrderSender
1212
*/
13-
protected $_orderFactory;
14-
15-
/**
16-
* @var \Magento\Checkout\Model\Session $_checkoutSession
17-
*/
18-
protected $_checkoutSession;
13+
protected $orderSender;
1914

2015
public function __construct(
21-
\Magento\Sales\Model\OrderFactory $orderFactory,
22-
\Magento\Checkout\Model\Session $checkoutSession
16+
\Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender
2317
) {
24-
$this->_checkoutSession = $checkoutSession;
25-
$this->_orderFactory = $orderFactory;
18+
$this->orderSender = $orderSender;
2619
}
2720

2821
public function execute(\Magento\Framework\Event\Observer $observer)
@@ -38,6 +31,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
3831
->setCanSendNewEmailFlag(true)
3932
->setCustomerNoteNotify(true);
4033
$order->save();
34+
35+
$this->orderSender->send($order, true);
4136
}
4237
}
4338
}

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ composer require yabacon/paystack-php
6666
[link-downloads]: https://packagist.org/packages/pstk/paystack-magento2-module
6767

6868

69+
## Running the magento2 on docker
70+
Contained within this repo, is a dockerfile and a docker-compose file to quickly spin up a magento2 and mysql container with the paystack plugin installed.
71+
72+
### Prerequisites
73+
- Install [Docker](https://www.docker.com/)
74+
75+
### Quick Steps
76+
- Create a `.env` file off the `.env.sample` in the root directory. Replace the `*******` with the right values
77+
- Run `docker-compose up` from the root directory to build and start the mysql and magento2 containers.
78+
- Visit `localhost:8000` on your browser to access the magento store. For the admin backend, visit `localhost:8000/<MAGENTO_BACKEND_FRONTNAME>` where `MAGENTO_BACKEND_FRONTNAME` is the value you specified in your `.env` file
79+
- Run `docker-compose down` from the root directory to stop the containers.
80+
81+
6982
## Documentation
7083

7184
* [Paystack Documentation](https://developers.paystack.co/v2.0/docs/)

auth.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"http-basic": {
3+
"repo.magento.com": {
4+
"username": "user_placeholder",
5+
"password": "pass_placeholder"
6+
}
7+
}
8+
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pstk/paystack-magento2-module",
33
"description": "Paystack Magento2 Module using \\Magento\\Payment\\Model\\Method\\AbstractMethod",
4-
"version": "2.3.5",
4+
"version": "2.4.1",
55
"require": {
66
"yabacon/paystack-php": "2.*"
77
},
@@ -24,4 +24,4 @@
2424
"Pstk\\Paystack\\": ""
2525
}
2626
}
27-
}
27+
}

docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '3.7'
2+
3+
services:
4+
mysql:
5+
image: mysql:5
6+
volumes:
7+
- db_data:/var/lib/mysql
8+
restart: always
9+
env_file: .env
10+
11+
magento2:
12+
depends_on:
13+
- mysql
14+
build:
15+
context: .
16+
args:
17+
- magento_username=$magento_username
18+
- magento_password=$magento_password
19+
image: paystack-magento2
20+
ports:
21+
- "8000:80"
22+
links:
23+
- mysql
24+
env_file: .env
25+
volumes:
26+
db_data: {}

0 commit comments

Comments
 (0)