DocumentUploadGateway.php 1.8 KB

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