public function Square::voidPayment in Commerce Square Connect 8
Voids the given payment.
Parameters
\Drupal\commerce_payment\Entity\PaymentInterface $payment: The payment to void.
Throws
\Drupal\commerce_payment\Exception\PaymentGatewayException Thrown when the transaction fails for any reason.
Overrides SupportsVoidsInterface::voidPayment
File
- src/
Plugin/ Commerce/ PaymentGateway/ Square.php, line 387
Class
- Square
- Provides the Square payment gateway.
Namespace
Drupal\commerce_square\Plugin\Commerce\PaymentGatewayCode
public function voidPayment(PaymentInterface $payment) {
$this
->assertPaymentState($payment, [
'authorization',
]);
list($transaction_id, $tender_id) = explode('|', $payment
->getRemoteId());
$mode = $this
->getMode();
try {
$transaction_api = new TransactionsApi($this
->getApiClient());
$result = $transaction_api
->voidTransaction($this->configuration[$mode . '_location_id'], $transaction_id);
} catch (ApiException $e) {
throw ErrorHelper::convertException($e);
}
$payment
->setState('authorization_voided');
$payment
->save();
}