-
Notifications
You must be signed in to change notification settings - Fork 3
/
shoppingcart-stripe.php
92 lines (80 loc) · 2.22 KB
/
shoppingcart-stripe.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
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
/**
* Class ShoppingcartStripePlugin
* @package Grav\Plugin
*/
class ShoppingcartStripePlugin extends Plugin
{
protected $plugin_name = 'shoppingcart-stripe';
protected $gateway;
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
/**
*/
public function onTwigSiteVariables()
{
$this->grav['assets']->addJs('plugin://' . $this->plugin_name . '/gateways/stripe/script.js');
$this->grav['assets']->addJs('https://checkout.stripe.com/checkout.js');
}
/**
*/
public function mergeShoppingCartPluginConfig()
{
$config = $this->config->get('plugins.' . $this->plugin_name);
unset($config['enabled']);
$this->config->set('plugins.shoppingcart', array_replace_recursive($this->config->get('plugins.shoppingcart'), $config));
}
/**
* Enable search only if url matches to the configuration.
*/
public function onPluginsInitialized()
{
require_once __DIR__ . '/vendor/autoload.php';
if (!$this->isAdmin()) {
$this->mergeShoppingCartPluginConfig();
$this->enable([
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onShoppingCartPay' => ['onShoppingCartPay', 0],
]);
}
}
/**
*
*/
protected function requireGateway()
{
$path = realpath(__DIR__ . '/../shoppingcart/classes/gateway.php');
if (!file_exists($path)) {
$path = realpath(__DIR__ . '/../grav-plugin-shoppingcart/classes/gateway.php');
}
require_once($path);
}
/**
*
*/
public function getGateway()
{
if (!$this->gateway) {
$this->requireGateway();
require_once __DIR__ . '/gateways/stripe/gateway.php';
$this->gateway = new ShoppingCart\GatewayStripe();
}
return $this->gateway;
}
/**
* @param $event
*/
public function onShoppingCartPay($event)
{
$this->getGateway()->onShoppingCartPay($event);
}
}