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-2016 |
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
|
|
|
* Updates the orders for which status updates were received via direct requests (like HTTP). |
130
|
|
|
* |
131
|
|
|
* @param array $params Associative list of request parameters |
132
|
|
|
* @param string|null $body Information sent within the body of the request |
133
|
|
|
* @param string|null &$response Response body for notification requests |
134
|
|
|
* @param array &$header Response headers for notification requests |
135
|
|
|
* @return \Aimeos\MShop\Order\Item\Iface|null Order item if update was successful, null if the given parameters are not valid for this provider |
136
|
|
|
* @throws \Aimeos\MShop\Service\Exception If updating one of the orders failed |
137
|
|
|
*/ |
138
|
|
|
public function updateSync( array $params = [], $body = null, &$response = null, array &$header = [] ) |
139
|
|
|
{ |
140
|
|
|
if( isset( $params['orderid'] ) ) |
141
|
|
|
{ |
142
|
|
|
$order = $this->getOrder( $params['orderid'] ); |
143
|
|
|
$order->setPaymentStatus( \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED ); |
144
|
|
|
$this->saveOrder( $order ); |
145
|
|
|
|
146
|
|
|
return $order; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
} |