You are here

protected function PaymentMethodAddForm::generateJwt in Commerce Authorize.Net 8

Create JWT token for CCA.

Return value

\Lcobucci\JWT\Token The JWT token.

1 call to PaymentMethodAddForm::generateJwt()
PaymentMethodAddForm::buildCreditCardForm in src/PluginForm/AcceptJs/PaymentMethodAddForm.php
Builds the credit card form.

File

src/PluginForm/AcceptJs/PaymentMethodAddForm.php, line 274

Class

PaymentMethodAddForm

Namespace

Drupal\commerce_authnet\PluginForm\AcceptJs

Code

protected function generateJwt() {
  $current_time = time();
  $expire_time = 3600;

  /** @var \Drupal\commerce_order\Entity\Order $order */
  if ($order = $this->routeMatch
    ->getParameter('commerce_order')) {
    $order_details = [
      'OrderDetails' => [
        'OrderNumber' => $order
          ->getOrderNumber(),
      ],
    ];
  }

  /** @var \Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway\AcceptJs $plugin */
  $plugin = $this->plugin;
  $token = (new Builder())
    ->issuedBy($plugin
    ->getCcaApiId())
    ->identifiedBy(uniqid(), TRUE)
    ->issuedAt($current_time)
    ->expiresAt($current_time + $expire_time)
    ->withClaim('OrgUnitId', $plugin
    ->getCcaOrgUnitId())
    ->withClaim('Payload', $order_details)
    ->withClaim('ObjectifyPayload', TRUE)
    ->getToken(new Sha256(), new Key($plugin
    ->getCcaApiKey()));
  return $token;
}