1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Carl Owens ([email protected]) |
4
|
|
|
* Company: PartFire Ltd (www.partfire.co.uk) |
5
|
|
|
* Copyright © 2016 PartFire Ltd. All rights reserved. |
6
|
|
|
* |
7
|
|
|
* User: Carl Owens |
8
|
|
|
* Date: 06/12/2016 |
9
|
|
|
* Time: 22:41 |
10
|
|
|
* File: TransferQuery.php |
11
|
|
|
**/ |
12
|
|
|
|
13
|
|
|
namespace PartFire\MangoPayBundle\Models\Adapters; |
14
|
|
|
|
15
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\Transfer; |
16
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\Translators\TransferTranslator; |
17
|
|
|
use PartFire\MangoPayBundle\Models\TransferQueryInterface; |
18
|
|
|
use MangoPay\Libraries\ResponseException; |
19
|
|
|
use MangoPay\Libraries\Exception; |
20
|
|
|
use PartFire\MangoPayBundle\Models\Exception as PartFireException; |
21
|
|
|
use Symfony\Bridge\Monolog\Logger; |
22
|
|
|
use MangoPay\MangoPayApi; |
23
|
|
|
|
24
|
|
|
class TransferQuery extends AbstractQuery implements TransferQueryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var TransferTranslator |
28
|
|
|
*/ |
29
|
|
|
protected $transferTranslator; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* TransferQuery constructor. |
33
|
|
|
* @param $clientId |
34
|
|
|
* @param $clientPassword |
35
|
|
|
* @param $baseUrl |
36
|
|
|
* @param MangoPayApi $mangoPayApi |
37
|
|
|
* @param Logger $logger |
38
|
|
|
* @param TransferTranslator $transferTranslator |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
$clientId, |
42
|
|
|
$clientPassword, |
43
|
|
|
$baseUrl, |
44
|
|
|
MangoPayApi $mangoPayApi, |
45
|
|
|
Logger $logger, |
46
|
|
|
TransferTranslator $transferTranslator |
47
|
|
|
) { |
48
|
|
|
parent::__construct($clientId, $clientPassword, $baseUrl, $mangoPayApi, $logger); |
49
|
|
|
$this->transferTranslator = $transferTranslator; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Transfer $transferDto |
54
|
|
|
* @return Transfer|PartFireException |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function create(Transfer $transferDto) |
57
|
|
|
{ |
58
|
|
|
$mangoTransfer = $this->transferTranslator->convertDTOToMangoPayTransfer($transferDto); |
59
|
|
|
try { |
60
|
|
|
$mangoTransfer = $this->mangoPayApi->Transfers->Create($mangoTransfer); |
61
|
|
|
} catch (ResponseException $e) { |
62
|
|
|
$this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]); |
63
|
|
|
return new PartFireException($e->getMessage(), $e->getCode()); |
64
|
|
|
} catch (Exception $e) { |
65
|
|
|
$this->logger->addError($e->getMessage()); |
66
|
|
|
return new PartFireException($e->getMessage(), $e->getCode()); |
67
|
|
|
} |
68
|
|
|
return $this->transferTranslator->convertMangoPayTransferToDTO($mangoTransfer); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
public function get(string $transferId) : Transfer |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
try { |
74
|
|
|
$mangoTransfer = $this->mangoPayApi->Transfers->Get($transferId); |
75
|
|
|
} catch (ResponseException $e) { |
76
|
|
|
$this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]); |
77
|
|
|
return new PartFireException($e->getMessage(), $e->getCode()); |
78
|
|
|
} catch (Exception $e) { |
79
|
|
|
$this->logger->addError($e->getMessage()); |
80
|
|
|
return new PartFireException($e->getMessage(), $e->getCode()); |
81
|
|
|
} |
82
|
|
|
return $this->transferTranslator->convertMangoPayKycDocumentToDTO($mangoTransfer); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.