CurrencyValidator.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Payment\Gateway\Validator;
  17. use Magento\Payment\Gateway\Validator\AbstractValidator;
  18. use Magento\Payment\Gateway\ConfigInterface;
  19. use Magento\Payment\Gateway\Validator\ResultInterfaceFactory;
  20. use Amazon\Core\Helper\Data;
  21. /**
  22. * Class CurrencyValidator
  23. * Validates allowable currencies for Amazon Pay
  24. */
  25. class CurrencyValidator extends AbstractValidator
  26. {
  27. /**
  28. * @var \Magento\Payment\Gateway\ConfigInterface
  29. */
  30. private $config;
  31. /**
  32. * @var Data
  33. */
  34. private $coreHelper;
  35. /**
  36. * CurrencyValidator constructor.
  37. *
  38. * @param ResultInterfaceFactory $resultFactory
  39. * @param ConfigInterface $config
  40. * @param Data $coreHelper
  41. */
  42. public function __construct(
  43. ResultInterfaceFactory $resultFactory,
  44. ConfigInterface $config,
  45. Data $coreHelper
  46. ) {
  47. $this->coreHelper = $coreHelper;
  48. $this->config = $config;
  49. parent::__construct($resultFactory);
  50. }
  51. /**
  52. * @param array $validationSubject
  53. * @return \Magento\Payment\Gateway\Validator\ResultInterface
  54. */
  55. public function validate(array $validationSubject)
  56. {
  57. $allowedCurrency = $this->coreHelper->getCurrencyCode('store', $validationSubject['storeId']);
  58. if ($allowedCurrency == $validationSubject['currency']) {
  59. return $this->createResult(
  60. true,
  61. ['status' => 200]
  62. );
  63. }
  64. return $this->createResult(
  65. false,
  66. [__('The currency selected is not supported by Amazon Pay.')]
  67. );
  68. }
  69. }