TransferBuilder.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Gateway\Http;
  7. /**
  8. * Class TransferBuilder
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class TransferBuilder
  13. {
  14. /**
  15. * @var array
  16. */
  17. private $clientConfig = [];
  18. /**
  19. * @var array
  20. */
  21. private $headers = [];
  22. /**
  23. * @var string
  24. */
  25. private $method;
  26. /**
  27. * @var array|string
  28. */
  29. private $body = [];
  30. /**
  31. * @var string
  32. */
  33. private $uri = '';
  34. /**
  35. * @var bool
  36. */
  37. private $encode = false;
  38. /**
  39. * @var array
  40. */
  41. private $auth = [Transfer::AUTH_USERNAME => null, Transfer::AUTH_PASSWORD => null];
  42. /**
  43. * @param array $clientConfig
  44. * @return $this
  45. */
  46. public function setClientConfig(array $clientConfig)
  47. {
  48. $this->clientConfig = $clientConfig;
  49. return $this;
  50. }
  51. /**
  52. * @param array $headers
  53. * @return $this
  54. */
  55. public function setHeaders(array $headers)
  56. {
  57. $this->headers = $headers;
  58. return $this;
  59. }
  60. /**
  61. * @param array|string $body
  62. * @return $this
  63. */
  64. public function setBody($body)
  65. {
  66. $this->body = $body;
  67. return $this;
  68. }
  69. /**
  70. * @param string $username
  71. * @return $this
  72. */
  73. public function setAuthUsername($username)
  74. {
  75. $this->auth[Transfer::AUTH_USERNAME] = $username;
  76. return $this;
  77. }
  78. /**
  79. * @param string $password
  80. * @return $this
  81. */
  82. public function setAuthPassword($password)
  83. {
  84. $this->auth[Transfer::AUTH_PASSWORD] = $password;
  85. return $this;
  86. }
  87. /**
  88. * @param string $method
  89. * @return $this
  90. */
  91. public function setMethod($method)
  92. {
  93. $this->method = $method;
  94. return $this;
  95. }
  96. /**
  97. * @param string $uri
  98. * @return $this
  99. */
  100. public function setUri($uri)
  101. {
  102. $this->uri = $uri;
  103. return $this;
  104. }
  105. /**
  106. * @param bool $encode
  107. * @return $this
  108. */
  109. public function shouldEncode($encode)
  110. {
  111. $this->encode = $encode;
  112. return $this;
  113. }
  114. /**
  115. * @return TransferInterface
  116. */
  117. public function build()
  118. {
  119. return new Transfer(
  120. $this->clientConfig,
  121. $this->headers,
  122. $this->body,
  123. $this->auth,
  124. $this->method,
  125. $this->uri,
  126. $this->encode
  127. );
  128. }
  129. }