1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Service |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Service\Provider\Payment; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Payment provider for direct debit orders. |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Service |
20
|
|
|
*/ |
21
|
|
|
class DirectDebit |
22
|
|
|
extends \Aimeos\MShop\Service\Provider\Payment\Base |
|
|
|
|
23
|
|
|
implements \Aimeos\MShop\Service\Provider\Payment\Iface |
24
|
|
|
{ |
25
|
|
|
private $feConfig = array( |
26
|
|
|
'directdebit.accountowner' => array( |
27
|
|
|
'code' => 'directdebit.accountowner', |
28
|
|
|
'internalcode' => 'accountowner', |
29
|
|
|
'label' => 'Account owner', |
30
|
|
|
'type' => 'string', |
31
|
|
|
'internaltype' => 'string', |
32
|
|
|
'default' => '', |
33
|
|
|
'required' => true |
34
|
|
|
), |
35
|
|
|
'directdebit.accountno' => array( |
36
|
|
|
'code' => 'directdebit.accountno', |
37
|
|
|
'internalcode' => 'accountno', |
38
|
|
|
'label' => 'Account number', |
39
|
|
|
'type' => 'string', |
40
|
|
|
'internaltype' => 'string', |
41
|
|
|
'default' => '', |
42
|
|
|
'required' => true |
43
|
|
|
), |
44
|
|
|
'directdebit.bankcode' => array( |
45
|
|
|
'code' => 'directdebit.bankcode', |
46
|
|
|
'internalcode' => 'bankcode', |
47
|
|
|
'label' => 'Bank code', |
48
|
|
|
'type' => 'string', |
49
|
|
|
'internaltype' => 'string', |
50
|
|
|
'default' => '', |
51
|
|
|
'required' => true |
52
|
|
|
), |
53
|
|
|
'directdebit.bankname' => array( |
54
|
|
|
'code' => 'directdebit.bankname', |
55
|
|
|
'internalcode' => 'bankname', |
56
|
|
|
'label' => 'Bank name', |
57
|
|
|
'type' => 'string', |
58
|
|
|
'internaltype' => 'string', |
59
|
|
|
'default' => '', |
60
|
|
|
'required' => true |
61
|
|
|
), |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Returns the configuration attribute definitions of the provider to generate a list of available fields and |
67
|
|
|
* rules for the value of each field in the frontend. |
68
|
|
|
* |
69
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object |
70
|
|
|
* @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface |
71
|
|
|
*/ |
72
|
|
|
public function getConfigFE( \Aimeos\MShop\Order\Item\Base\Iface $basket ) |
73
|
|
|
{ |
74
|
|
|
$feconfig = $this->feConfig; |
75
|
|
|
|
76
|
|
|
try |
77
|
|
|
{ |
78
|
|
|
$address = $basket->getAddress( \Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT ); |
79
|
|
|
|
80
|
|
|
if( ( $fn = $address->getFirstname() ) !== '' && ( $ln = $address->getLastname() ) !== '' ) { |
81
|
|
|
$feconfig['directdebit.accountowner']['default'] = $fn . ' ' . $ln; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
catch( \Aimeos\MShop\Order\Exception $e ) { ; } // If address isn't available |
85
|
|
|
|
86
|
|
|
return $this->getConfigItems( $feconfig ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Checks the frontend configuration attributes for validity. |
92
|
|
|
* |
93
|
|
|
* @param array $attributes Attributes entered by the customer during the checkout process |
94
|
|
|
* @return array An array with the attribute keys as key and an error message as values for all attributes that are |
95
|
|
|
* known by the provider but aren't valid resp. null for attributes whose values are OK |
96
|
|
|
*/ |
97
|
|
|
public function checkConfigFE( array $attributes ) |
98
|
|
|
{ |
99
|
|
|
return $this->checkConfig( $this->feConfig, $attributes ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Sets the payment attributes in the given service. |
105
|
|
|
* |
106
|
|
|
* @param \Aimeos\MShop\Order\Item\Base\Service\Iface $orderServiceItem Order service item that will be added to the basket |
107
|
|
|
* @param array $attributes Attribute key/value pairs entered by the customer during the checkout process |
108
|
|
|
*/ |
109
|
|
|
public function setConfigFE( \Aimeos\MShop\Order\Item\Base\Service\Iface $orderServiceItem, array $attributes ) |
110
|
|
|
{ |
111
|
|
|
$this->setAttributes( $orderServiceItem, $attributes, 'payment' ); |
112
|
|
|
|
113
|
|
|
if( ( $attrItem = $orderServiceItem->getAttributeItem( 'directdebit.accountno', 'payment' ) ) !== null ) |
114
|
|
|
{ |
115
|
|
|
$attrList = array( $attrItem->getCode() => $attrItem->getValue() ); |
116
|
|
|
$this->setAttributes( $orderServiceItem, $attrList, 'payment/hidden' ); |
117
|
|
|
|
118
|
|
|
$value = $attrItem->getValue(); |
119
|
|
|
$len = strlen( $value ); |
120
|
|
|
$xstr = ( $len > 3 ? str_repeat( 'X', $len - 3 ) : '' ); |
121
|
|
|
|
122
|
|
|
$attrItem->setValue( $xstr . substr( $value, -3 ) ); |
123
|
|
|
$orderServiceItem->setAttributeItem( $attrItem ); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Executes the payment again for the given order if supported. |
130
|
|
|
* This requires support of the payment gateway and token based payment |
131
|
|
|
* |
132
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object |
133
|
|
|
* @return void |
134
|
|
|
*/ |
135
|
|
|
public function repay( \Aimeos\MShop\Order\Item\Iface $order ) |
136
|
|
|
{ |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Updates the orders for whose status updates have been received by the confirmation page |
142
|
|
|
* |
143
|
|
|
* @param \Psr\Http\Message\ServerRequestInterface $request Request object with parameters and request body |
144
|
|
|
* @param \Aimeos\MShop\Order\Item\Iface $order Order item that should be updated |
145
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface Updated order item |
146
|
|
|
* @throws \Aimeos\MShop\Service\Exception If updating the orders failed |
147
|
|
|
*/ |
148
|
|
|
public function updateSync( \Psr\Http\Message\ServerRequestInterface $request, \Aimeos\MShop\Order\Item\Iface $order ) |
149
|
|
|
{ |
150
|
|
|
$order->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED ); |
151
|
|
|
$this->saveOrder( $order ); |
152
|
|
|
|
153
|
|
|
return $order; |
154
|
|
|
} |
155
|
|
|
} |