|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* NOTICE OF LICENSE |
|
5
|
|
|
* |
|
6
|
|
|
* This source file is subject to the GNU General Public License (GPL 3) |
|
7
|
|
|
* that is bundled with this package in the file LICENSE.txt |
|
8
|
|
|
* |
|
9
|
|
|
* DISCLAIMER |
|
10
|
|
|
* |
|
11
|
|
|
* Do not edit or add to this file if you wish to upgrade Payone to newer |
|
12
|
|
|
* versions in the future. If you wish to customize Payone for your |
|
13
|
|
|
* needs please refer to http://www.payone.de for more information. |
|
14
|
|
|
* |
|
15
|
|
|
* @category Payone |
|
16
|
|
|
* @package Payone_Api |
|
17
|
|
|
* @subpackage Mapper |
|
18
|
|
|
* @copyright Copyright (c) 2012 <[email protected]> - www.noovias.com |
|
19
|
|
|
* @author Matthias Walter <[email protected]> |
|
20
|
|
|
* @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3) |
|
21
|
|
|
* @link http://www.noovias.com |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* |
|
26
|
|
|
* @category Payone |
|
27
|
|
|
* @package Payone_Api |
|
28
|
|
|
* @subpackage Mapper |
|
29
|
|
|
* @copyright Copyright (c) 2012 <[email protected]> - www.noovias.com |
|
30
|
|
|
* @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3) |
|
31
|
|
|
* @link http://www.noovias.com |
|
32
|
|
|
*/ |
|
33
|
|
|
abstract class Payone_Api_Mapper_Request_Payment_Abstract |
|
34
|
|
|
extends Payone_Api_Mapper_Request_Abstract |
|
35
|
|
|
implements Payone_Api_Mapper_Request_Interface |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @param Payone_Api_Request_Interface $request |
|
39
|
|
|
* @return bool |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function mapAmount(Payone_Api_Request_Interface $request) |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var $request Payone_Api_Request_Authorization */ |
|
44
|
|
|
$amount = $request->getAmount(); |
|
45
|
|
|
$currency = $request->getCurrency(); |
|
46
|
|
|
|
|
47
|
|
|
$mappedAmount = $this->getMapperCurrency()->mapAmountToSub($amount, $currency); |
|
48
|
|
|
|
|
49
|
|
|
$request->setAmount($mappedAmount); |
|
50
|
|
|
|
|
51
|
|
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @todo we should introduce an Request_Payment_Interface |
|
56
|
|
|
* |
|
57
|
|
|
* @param Payone_Api_Request_Interface $request |
|
58
|
|
|
* @return bool |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function mapInvoicingData(Payone_Api_Request_Interface $request) |
|
61
|
|
|
{ |
|
62
|
|
|
/** @var $invoicing Payone_Api_Request_Parameter_Invoicing_Transaction */ |
|
63
|
|
|
$invoicing = $request->getInvoicing(); |
|
|
|
|
|
|
64
|
|
|
if ($invoicing == null) { |
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if ($invoicing->hasItems()) { |
|
69
|
|
|
/** @var $request Payone_Api_Request_Authorization */ |
|
70
|
|
|
$currency = $request->getCurrency(); |
|
71
|
|
|
$invoicingItems = $invoicing->getItems(); |
|
72
|
|
|
foreach ($invoicingItems as $item) { |
|
73
|
|
|
/** @var $item Payone_Api_Request_Parameter_Invoicing_Item */ |
|
74
|
|
|
$price = $item->getPr(); |
|
75
|
|
|
$mappedPrice = $this->getMapperCurrency()->mapAmountToSub($price, $currency); |
|
76
|
|
|
$item->setPr($mappedPrice); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return true; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: