diff -u b/js/commerce_authnet.accept.form.js b/js/commerce_authnet.accept.form.js --- b/js/commerce_authnet.accept.form.js +++ b/js/commerce_authnet.accept.form.js @@ -89,7 +89,7 @@ case "NOACTION": // Success indicates that we got back CCA values we can pass to the gateway // No action indicates that everything worked, but there is no CCA values to worry about, so we can move on with the transaction - console.warn('The transaction was completed with no errors', data.Payment.ExtendedData); + console.warn('The transaction was completed with no errors.', data.Payment.ExtendedData); responseJwt = jwt; // CCA Succesful, now complete the transaction with Authorize.Net @@ -98,30 +98,43 @@ case "FAILURE": // Failure indicates the authentication attempt failed - console.warn('The authentication attempt failed', data.Payment); + console.warn('The authentication attempt failed.', data.Payment); + alert('The authentication attempt failed.') + location.reload(); break; case "ERROR": default: // Error indicates that a problem was encountered at some point in the transaction - console.warn('An issue occurred with the transaction', data.Payment); + console.warn('An issue occurred with the transaction.', data.Payment); + alert('An issue occurred with the transaction.') + location.reload(); break; } } else { - console.error("Failure while attempting to verify JWT signature: ", data) + console.error("Failure while attempting to verify JWT signature: ", data); + alert('Failure while attempting to verify JWT signature.'); + location.reload(); } } else { console.error('Response data was incorrectly formatted: ', responseData); + alert('Response data was incorrectly formatted.'); + location.reload(); } }) .fail(function (xhr, ajaxError) { - console.log('Connection failure:', ajaxError) + console.log('Connection failure:', ajaxError); + alert('Connection failure.'); + location.reload(); }); } catch (validateError) { - console.error('Failed while processing validate', validateError); + console.error('Failed while processing validate.', validateError); + alert('Failed while processing validate.'); + location.reload(); + } }); diff -u b/src/Plugin/Commerce/PaymentGateway/AcceptJs.php b/src/Plugin/Commerce/PaymentGateway/AcceptJs.php --- b/src/Plugin/Commerce/PaymentGateway/AcceptJs.php +++ b/src/Plugin/Commerce/PaymentGateway/AcceptJs.php @@ -376,7 +376,7 @@ // We don't want 3DS on the user payment method form. if (!empty($this->getConfiguration()['cca_status']) && !empty($payment_details['cca_jwt_token'])) { if (empty($payment_details['cca_jwt_response_token'])) { - throw new \InvalidArgumentException(sprintf('Cannot continue when CCA is enabled but not used.')); + throw new PaymentGatewayException('Cannot continue when CCA is enabled but not used.'); } /** @var \Lcobucci\JWT\Token $token */ @@ -384,9 +384,16 @@ $signer = new Sha256(); if (!$token->verify($signer, $this->getCcaApiKey())) { - throw new \InvalidArgumentException(sprintf('Response CCA JWT is not valid.')); + throw new PaymentGatewayException('Response CCA JWT is not valid.'); + } + $claims = $token->getClaims(); + /** @var \Lcobucci\JWT\Claim $payload */ + $payload = $claims['Payload']; + if (isset($payload->getValue()->Payment->ExtendedData->SignatureVerification) && $payload->getValue()->Payment->ExtendedData->SignatureVerification === 'N') { + throw new PaymentGatewayException('Unsuccessful signature verification.'); } } + $required_keys = [ 'data_descriptor', 'data_value', ]; @@ -406,14 +413,13 @@ $payment_method->save(); if (!empty($this->getConfiguration()['cca_status']) && !empty($payment_details['cca_jwt_token'])) { - $claims = $token->getClaims(); - /** @var \Lcobucci\JWT\Claim $payload */ - $payload = $claims['Payload']; // We might not have a CAVV value. // @see https://usa.visa.com/dam/VCOM/download/merchants/verified-by-visa-acquirer-merchant-implementation-guide.pdf // Table 5-2. if (isset($payload->getValue()->Payment->ExtendedData->CAVV)) { $_SESSION['commerce_authnet'][$payment_method->id()]['cavv'] = $payload->getValue()->Payment->ExtendedData->CAVV; + } + if (isset($payload->getValue()->Payment->ExtendedData->ECIFlag)) { $_SESSION['commerce_authnet'][$payment_method->id()]['eci'] = $payload->getValue()->Payment->ExtendedData->ECIFlag; } } diff -u b/src/PluginForm/AcceptJsAddForm.php b/src/PluginForm/AcceptJsAddForm.php --- b/src/PluginForm/AcceptJsAddForm.php +++ b/src/PluginForm/AcceptJsAddForm.php @@ -184,7 +184,7 @@ ], ]; $element['#attached']['drupalSettings']['commerceAuthorizeNet']['orderId'] = $order->id(); - $element['#attached']['drupalSettings']['commerceAuthorizeNet']['orderAmount'] = $order->getTotalPrice()->getNumber(); + $element['#attached']['drupalSettings']['commerceAuthorizeNet']['orderAmount'] = round($order->getTotalPrice()->getNumber()); $element['#attached']['drupalSettings']['commerceAuthorizeNet']['orderCurrency'] = $order->getTotalPrice()->getCurrencyCode(); $element['#attached']['drupalSettings']['commerceAuthorizeNet']['ccaStatus'] = 1; }