1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PH\Bundle\PayumBundle\Action\Mollie\SepaDirectDebit; |
6
|
|
|
|
7
|
|
|
use PayHelper\Payum\Mollie\Constants; |
8
|
|
|
use PayHelper\Payum\Mollie\Request\Api\CreateSepaOneOffPayment; |
9
|
|
|
use Payum\Core\Action\ActionInterface; |
10
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
11
|
|
|
use Payum\Core\Exception\LogicException; |
12
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
13
|
|
|
use Payum\Core\GatewayAwareInterface; |
14
|
|
|
use Payum\Core\GatewayAwareTrait; |
15
|
|
|
use Payum\Core\Model\BankAccountInterface; |
16
|
|
|
use Payum\Core\Security\SensitiveValue; |
17
|
|
|
use PH\Bundle\PayumBundle\Request\ObtainBankAccount; |
18
|
|
|
|
19
|
|
|
class SepaOneOffObtainBankAccountAction implements ActionInterface, GatewayAwareInterface |
20
|
|
|
{ |
21
|
|
|
use GatewayAwareTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function execute($request) |
27
|
|
|
{ |
28
|
|
|
RequestNotSupportedException::assertSupports($this, $request); |
29
|
|
|
|
30
|
|
|
$model = ArrayObject::ensureArrayObject($request->getModel()); |
31
|
|
|
|
32
|
|
|
if (!$model->validateNotEmpty(['sepaIban', 'sepaHolder'], false)) { |
33
|
|
|
try { |
34
|
|
|
$obtainBankAccount = new ObtainBankAccount($request->getToken()); |
35
|
|
|
$obtainBankAccount->setModel($request->getModel()); |
36
|
|
|
$this->gateway->execute($obtainBankAccount); |
37
|
|
|
|
38
|
|
|
/** @var BankAccountInterface $bankAccount */ |
39
|
|
|
$bankAccount = $obtainBankAccount->obtain(); |
40
|
|
|
|
41
|
|
|
$model['sepaIban'] = SensitiveValue::ensureSensitive($bankAccount->getIban()); |
42
|
|
|
$model['sepaHolder'] = SensitiveValue::ensureSensitive($bankAccount->getHolder()); |
43
|
|
|
|
44
|
|
|
$this->gateway->execute(new CreateSepaOneOffPayment($model)); |
45
|
|
|
} catch (RequestNotSupportedException $e) { |
46
|
|
|
throw new LogicException('Bank account details has to be set explicitly or there has to be an action that supports ObtainBankAccount request.'); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
View Code Duplication |
public function supports($request) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
return |
57
|
|
|
$request instanceof CreateSepaOneOffPayment && |
58
|
|
|
$request->getModel() instanceof \ArrayAccess && |
59
|
|
|
Constants::METHOD_DIRECTDEBIT_ONEOFF === $request->getModel()['method'] && |
60
|
|
|
!isset($request->getModel()['sepaIban']) && |
61
|
|
|
!isset($request->getModel()['sepaHolder']) |
62
|
|
|
; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.