CvvEmsCodeMapper.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\Payflow;
  7. use Magento\Payment\Api\PaymentVerificationInterface;
  8. use Magento\Paypal\Model\Config;
  9. use Magento\Paypal\Model\Info;
  10. use Magento\Sales\Api\Data\OrderPaymentInterface;
  11. /**
  12. * Processes CVV codes mapping from PayPal Payflow transaction to
  13. * electronic merchant systems standard.
  14. *
  15. * @see https://developer.paypal.com/docs/classic/payflow/integration-guide/#credit-card-transaction-responses
  16. * @see http://www.emsecommerce.net/avs_cvv2_response_codes.htm
  17. */
  18. class CvvEmsCodeMapper implements PaymentVerificationInterface
  19. {
  20. /**
  21. * Default code for mismatch mapping
  22. *
  23. * @var string
  24. */
  25. private static $notProvidedCode = 'P';
  26. /**
  27. * List of mapping CVV codes
  28. *
  29. * @var array
  30. */
  31. private static $cvvMap = [
  32. 'Y' => 'M',
  33. 'N' => 'N'
  34. ];
  35. /**
  36. * Gets payment CVV verification code.
  37. *
  38. * @param OrderPaymentInterface $orderPayment
  39. * @return string
  40. * @throws \InvalidArgumentException If specified order payment has different payment method code.
  41. */
  42. public function getCode(OrderPaymentInterface $orderPayment)
  43. {
  44. if ($orderPayment->getMethod() !== Config::METHOD_PAYFLOWPRO) {
  45. throw new \InvalidArgumentException(
  46. 'The "' . $orderPayment->getMethod() . '" does not supported by Payflow CVV mapper.'
  47. );
  48. }
  49. $additionalInfo = $orderPayment->getAdditionalInformation();
  50. if (empty($additionalInfo[Info::PAYPAL_CVV2MATCH])) {
  51. return self::$notProvidedCode;
  52. }
  53. $cvv = $additionalInfo[Info::PAYPAL_CVV2MATCH];
  54. return isset(self::$cvvMap[$cvv]) ? self::$cvvMap[$cvv] : self::$notProvidedCode;
  55. }
  56. }