1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments; |
4
|
|
|
|
5
|
|
|
use ByTIC\Payments\Gateways\Manager; |
6
|
|
|
use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider; |
7
|
|
|
use Nip\Records\Locator\ModelLocator; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class PaymentsServiceProvider |
11
|
|
|
* @package ByTIC\Payments |
12
|
|
|
*/ |
13
|
|
|
class PaymentsServiceProvider extends AbstractSignatureServiceProvider |
14
|
|
|
{ |
15
|
|
|
protected static $purchaseModel = 'purchases'; |
16
|
|
|
protected static $purchaseSessionsModel = 'purchase-sessions'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @inheritdoc |
20
|
|
|
*/ |
21
|
|
|
public function register() |
22
|
|
|
{ |
23
|
|
|
$this->registerPurchases(); |
24
|
|
|
$this->registerGatewaysManager(); |
25
|
|
|
$this->registerPurchaseSessions(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function registerPurchases() |
29
|
|
|
{ |
30
|
|
|
$this->getContainer()->singleton('purchases', function () { |
|
|
|
|
31
|
|
|
return ModelLocator::get($this::$purchaseModel); |
32
|
|
|
}); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function registerPurchaseSessions() |
36
|
|
|
{ |
37
|
|
|
$this->getContainer()->singleton('purchase-sessions', function () { |
38
|
|
|
return ModelLocator::get($this::$purchaseSessionsModel); |
39
|
|
|
}); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function registerGatewaysManager() |
43
|
|
|
{ |
44
|
|
|
$this->getContainer()->singleton('payments.gateways', function () { |
45
|
|
|
return new Manager(); |
46
|
|
|
}); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $purchaseModel |
51
|
|
|
*/ |
52
|
|
|
public static function setPurchaseModel(string $purchaseModel) |
53
|
|
|
{ |
54
|
|
|
self::$purchaseModel = $purchaseModel; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $purchaseSessionsModel |
59
|
|
|
*/ |
60
|
|
|
public static function setPurchaseSessionsModel(string $purchaseSessionsModel) |
61
|
|
|
{ |
62
|
|
|
self::$purchaseSessionsModel = $purchaseSessionsModel; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @inheritdoc |
67
|
|
|
*/ |
68
|
|
|
public function provides() |
69
|
|
|
{ |
70
|
|
|
return ['purchases', 'purchase-sessions','payments.gateways']; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|