ApplePayGateway.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Braintree;
  3. /**
  4. * Braintree ApplePayGateway module
  5. * Manages Apple Pay for Web
  6. *
  7. * @package Braintree
  8. * @category Resources
  9. */
  10. class ApplePayGateway
  11. {
  12. private $_gateway;
  13. private $_config;
  14. private $_http;
  15. public function __construct($gateway)
  16. {
  17. $this->_gateway = $gateway;
  18. $this->_config = $gateway->config;
  19. $this->_config->assertHasAccessTokenOrKeys();
  20. $this->_http = new Http($gateway->config);
  21. }
  22. public function registerDomain($domain)
  23. {
  24. $path = $this->_config->merchantPath() . '/processing/apple_pay/validate_domains';
  25. $response = $this->_http->post($path, ['url' => $domain]);
  26. if (array_key_exists('response', $response) && $response['response']['success'])
  27. {
  28. return new Result\Successful;
  29. }
  30. else if (array_key_exists('apiErrorResponse', $response))
  31. {
  32. return new Result\Error($response['apiErrorResponse']);
  33. }
  34. }
  35. public function unregisterDomain($domain)
  36. {
  37. $path = $this->_config->merchantPath() . '/processing/apple_pay/unregister_domain';
  38. $this->_http->delete($path, ['url' => $domain]);
  39. return new Result\Successful;
  40. }
  41. public function registeredDomains()
  42. {
  43. $path = $this->_config->merchantPath() . '/processing/apple_pay/registered_domains';
  44. $response = $this->_http->get($path);
  45. if (array_key_exists('response', $response) && array_key_exists('domains', $response['response']))
  46. {
  47. $options = ApplePayOptions::factory($response['response']);
  48. return new Result\Successful($options, 'applePayOptions');
  49. }
  50. else if (array_key_exists('apiErrorResponse', $response))
  51. {
  52. return new Result\Error($response['apiErrorResponse']);
  53. }
  54. else
  55. {
  56. throw new Exception\Unexpected('expected response or apiErrorResponse');
  57. }
  58. }
  59. }
  60. class_alias('Braintree\ApplePayGateway', 'Braintree_ApplePayGateway');