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: 28/11/2016 |
9
|
|
|
* Time: 16:34 |
10
|
|
|
* File: WalletQuery.php |
11
|
|
|
**/ |
12
|
|
|
|
13
|
|
|
namespace PartFire\MangoPayBundle\Models\Adapters; |
14
|
|
|
|
15
|
|
|
use MangoPay\Libraries\Exception; |
16
|
|
|
use MangoPay\Libraries\ResponseException; |
17
|
|
|
use MangoPay\MangoPayApi; |
18
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\Translators\WalletTranslator; |
19
|
|
|
use PartFire\MangoPayBundle\Models\DTOs\Wallet; |
20
|
|
|
use PartFire\MangoPayBundle\Models\WalletQueryInterface; |
21
|
|
|
use PartFire\MangoPayBundle\Models\Exception as PartFireException; |
22
|
|
|
use Symfony\Bridge\Monolog\Logger; |
23
|
|
|
|
24
|
|
|
class WalletQuery extends AbstractQuery implements WalletQueryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var WalletTranslator |
28
|
|
|
*/ |
29
|
|
|
protected $walletTranslator; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* WalletQuery constructor. |
33
|
|
|
* @param $clientId |
34
|
|
|
* @param $clientPassword |
35
|
|
|
* @param $baseUrl |
36
|
|
|
* @param MangoPayApi $mangoPayApi |
37
|
|
|
* @param Logger $logger |
38
|
|
|
* @param WalletTranslator $walletTranslator |
39
|
|
|
*/ |
40
|
|
|
public function __construct( |
41
|
|
|
$clientId, |
42
|
|
|
$clientPassword, |
43
|
|
|
$baseUrl, |
44
|
|
|
MangoPayApi $mangoPayApi, |
45
|
|
|
Logger $logger, |
46
|
|
|
WalletTranslator $walletTranslator |
47
|
|
|
) { |
48
|
|
|
parent::__construct($clientId, $clientPassword, $baseUrl,$mangoPayApi, $logger); |
49
|
|
|
$this->walletTranslator = $walletTranslator; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function create(Wallet $walletDto) |
53
|
|
|
{ |
54
|
|
|
$mangoWallet = $this->walletTranslator->convertDTOToMangoPayWallet($walletDto); |
55
|
|
|
try { |
56
|
|
|
$mangoWallet = $this->mangoPayApi->Wallets->Create($mangoWallet); |
57
|
|
|
} catch(ResponseException $e) { |
58
|
|
|
$this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]); |
59
|
|
|
throw new PartFireException($e->getMessage(), $e->getCode(), $e); |
60
|
|
|
} catch(Exception $e) { |
61
|
|
|
$this->logger->addError($e->getMessage()); |
62
|
|
|
throw new PartFireException($e->getMessage(), $e->getCode(), $e); |
63
|
|
|
} |
64
|
|
|
return $this->walletTranslator->convertMangoPayWalletToDTO($mangoWallet); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function get($walletId) |
68
|
|
|
{ |
69
|
|
|
try { |
70
|
|
|
$mangoWallet = $this->mangoPayApi->Wallets->Get($walletId); |
71
|
|
|
} catch(ResponseException $e) { |
72
|
|
|
$this->logger->addCritical($e->getMessage(), ['code' => $e->getCode(), 'details' => $e->GetErrorDetails()]); |
73
|
|
|
throw new PartFireException($e->getMessage(), $e->getCode(), $e); |
74
|
|
|
} catch(Exception $e) { |
75
|
|
|
$this->logger->addError($e->getMessage()); |
76
|
|
|
throw new PartFireException($e->getMessage(), $e->getCode(), $e); |
77
|
|
|
} |
78
|
|
|
return $this->walletTranslator->convertMangoPayWalletToDTO($mangoWallet); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getAll() |
82
|
|
|
{ |
83
|
|
|
// TODO: Implement getAll() method. |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function delete($walletId) |
87
|
|
|
{ |
88
|
|
|
// TODO: Implement delete() method. |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|