-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApi.php
executable file
·97 lines (82 loc) · 2.22 KB
/
Api.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
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/
namespace CoreShop\Payum\Heidelpay;
use Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod;
use Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod;
use Heidelpay\PhpPaymentApi\PaymentMethods\PayPalPaymentMethod;
use Heidelpay\PhpPaymentApi\PaymentMethods\SofortPaymentMethod;
use Http\Message\MessageFactory;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\HttpClientInterface;
class Api
{
/**
* @var mixed
*/
protected $api;
/**
* @var HttpClientInterface
*/
protected $client;
/**
* @var MessageFactory
*/
protected $messageFactory;
const TYPES = [
'PayPal' => PayPalPaymentMethod::class,
'Sofort' => SofortPaymentMethod::class,
'CreditCard' => CreditCardPaymentMethod::class,
'DebitCard' => DebitCardPaymentMethod::class
];
/**
* @var array|ArrayObject
*/
protected $options = [];
/**
* @var string
*/
protected $type;
public function __construct($type, array $options, HttpClientInterface $client, MessageFactory $messageFactory)
{
$options = ArrayObject::ensureArrayObject($options);
$this->type = $type;
$this->options = $options;
$this->client = $client;
$this->messageFactory = $messageFactory;
}
/**
* @param $option
* @return mixed
*/
public function getOption($option)
{
return $this->options[$option];
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @return mixed
*/
public function getApi()
{
if (null === $this->api) {
$class = self::TYPES[$this->type];
$this->api = new $class();
}
return $this->api;
}
}