public function AcceptJs::declinePayment in Commerce Authorize.Net 8
Declines the given payment under review.
Only payments in the 'unauthorized_review' and 'authorization_review' states can be declined.
Parameters
\Drupal\commerce_payment\Entity\PaymentInterface $payment: The payment.
Throws
\Drupal\commerce_payment\Exception\PaymentGatewayException Thrown when the transaction fails for any reason.
Overrides AcceptJsInterface::declinePayment
File
- src/
Plugin/ Commerce/ PaymentGateway/ AcceptJs.php, line 391
Class
- AcceptJs
- Provides the Accept.js payment gateway.
Namespace
Drupal\commerce_authnet\Plugin\Commerce\PaymentGatewayCode
public function declinePayment(PaymentInterface $payment) {
/** @var \Drupal\commerce_payment\Entity\PaymentMethod $payment_method */
$this
->assertPaymentState($payment, [
'unauthorized_review',
'authorization_review',
]);
if ($payment
->isExpired()) {
throw new HardDeclineException('This payment has expired.');
}
$request = new UpdateHeldTransactionRequest($this->authnetConfiguration, $this->httpClient);
$request
->setAction(UpdateHeldTransactionRequest::DECLINE);
$request
->setRefTransId($payment
->getRemoteId());
$response = $request
->execute();
if ($response
->getResultCode() != 'Ok') {
$this
->logResponse($response);
$message = $response
->getMessages()[0];
throw new PaymentGatewayException($message
->getText());
}
$new_state = $payment
->getState()
->getId() == 'unauthorized_review' ? 'unauthorized_declined' : 'authorization_declined';
$payment
->setState($new_state);
$payment
->save();
}