You are here

class CcaValidation in Commerce Authorize.Net 8

Verifies JWT in the CCA process.

Hierarchy

Expanded class hierarchy of CcaValidation

See also

https://developer.cardinalcommerce.com/cardinal-cruise-activation.shtml#...

File

src/Controller/CcaValidation.php, line 18

Namespace

Drupal\commerce_authnet\Controller
View source
class CcaValidation implements ContainerInjectionInterface {

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  private $requestStack;

  /**
   * Constructs a new CcaValidation object.
   *
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   */
  public function __construct(RequestStack $request_stack) {
    $this->requestStack = $request_stack;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('request_stack'));
  }

  /**
   * Validates the JWT.
   */
  public function validateJwt() {
    $response_jwt = $this->requestStack
      ->getCurrentRequest()->request
      ->get('responseJwt');

    /** @var \Lcobucci\JWT\Token $token */
    $token = (new Parser())
      ->parse($response_jwt);
    $signer = new Sha256();
    $gateway_id = $this->requestStack
      ->getCurrentRequest()->request
      ->get('gatewayId');

    /** @var \Drupal\commerce_payment\Entity\PaymentGateway $gateway */
    $gateway = PaymentGateway::load($gateway_id);
    $api_key = $gateway
      ->getPlugin()
      ->getCcaApiKey();
    $claims = $token
      ->getClaims();
    $response = [
      'verified' => $token
        ->verify($signer, $api_key),
      'payload' => $claims,
    ];
    return new JsonResponse($response);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CcaValidation::$requestStack private property The request stack.
CcaValidation::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
CcaValidation::validateJwt public function Validates the JWT.
CcaValidation::__construct public function Constructs a new CcaValidation object.