Passed
Push — v3.0 ( 8d7778...582152 )
by Raza
01:45
created

DisputesActions::provideDisputeEvidence()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 22
rs 9.9
cc 3
nc 4
nop 2
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
use GuzzleHttp\Psr7;
6
use Srmklive\PayPal\Services\VerifyDocuments;
7
8
trait DisputesActions
9
{
10
    /**
11
     * Acknowledge item has been returned.
12
     *
13
     * @param string $dispute_id
14
     * @param string $dispute_note
15
     * @param string $acknowledgement_type
16
     *
17
     * @throws \Throwable
18
     *
19
     * @return array|\Psr\Http\Message\StreamInterface|string
20
     *
21
     * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_acknowledge-return-item
22
     */
23
    public function acknowledgeItemReturned(string $dispute_id, string $dispute_note, string $acknowledgement_type)
24
    {
25
        $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/acknowledge-return-item";
26
27
        $this->options['json'] = [
28
            'note'                  => $dispute_note,
29
            'acknowledgement_type'  => $acknowledgement_type,
30
        ];
31
32
        $this->verb = 'post';
33
34
        return $this->doPayPalRequest();
35
    }
36
37
    /**
38
     * Providence evidence in support of a dispute.
39
     *
40
     * @param string $dispute_id
41
     * @param array  $file_path
42
     *
43
     * @throws \Throwable
44
     *
45
     * @return array|\Psr\Http\Message\StreamInterface|string
46
     *
47
     * https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_provide-evidence 
48
     */
49
    public function provideDisputeEvidence(string $dispute_id, array $files)
50
    {
51
        if (VerifyDocuments::isValidEvidenceFile($files) === false) {
52
            $this->throwInvalidEvidenceFileException();
0 ignored issues
show
Bug introduced by
It seems like throwInvalidEvidenceFileException() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
            $this->/** @scrutinizer ignore-call */ 
53
                   throwInvalidEvidenceFileException();
Loading history...
53
        }
54
55
        $this->apiEndPoint = "/v1/customer/disputes/{$dispute_id}/provide-evidence";
56
57
        $this->setRequestHeader('Content-Type', 'multipart/form-data');
0 ignored issues
show
Bug introduced by
It seems like setRequestHeader() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        $this->/** @scrutinizer ignore-call */ 
58
               setRequestHeader('Content-Type', 'multipart/form-data');
Loading history...
58
59
        $this->options['multipart'] = [];
60
61
        foreach ($files as $file) {
62
            $this->options['multipart'][] = [
63
                'name'     => basename($file),
64
                'contents' => Psr7\Utils::tryFopen($file, 'r'),
65
            ];
66
        }
67
68
        $this->verb = 'post';
69
70
        return $this->doPayPalRequest();        
71
    }
72
73
    /**
74
     * Accept customer dispute claim.
75
     *
76
     * @param string $dispute_id
77
     * @param string $dispute_note
78
     * @param array  $data
79
     *
80
     * @throws \Throwable
81
     *
82
     * @return array|\Psr\Http\Message\StreamInterface|string
83
     *
84
     * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_accept-claim
85
     */
86
    public function acceptDisputeClaim(string $dispute_id, string $dispute_note, array $data = [])
87
    {
88
        $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-claim";
89
90
        $data['note'] = $dispute_note;
91
        $data['accept_claim_type'] = 'REFUND';
92
93
        $this->options['json'] = $data;
94
95
        $this->verb = 'post';
96
97
        return $this->doPayPalRequest();
98
    }
99
100
    /**
101
     * Accept offer to resolve dispute.
102
     *
103
     * @param string $dispute_id
104
     * @param string $dispute_note
105
     *
106
     * @throws \Throwable
107
     *
108
     * @return array|\Psr\Http\Message\StreamInterface|string
109
     *
110
     * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes-actions_accept-offer
111
     */
112
    public function acceptDisputeOfferResolution(string $dispute_id, string $dispute_note)
113
    {
114
        $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-offer";
115
116
        $this->options['json'] = [
117
            'note'  => $dispute_note,
118
        ];
119
120
        $this->verb = 'post';
121
122
        return $this->doPayPalRequest();
123
    }
124
}
125