1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Getloy\PaymentProviders; |
4
|
|
|
|
5
|
|
|
use Getloy\PaymentProviders\Configuration\PaymentProviderConfig; |
6
|
|
|
use Getloy\TransactionDetails\OrderDetails; |
7
|
|
|
use Getloy\TransactionDetails\OrderItems; |
8
|
|
|
use Getloy\TransactionDetails\PayeeDetails; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Abstract payment provider class. |
12
|
|
|
*/ |
13
|
|
|
abstract class PaymentProvider |
14
|
|
|
{ |
15
|
|
|
protected $paymentMethod; |
16
|
|
|
protected $requestOrigin = 'getloy-integration-library-php v1.0.0'; |
17
|
|
|
protected $config; |
18
|
|
|
|
19
|
|
|
public function __construct(array $config) |
20
|
|
|
{ |
21
|
|
|
$this->config = $this->instantiateValidator($config); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Instantiate a payment provider config for the payment method. |
26
|
|
|
* |
27
|
|
|
* @param array $config Configuration for the payment method. |
28
|
|
|
* @return PaymentProviderConfig The configuration. |
29
|
|
|
*/ |
30
|
|
|
abstract protected function instantiateValidator(array $config): PaymentProviderConfig; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Generate the payment provider-specific part of the widget payload. |
34
|
|
|
* |
35
|
|
|
* @param string $transactionId |
36
|
|
|
* @param OrderDetails $order |
37
|
|
|
* @param PayeeDetails $payee |
38
|
|
|
* @param string $callbackUrl |
39
|
|
|
* @param string $paymentMethodVariant Payment method variant name (optional). |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
abstract public function paymentProviderPayload( |
43
|
|
|
string $transactionId, |
44
|
|
|
OrderDetails $order, |
45
|
|
|
PayeeDetails $payee, |
46
|
|
|
string $callbackUrl, |
47
|
|
|
string $paymentMethodVariant = null |
48
|
|
|
): array; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get configuration value. |
52
|
|
|
* @param string $configOption Name of the configuration option. |
53
|
|
|
* @return mixed The configuration value, or an empty string if the option is not set. |
54
|
|
|
*/ |
55
|
|
|
public function get(string $option) |
56
|
|
|
{ |
57
|
|
|
return $this->config->get($option); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|