ProcessableException.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\Api;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Framework\Phrase;
  9. /**
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class ProcessableException extends LocalizedException
  14. {
  15. /**#@+
  16. * Error code returned by PayPal
  17. */
  18. const API_INTERNAL_ERROR = 10001;
  19. const API_UNABLE_PROCESS_PAYMENT_ERROR_CODE = 10417;
  20. const API_MAX_PAYMENT_ATTEMPTS_EXCEEDED = 10416;
  21. const API_UNABLE_TRANSACTION_COMPLETE = 10486;
  22. const API_TRANSACTION_EXPIRED = 10411;
  23. const API_DO_EXPRESS_CHECKOUT_FAIL = 10422;
  24. const API_COUNTRY_FILTER_DECLINE = 10537;
  25. const API_MAXIMUM_AMOUNT_FILTER_DECLINE = 10538;
  26. const API_OTHER_FILTER_DECLINE = 10539;
  27. const API_ADDRESS_MATCH_FAIL = 10736;
  28. const API_TRANSACTION_HAS_BEEN_COMPLETED = 10415;
  29. /**#@-*/
  30. /**
  31. * Constructor
  32. *
  33. * @param \Magento\Framework\Phrase $phrase
  34. * @param \Exception $cause
  35. * @param int $code
  36. */
  37. public function __construct(Phrase $phrase, \Exception $cause = null, $code = 0)
  38. {
  39. parent::__construct($phrase, $cause, $code);
  40. $this->code = $code;
  41. }
  42. /**
  43. * Get error message which can be displayed to website user
  44. *
  45. * @return \Magento\Framework\Phrase
  46. */
  47. public function getUserMessage()
  48. {
  49. switch ($this->getCode()) {
  50. case self::API_INTERNAL_ERROR:
  51. case self::API_UNABLE_PROCESS_PAYMENT_ERROR_CODE:
  52. $message = __(
  53. 'I\'m sorry - but we were not able to process your payment.'
  54. . ' Please try another payment method or contact us so we can assist you.'
  55. );
  56. break;
  57. case self::API_COUNTRY_FILTER_DECLINE:
  58. case self::API_MAXIMUM_AMOUNT_FILTER_DECLINE:
  59. case self::API_OTHER_FILTER_DECLINE:
  60. $message = __(
  61. 'I\'m sorry - but we are not able to complete your transaction.'
  62. . ' Please contact us so we can assist you.'
  63. );
  64. break;
  65. case self::API_ADDRESS_MATCH_FAIL:
  66. $message = __(
  67. 'A match of the Shipping Address City, State, and Postal Code failed.'
  68. );
  69. break;
  70. default:
  71. $message = __('We can\'t place the order.');
  72. break;
  73. }
  74. return $message;
  75. }
  76. }