DocumentUploadGateway.php
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Braintree;
use InvalidArgumentException;
/**
 * Braintree DisputeGateway module
 * PHP Version 5
 * Creates and manages Braintree Disputes
 *
 * @package   Braintree
 */
class DocumentUploadGateway
{
    /**
     * @var Gateway
     */
    private $_gateway;
    /**
     * @var Configuration
     */
    private $_config;
    /**
     * @var Http
     */
    private $_http;
    /**
     * @param Gateway $gateway
     */
    public function __construct($gateway)
    {
        $this->_gateway = $gateway;
        $this->_config = $gateway->config;
        $this->_config->assertHasAccessTokenOrKeys();
        $this->_http = new Http($gateway->config);
    }
    /* public class methods */
    /**
     * Accepts a dispute, given a dispute ID
     *
     * @param string $id
     */
    public function create($params)
    {
        Util::verifyKeys(self::createSignature(), $params);
        $file = $params['file'];
        if (!is_resource($file)) {
            throw new InvalidArgumentException('file must be a stream resource');
        }
        $payload = [
            'document_upload[kind]' => $params['kind']
        ];
        $path = $this->_config->merchantPath() . '/document_uploads/';
        $response = $this->_http->postMultipart($path, $payload, $file);
        if (isset($response['apiErrorResponse'])) {
            return new Result\Error($response['apiErrorResponse']);
        }
        if (isset($response['documentUpload'])) {
            $documentUpload = DocumentUpload::factory($response['documentUpload']);
            return new Result\Successful($documentUpload);
        }
    }
    public static function createSignature()
    {
        return [
            'file', 'kind'
        ];
    }
}
class_alias('Braintree\DocumentUploadGateway', 'Braintree_DocumentUploadGateway');