function commerce_square_void_form_submit in Commerce Square Connect 7
Submit handler: process the void request.
File
- includes/
commerce_square.admin.inc, line 105 - Provides admin menu callbacks for Commerce Square.
Code
function commerce_square_void_form_submit($form, &$form_state) {
$transaction = $form_state['transaction'];
$client = SquareApi::createFromInstanceId($transaction->instance_id);
try {
$client
->void($transaction);
$transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
drupal_set_message(t('Transaction successfully voided.'));
} catch (ApiException $e) {
/** @var \SquareConnect\Model\VoidTransactionResponse $result */
$result = $e
->getResponseObject();
foreach ($result
->getErrors() as $error) {
drupal_set_message(sprintf('%s %s %s', $error
->getCode(), $error
->getCategory(), $error
->getDetail()), 'error');
}
} catch (Exception $e) {
drupal_set_message(t('There was an error voiding the transaction: @message', array(
'@message' => $e
->getMessage(),
)), 'error');
}
commerce_payment_transaction_save($transaction);
$form_state['redirect'] = 'admin/commerce/orders/' . $form_state['order']->order_id . '/payment';
}