TestingGateway.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Braintree;
  3. class TestingGateway
  4. {
  5. private $_gateway;
  6. private $_config;
  7. private $_http;
  8. public function __construct($gateway)
  9. {
  10. $this->_gateway = $gateway;
  11. $this->_config = $gateway->config;
  12. $this->_http = new Http($this->_config);
  13. }
  14. public function settle($transactionId)
  15. {
  16. return self::_doTestRequest('/settle', $transactionId);
  17. }
  18. public function settlementPending($transactionId)
  19. {
  20. return self::_doTestRequest('/settlement_pending', $transactionId);
  21. }
  22. public function settlementConfirm($transactionId)
  23. {
  24. return self::_doTestRequest('/settlement_confirm', $transactionId);
  25. }
  26. public function settlementDecline($transactionId)
  27. {
  28. return self::_doTestRequest('/settlement_decline', $transactionId);
  29. }
  30. private function _doTestRequest($testPath, $transactionId)
  31. {
  32. self::_checkEnvironment();
  33. $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . $testPath;
  34. $response = $this->_http->put($path);
  35. return Transaction::factory($response['transaction']);
  36. }
  37. private function _checkEnvironment()
  38. {
  39. if (Configuration::$global->getEnvironment() === 'production') {
  40. throw new Exception\TestOperationPerformedInProduction();
  41. }
  42. }
  43. }
  44. class_alias('Braintree\TestingGateway', 'Braintree_TestingGateway');