|
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: 02/12/2016 |
|
9
|
|
|
* Time: 15:50 |
|
10
|
|
|
* File: KycDocumentQuery.php |
|
11
|
|
|
**/ |
|
12
|
|
|
|
|
13
|
|
|
namespace PartFire\MangoPayBundle\Models\Adapters; |
|
14
|
|
|
|
|
15
|
|
|
use MangoPay\MangoPayApi; |
|
16
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\KycDocument; |
|
17
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\Translators\KycDocumentTranslator; |
|
18
|
|
|
use PartFire\MangoPayBundle\Models\KycDocumentQueryInterface; |
|
19
|
|
|
use Symfony\Bridge\Monolog\Logger; |
|
20
|
|
|
use MangoPay\Libraries\ResponseException; |
|
21
|
|
|
use MangoPay\Libraries\Exception; |
|
22
|
|
|
use PartFire\MangoPayBundle\Models\Exception as PartFireException; |
|
23
|
|
|
|
|
24
|
|
|
class KycDocumentQuery extends AbstractQuery implements KycDocumentQueryInterface |
|
25
|
|
|
{ |
|
26
|
|
|
protected $kycDocumentTranslator; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct( |
|
29
|
|
|
$clientId, |
|
30
|
|
|
$clientPassword, |
|
31
|
|
|
$baseUrl, |
|
32
|
|
|
MangoPayApi $mangoPayApi, |
|
33
|
|
|
Logger $logger, |
|
34
|
|
|
KycDocumentTranslator $kycDocumentTranslator |
|
35
|
|
|
) { |
|
36
|
|
|
$this->kycDocumentTranslator = $kycDocumentTranslator; |
|
37
|
|
|
parent::__construct($clientId, $clientPassword, $baseUrl,$mangoPayApi, $logger); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function create(KycDocument $kycDocumentDto, $shouldSubmit = false) |
|
41
|
|
|
{ |
|
42
|
|
|
$mangoKycDocument = $this->kycDocumentTranslator->convertDTOToMangoKycDocument($kycDocumentDto); |
|
43
|
|
|
try { |
|
44
|
|
|
$UserId = $kycDocumentDto->getOwnerId(); |
|
45
|
|
|
if ($shouldSubmit) { |
|
46
|
|
|
$mangoKycDocument->Status = "VALIDATION_ASKED"; |
|
47
|
|
|
} |
|
48
|
|
|
$mangoKycDocument = $this->mangoPayApi->Users->CreateKycDocument($UserId, $mangoKycDocument); |
|
49
|
|
|
|
|
50
|
|
|
} catch(ResponseException $e) { |
|
51
|
|
|
$this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]); |
|
52
|
|
|
return new PartFireException($e->getMessage(), $e->getCode()); |
|
53
|
|
|
} catch(Exception $e) { |
|
54
|
|
|
$this->logger->addError($e->getMessage()); |
|
55
|
|
|
return new PartFireException($e->getMessage(), $e->getCode()); |
|
56
|
|
|
} |
|
57
|
|
|
return $this->kycDocumentTranslator->convertMangoPayKycDocumentToDTO($mangoKycDocument); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function submit(KycDocument $kycDocumentDto) |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->create($kycDocumentDto, true); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
View Code Duplication |
public function get(int $kycDocumentId) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
try { |
|
68
|
|
|
$mangoKycDocument = $this->mangoPayApi->Users->GetKycDocument($kycDocumentId); |
|
|
|
|
|
|
69
|
|
|
} catch(ResponseException $e) { |
|
70
|
|
|
$this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]); |
|
71
|
|
|
return new PartFireException($e->getMessage(), $e->getCode()); |
|
72
|
|
|
} catch(Exception $e) { |
|
73
|
|
|
$this->logger->addError($e->getMessage()); |
|
74
|
|
|
return new PartFireException($e->getMessage(), $e->getCode()); |
|
75
|
|
|
} |
|
76
|
|
|
return $this->kycDocumentTranslator->convertMangoPayKycDocumentToDTO($mangoKycDocument); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
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.