PaymentMethodNonceGateway.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Braintree;
  3. /**
  4. * Braintree PaymentMethodNonceGateway module
  5. *
  6. * @package Braintree
  7. * @category Resources
  8. */
  9. /**
  10. * Creates and manages Braintree PaymentMethodNonces
  11. *
  12. * <b>== More information ==</b>
  13. *
  14. *
  15. * @package Braintree
  16. * @category Resources
  17. */
  18. class PaymentMethodNonceGateway
  19. {
  20. private $_gateway;
  21. private $_config;
  22. private $_http;
  23. public function __construct($gateway)
  24. {
  25. $this->_gateway = $gateway;
  26. $this->_config = $gateway->config;
  27. $this->_http = new Http($gateway->config);
  28. }
  29. public function create($token)
  30. {
  31. $subPath = '/payment_methods/' . $token . '/nonces';
  32. $fullPath = $this->_config->merchantPath() . $subPath;
  33. $response = $this->_http->post($fullPath);
  34. return new Result\Successful(
  35. PaymentMethodNonce::factory($response['paymentMethodNonce']),
  36. "paymentMethodNonce"
  37. );
  38. }
  39. /**
  40. * @access public
  41. *
  42. */
  43. public function find($nonce)
  44. {
  45. try {
  46. $path = $this->_config->merchantPath() . '/payment_method_nonces/' . $nonce;
  47. $response = $this->_http->get($path);
  48. return PaymentMethodNonce::factory($response['paymentMethodNonce']);
  49. } catch (Exception\NotFound $e) {
  50. throw new Exception\NotFound(
  51. 'payment method nonce with id ' . $nonce . ' not found'
  52. );
  53. }
  54. }
  55. }
  56. class_alias('Braintree\PaymentMethodNonceGateway', 'Braintree_PaymentMethodNonceGateway');