PayflowConfig.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model;
  7. use Magento\Payment\Model\Method\AbstractMethod;
  8. /**
  9. * Class PayflowConfig
  10. * @todo ELiminate current configuration class
  11. */
  12. class PayflowConfig extends Config
  13. {
  14. /**#@-*/
  15. /**#@+
  16. * Payment transaction types
  17. */
  18. const TRXTYPE_AUTH_ONLY = 'A';
  19. const TRXTYPE_SALE = 'S';
  20. /**#@-*/
  21. /**
  22. * Mapper from Magento payment actions to PayPal-specific transaction types
  23. *
  24. * @return string|null
  25. */
  26. public function getTrxType()
  27. {
  28. switch ($this->getValue('payment_action')) {
  29. case self::PAYMENT_ACTION_AUTH:
  30. return self::TRXTYPE_AUTH_ONLY;
  31. case self::PAYMENT_ACTION_SALE:
  32. return self::TRXTYPE_SALE;
  33. default:
  34. break;
  35. }
  36. return null;
  37. }
  38. /**
  39. * Getter for URL to perform Payflow requests, based on test mode by default
  40. *
  41. * @param bool|null $testMode Ability to specify test mode using
  42. * @return string
  43. */
  44. public function getTransactionUrl($testMode = null)
  45. {
  46. $testMode = $testMode === null ? $this->getValue('sandbox_flag') : (bool)$testMode;
  47. if ($testMode) {
  48. return $this->methodInstance->getConfigData('transaction_url_test_mode');
  49. }
  50. return $this->methodInstance->getConfigData('transaction_url');
  51. }
  52. /**
  53. * Payment action getter compatible with payment model
  54. *
  55. * @return string|null
  56. */
  57. public function getPaymentAction()
  58. {
  59. switch ($this->getValue('payment_action')) {
  60. case self::PAYMENT_ACTION_AUTH:
  61. return AbstractMethod::ACTION_AUTHORIZE;
  62. case self::PAYMENT_ACTION_SALE:
  63. return AbstractMethod::ACTION_AUTHORIZE_CAPTURE;
  64. default:
  65. break;
  66. }
  67. return null;
  68. }
  69. /**
  70. * Check whether method active in configuration and supported for merchant country or not
  71. *
  72. * @param string $method Method code
  73. * @return bool
  74. *
  75. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  76. */
  77. public function isMethodActive($method)
  78. {
  79. return parent::isMethodActive(Config::METHOD_PAYMENT_PRO)
  80. || parent::isMethodActive(Config::METHOD_PAYFLOWPRO);
  81. }
  82. /**
  83. * Map any supported payment method into a config path by specified field name
  84. *
  85. * @param string $fieldName
  86. * @return string|null
  87. */
  88. protected function _getSpecificConfigPath($fieldName)
  89. {
  90. if ($this->pathPattern) {
  91. return sprintf($this->pathPattern, $this->_methodCode, $fieldName);
  92. }
  93. return "payment/{$this->_methodCode}/{$fieldName}";
  94. }
  95. }