Passed
Push — master ( 00b32c...f72d01 )
by Aimeos
04:46
created

Base   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 151
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 151
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigBE() 0 3 1
A cancel() 0 4 1
A refund() 0 4 1
A transfer() 0 4 1
A repay() 0 4 1
A checkConfigBE() 0 3 1
A setConfigFE() 0 4 1
A process() 0 4 1
A capture() 0 4 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2021
7
 * @package MShop
8
 * @subpackage Service
9
 */
10
11
12
namespace Aimeos\MShop\Service\Provider\Payment;
13
14
15
/**
16
 * Abstract class for all payment provider implementations.
17
 *
18
 * @package MShop
19
 * @subpackage Service
20
 */
21
abstract class Base extends \Aimeos\MShop\Service\Provider\Base implements Iface
22
{
23
	/**
24
	 * Feature constant if querying for status updates for an order is supported.
25
	 */
26
	const FEAT_QUERY = 1;
27
28
	/**
29
	 * Feature constant if canceling authorizations is supported.
30
	 */
31
	const FEAT_CANCEL = 2;
32
33
	/**
34
	 * Feature constant if money authorization and later capture is supported.
35
	 */
36
	const FEAT_CAPTURE = 3;
37
38
	/**
39
	 * Feature constant if refunding payments is supported.
40
	 */
41
	const FEAT_REFUND = 4;
42
43
	/**
44
	 * Feature constant if reoccurring payments is supported.
45
	 */
46
	const FEAT_REPAY = 5;
47
48
	/**
49
	 * Feature constant if payment transfer is supported.
50
	 */
51
	const FEAT_TRANSFER = 6;
52
53
54
	/**
55
	 * Checks the backend configuration attributes for validity.
56
	 *
57
	 * @param array $attributes Attributes added by the shop owner in the administraton interface
58
	 * @return array An array with the attribute keys as key and an error message as values for all attributes that are
59
	 * 	known by the provider but aren't valid
60
	 */
61
	public function checkConfigBE( array $attributes ) : array
62
	{
63
		return [];
64
	}
65
66
67
	/**
68
	 * Returns the configuration attribute definitions of the provider to generate a list of available fields and
69
	 * rules for the value of each field in the administration interface.
70
	 *
71
	 * @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface
72
	 */
73
	public function getConfigBE() : array
74
	{
75
		return [];
76
	}
77
78
79
	/**
80
	 * Cancels the authorization for the given order if supported.
81
	 *
82
	 * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
83
	 * @return \Aimeos\MShop\Order\Item\Iface Updated order item object
84
	 */
85
	public function cancel( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface
86
	{
87
		$msg = $this->getContext()->translate( 'mshop', 'Method "%1$s" for provider not available' );
88
		throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, 'cancel' ) );
89
	}
90
91
92
	/**
93
	 * Captures the money later on request for the given order if supported.
94
	 *
95
	 * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
96
	 * @return \Aimeos\MShop\Order\Item\Iface Updated order item object
97
	 */
98
	public function capture( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface
99
	{
100
		$msg = $this->getContext()->translate( 'mshop', 'Method "%1$s" for provider not available' );
101
		throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, 'capture' ) );
102
	}
103
104
105
	/**
106
	 * Tries to get an authorization or captures the money immediately for the given order if capturing the money
107
	 * separately isn't supported or not configured by the shop owner.
108
	 *
109
	 * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
110
	 * @param array $params Request parameter if available
111
	 * @return \Aimeos\MShop\Common\Helper\Form\Iface|null Form object with URL, action and parameters to redirect to
112
	 * 	(e.g. to an external server of the payment provider or to a local success page)
113
	 */
114
	public function process( \Aimeos\MShop\Order\Item\Iface $order, array $params = [] ) : ?\Aimeos\MShop\Common\Helper\Form\Iface
115
	{
116
		$url = $this->getConfigValue( 'payment.url-success', '' );
117
		return new \Aimeos\MShop\Common\Helper\Form\Standard( $url, 'POST', [] );
118
	}
119
120
121
	/**
122
	 * Refunds the money for the given order if supported.
123
	 *
124
	 * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
125
	 * @return \Aimeos\MShop\Order\Item\Iface Updated order item object
126
	 */
127
	public function refund( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface
128
	{
129
		$msg = $this->getContext()->translate( 'mshop', 'Method "%1$s" for provider not available' );
130
		throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, 'refund' ) );
131
	}
132
133
134
	/**
135
	 * Executes the payment again for the given order if supported.
136
	 * This requires support of the payment gateway and token based payment
137
	 *
138
	 * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
139
	 * @return \Aimeos\MShop\Order\Item\Iface Updated order item object
140
	 */
141
	public function repay( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface
142
	{
143
		$msg = $this->getContext()->translate( 'mshop', 'Method "%1$s" for provider not available' );
144
		throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, 'repay' ) );
145
	}
146
147
148
	/**
149
	 * Sets the payment attributes in the given service.
150
	 *
151
	 * @param \Aimeos\MShop\Order\Item\Base\Service\Iface $orderServiceItem Order service item that will be added to the basket
152
	 * @param array $attributes Attribute key/value pairs entered by the customer during the checkout process
153
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Iface Order service item with attributes added
154
	 */
155
	public function setConfigFE( \Aimeos\MShop\Order\Item\Base\Service\Iface $orderServiceItem,
156
		array $attributes ) : \Aimeos\MShop\Order\Item\Base\Service\Iface
157
	{
158
		return $this->setAttributes( $orderServiceItem, $attributes, 'payment' );
159
	}
160
161
162
	/**
163
	 * Transfers the money to the vendors.
164
	 *
165
	 * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object
166
	 * @return \Aimeos\MShop\Order\Item\Iface Updated order item object
167
	 */
168
	public function transfer( \Aimeos\MShop\Order\Item\Iface $order ) : \Aimeos\MShop\Order\Item\Iface
169
	{
170
		$msg = $this->getContext()->translate( 'mshop', 'Method "%1$s" for provider not available' );
171
		throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, 'transfer' ) );
172
	}
173
}
174