Completed
Pull Request — master (#4)
by Cesar
01:51
created

getUserTransactionsFromRefreshToken()   A

Complexity

Conditions 2
Paths 8

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 2
nc 8
nop 1
1
<?php
2
3
namespace App\Service\Paypal;
4
5
use Exception;
6
7
/**
8
 * Class ReportingService
9
 * @package App\Service\Paypal
10
 */
11
class ReportingService extends IdentityService
12
{
13
    /**
14
     * @param string $refreshToken
15
     * @return bool|string|null
16
     */
17
    public function getUserTransactionsFromRefreshToken(string $refreshToken)
18
    {
19
        try {
20
            $tokenInfo = $this->refreshToken($refreshToken);
21
            $ch = curl_init();
22
            curl_setopt(
23
                $ch,
24
                CURLOPT_URL,
25
                "https://api.sandbox.paypal.com/v1/reporting/transactions?start_date=" .
26
                date('Y-m-d', strtotime('5 days ago')) . 'T00:00:00-0700' .
27
                "&end_date=" . date('Y-m-d', strtotime('now')) . 'T00:00:00-0700'
28
            );
29
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
30
            curl_setopt($ch, CURLOPT_HTTPHEADER, [
31
                'Content-Type: application/json',
32
                'Authorization: Bearer ' . $tokenInfo->getAccessToken(),
33
            ]);
34
            $userTransactions = curl_exec($ch);
35
            curl_close($ch);
36
        } catch (Exception $e) {
37
            $this->logger->error('Error on PayPal::getUserTransactionsFromRefreshToken = ' . $e->getMessage());
38
            return null;
39
        }
40
        return json_decode($userTransactions);
41
    }
42
}
43