Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 8c03c93

Browse files
author
Kleyton Basilio Pilon
committed
feat(Transfers): Added get list, get id, revert and getters
1 parent 636674a commit 8c03c93

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

src/Resource/Transfers.php

+62
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Requests;
66
use stdClass;
7+
use Moip\Helper\Filters;
8+
use Moip\Helper\Pagination;
79

810
/**
911
* Class Transfers.
@@ -118,6 +120,16 @@ public function setTransfers(
118120
return $this;
119121
}
120122

123+
/**
124+
* Returns transfer.
125+
*
126+
* @return stdClass
127+
*/
128+
public function getTransfers()
129+
{
130+
return $this->data;
131+
}
132+
121133
/**
122134
* Set info of holder.
123135
*
@@ -138,6 +150,16 @@ public function setHolder($fullname, $taxDocument)
138150
return $this;
139151
}
140152

153+
/**
154+
* Returns transfer holder.
155+
*
156+
* @return stdClass
157+
*/
158+
public function getHolder()
159+
{
160+
return $this->data->transferInstrument->bankAccount->holder;
161+
}
162+
141163
/**
142164
* Execute Tranfers.
143165
*
@@ -152,6 +174,46 @@ public function execute()
152174
return $this->populate($response);
153175
}
154176

177+
/**
178+
* Revert Tranfers.
179+
*
180+
* @param string $id Transfer id.
181+
*
182+
* @return Transfers
183+
*/
184+
public function revert($id)
185+
{
186+
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $id, 'reverse');
187+
188+
$response = $this->httpRequest($path, Requests::POST, $this);
189+
190+
return $this->populate($response);
191+
}
192+
193+
/**
194+
* Get a Transfer.
195+
*
196+
* @param string $id Transfer id.
197+
*
198+
* @return stdClass
199+
*/
200+
public function get($id)
201+
{
202+
return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $id));
203+
}
204+
205+
/**
206+
* Create a new Transfers list instance.
207+
*
208+
* @return \Moip\Resource\TransfersList
209+
*/
210+
public function getList(Pagination $pagination = null, Filters $filters = null, $qParam = '')
211+
{
212+
$transfersList = new TransfersList($this->moip);
213+
214+
return $transfersList->get($pagination, $filters, $qParam);
215+
}
216+
155217
/**
156218
* Get MoIP Transfers id.
157219
*

src/Resource/TransfersList.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Moip\Resource;
4+
5+
use stdClass;
6+
use Moip\Helper\Filters;
7+
use Moip\Helper\Pagination;
8+
9+
class TransfersList extends MoipResource
10+
{
11+
/**
12+
* Path bank accounts API.
13+
*
14+
* @const string
15+
*/
16+
const PATH = 'transfers';
17+
18+
/**
19+
* Initialize a new instance.
20+
*/
21+
public function initialize()
22+
{
23+
$this->data = new stdClass();
24+
$this->data->transfers = [];
25+
}
26+
27+
/**
28+
* Get transfers.
29+
*
30+
* @return array
31+
*/
32+
public function getTransfers()
33+
{
34+
return $this->getIfSet('transfers');
35+
}
36+
37+
/**
38+
* Get transfer list.
39+
*
40+
* @param Pagination $pagination
41+
* @param Filters $filters
42+
* @param string $qParam Query a specific value.
43+
*
44+
* @return stdClass
45+
*/
46+
public function get(Pagination $pagination = null, Filters $filters = null, $qParam = '')
47+
{
48+
return $this->getByPath($this->generateListPath($pagination, $filters, ['q' => $qParam]));
49+
}
50+
51+
protected function populate(stdClass $response)
52+
{
53+
$transfersList = clone $this;
54+
$transfersList->data = new stdClass();
55+
56+
$transfersList->data->transfers = $response->transfers;
57+
58+
$transfersList->data->summary = $response->summary;
59+
$transfersList->_links = $response->_links;
60+
61+
return $transfersList;
62+
}
63+
}

0 commit comments

Comments
 (0)