| 676 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Srmklive\PayPal\Traits\PayPalAPI;
|
|
|
4 |
|
|
|
5 |
use Carbon\Carbon;
|
|
|
6 |
|
|
|
7 |
trait Reporting
|
|
|
8 |
{
|
|
|
9 |
/**
|
|
|
10 |
* List all transactions.
|
|
|
11 |
*
|
|
|
12 |
* @param array $filters
|
|
|
13 |
* @param string $fields
|
|
|
14 |
* @param int $page
|
|
|
15 |
* @param int $page_size
|
|
|
16 |
*
|
|
|
17 |
* @throws \Throwable
|
|
|
18 |
*
|
|
|
19 |
* @return array|\Psr\Http\Message\StreamInterface|string
|
|
|
20 |
*
|
|
|
21 |
* @see https://developer.paypal.com/docs/api/transaction-search/v1/#transactions_get
|
|
|
22 |
*/
|
|
|
23 |
public function listTransactions(array $filters, string $fields = 'all', int $page = 1, int $page_size = 100)
|
|
|
24 |
{
|
|
|
25 |
$filters_list = collect($filters)->isEmpty() ? '' :
|
|
|
26 |
collect($filters)->map(function ($value, $key) {
|
|
|
27 |
return "{$key}={$value}&";
|
|
|
28 |
})->implode('');
|
|
|
29 |
|
|
|
30 |
$this->apiEndPoint = "v1/reporting/transactions?{$filters_list}fields={$fields}&page={$page}&page_size={$page_size}";
|
|
|
31 |
|
|
|
32 |
$this->verb = 'get';
|
|
|
33 |
|
|
|
34 |
return $this->doPayPalRequest();
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* List available balance.
|
|
|
39 |
*
|
|
|
40 |
* @param string $date
|
|
|
41 |
* @param string $balance_currency
|
|
|
42 |
*
|
|
|
43 |
* @throws \Throwable
|
|
|
44 |
*
|
|
|
45 |
* @return array|\Psr\Http\Message\StreamInterface|string
|
|
|
46 |
*
|
|
|
47 |
* @see https://developer.paypal.com/docs/api/transaction-search/v1/#balances_get
|
|
|
48 |
*/
|
|
|
49 |
public function listBalances(string $date = '', string $balance_currency = '')
|
|
|
50 |
{
|
|
|
51 |
$date = empty($date) ? Carbon::now()->toIso8601String() : Carbon::parse($date)->toIso8601String();
|
|
|
52 |
$currency = empty($balance_currency) ? $this->getCurrency() : $balance_currency;
|
|
|
53 |
|
|
|
54 |
$this->apiEndPoint = "v1/reporting/balances?currency_code={$currency}&as_of_time={$date}";
|
|
|
55 |
|
|
|
56 |
$this->verb = 'get';
|
|
|
57 |
|
|
|
58 |
return $this->doPayPalRequest();
|
|
|
59 |
}
|
|
|
60 |
}
|