Check, if payment transaction is finished and payment is not new.

 @param    payment_transaction   [PaymentTransaction]    Payment transaction for validation
420322
def check_payment_transaction_status(payment_transaction)
      unless payment_transaction.finished?
        raise ValidationError, 'Only finished payment transaction can be used for create-card-ref-id'
      end

      unless payment_transaction.payment.paid?
        raise ValidationError, "Can not use new payment for create-card-ref-id. Execute 'sale' or 'preauth' query first"
      end
    end
728882
def new_transaction(options = {})
      options = options.dup

      options.merge!({
        :pos_id => @pos_id,
        :pos_auth_key => @pos_auth_key,
        :gateway_url => options[:gateway_url] || @gateway_url,
        :key1 => @key1,
        :encoding => encoding,
        :variant => variant
      })

      if !options.has_key?(:add_signature)
        options[:add_signature] = add_signature?
      end

      if !options.has_key?(:pay_type)
        options[:pay_type] = test_payment? ? 't' : nil
      end

      Transaction.new(options)
    end
747436
private function checkPaymentMethod($payment)
    {
        $paymentMethod = $payment->getMethod();

        if ($paymentMethod != Payment::METHOD_CODE) {
            throw new LocalizedException(__(
                'Payment method assigned to order is: %1',
                $paymentMethod
            ));
        }
    }
809576
public static boolean isCommittedProcessed(byte[] stateBytes, Transaction tx) {
    long writePointer = Bytes.toLong(stateBytes, 0, Longs.BYTES);
    if (!tx.isVisible(writePointer)) {
      return false;
    }
    byte state = stateBytes[Longs.BYTES + Ints.BYTES];
    return state == ConsumerEntryState.PROCESSED.getState();
  }
716080
def commit_transaction(self):
        
        self._check_ended()
        retry = False
        state = self._transaction.state
        if state is _TxnState.NONE:
            raise InvalidOperation("No transaction started")
        elif state in (_TxnState.STARTING, _TxnState.COMMITTED_EMPTY):
            # Server transaction was never started, no need to send a command.
            self._transaction.state = _TxnState.COMMITTED_EMPTY
            return
        elif state is _TxnState.ABORTED:
            raise InvalidOperation(
                "Cannot call commitTransaction after calling abortTransaction")
        elif state is _TxnState.COMMITTED:
            # We're explicitly retrying the commit, move the state back to
            # "in progress" so that _in_transaction returns true.
            self._transaction.state = _TxnState.IN_PROGRESS
            retry = True

        try:
            self._finish_transaction_with_retry("commitTransaction", retry)
        except ConnectionFailure as exc:
            # We do not know if the commit was successfully applied on the
            # server or if it satisfied the provided write concern, set the
            # unknown commit error label.
            exc._remove_error_label("TransientTransactionError")
            _reraise_with_unknown_commit(exc)
        except WTimeoutError as exc:
            # We do not know if the commit has satisfied the provided write
            # concern, add the unknown commit error label.
            _reraise_with_unknown_commit(exc)
        except OperationFailure as exc:
            if exc.code not in _UNKNOWN_COMMIT_ERROR_CODES:
                # The server reports errorLabels in the case.
                raise
            # We do not know if the commit was successfully applied on the
            # server or if it satisfied the provided write concern, set the
            # unknown commit error label.
            _reraise_with_unknown_commit(exc)
        finally:
            self._transaction.state = _TxnState.COMMITTED
1205716
def payment_status_changed_listener(sender, instance, old_status, new_status, **kwargs):
    
    logger.debug("payment_status_changed_listener, old=%s, new=%s", old_status,
                 new_status)
    if old_status != 'paid' and new_status == 'paid':
        # Ensures that we process order only one
        instance.order.status = 'P'
        instance.order.save()
658306
@Override
    public void afterCompletion(TransactionCommon transaction, boolean committed)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "afterCompletion", new Object[] { transaction, Boolean.valueOf(committed) });

        synchronized (this)
        {
            // If the connection is already closed this transaction
            // will have been removed.
            if (!_closed)
            {
                synchronized (_ownedTransactions)
                {
                    // Remove the transaction from the connections list
                    _ownedTransactions.remove(transaction);
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "afterCompletion");
    }
574264
def ddl_transaction(&block)
        if Base.connection.supports_ddl_transactions?
          Base.transaction { block.call }
        else
          block.call
        end
      end
167087
def validate_recurrent_transaction_params!(options)
      required_params = [:amount, :payment_method, :invoicenumber, :transaction_id]

      validate_required_params!(options, required_params)

      validate_amount!(options)

      valid_payment_methods = [
        PaymentMethod::VISA, PaymentMethod::MASTER_CARD, PaymentMethod::MAESTRO,
        PaymentMethod::SEPA_DIRECT_DEBIT, PaymentMethod::PAYPAL
      ]
      validate_payment_method!(options, valid_payment_methods)
    end
251596
public static boolean isUncommitted(Transaction tx)
   {
      if (tx == null)
         return false;
      
      try
      {
         int status = tx.getStatus();

         return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK;
      }
      catch (SystemException error)
      {
         throw new RuntimeException("Error during isUncommitted()", error);
      }
   }
944491
public function checkPayment($transaction_id)
    {
        // Check arguments
        if (null === $transaction_id || !is_string($transaction_id) || strlen(trim($transaction_id)) == 0) {
            throw new \InvalidArgumentException('Transaction ID should be a string.');
        }

        // Params
        $params = array(
            'partnerid' => $this->partnerId,
            'transaction_id' => $transaction_id,
        );

        // Do request
        $response = $this->request('check-status/', $params);

        // Gather data
        if ($response->order === null) {
            throw new MollieException('Unexpected response');
        }
        $transactionId = (string) $response->order->transaction_id;
        $amount = (int) $response->order->amount;
        $paid = ((string) $response->order->paid == 'true');
        $status = (string) $response->order->status;

        // Return TransactionStatus
        return new TransactionStatus($amount, $paid, $transactionId, $status);
    }
1191152
@SuppressWarnings("unused")
    @Override
    public void onPaymentSuccess(String razorpayPaymentID) {
        try {
            Toast.makeText(this, "Payment Successful: " + razorpayPaymentID, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Log.e(TAG, "Exception in onPaymentSuccess", e);
        }
    }
561410
private TransactionStatus computeNewTransactionStatusFromPaymentTransactionInfoPlugin(final PaymentTransactionInfoPlugin input, final TransactionStatus currentTransactionStatus) {
        final TransactionStatus newTransactionStatus = PaymentTransactionInfoPluginConverter.toTransactionStatus(input);
        return (newTransactionStatus != TransactionStatus.UNKNOWN) ? newTransactionStatus : currentTransactionStatus;
    }
1150617
protected function completePayment()
    {
        if ($this->controller->isQuery('paid')) {
            $gateway = $this->getGateway();
            $this->response = $gateway->completePurchase($this->getPurchaseParams())->send();
            $this->processResponse();
        }
    }
286331
protected function finishPurchase()
    {
        if ($this->response->isSuccessful()) {
            $this->updateOrderStatus();
            $this->addTransaction();
            $this->redirectSuccess();
        } else if ($this->response->isRedirect()) {
            $this->response->redirect();
        } else {
            $this->redirectError();
        }
    }
1180822
protected boolean hasOngoingTransaction() {
		if(!isSupervisedMode()) {
			return false;
		} else {
			if(ongoingTransactions != null) {
				for (Transaction transaction : ongoingTransactions) {
					if(TransactionState.CALLING.equals(transaction.getState()) ||
						TransactionState.TRYING.equals(transaction.getState()) ||
						TransactionState.PROCEEDING.equals(transaction.getState()) ||
						TransactionState.COMPLETED.equals(transaction.getState()) ||
						TransactionState.CONFIRMED.equals(transaction.getState())) {
							return true;
					}
				}
			}
			return false;
		}
	}
1305286
public boolean confirmPayment(String orderNumber, String timestamp, String paid, String method, String authCode) {
		String base = new StringBuilder()
  	  .append(orderNumber)
  	  .append('|')
  	  .append(timestamp)
  	  .append('|')
  	  .append(paid)
  	  .append('|')
  	  .append(method)
  	  .append('|')
  	  .append(merchantSecret)
  	  .toString();
		
		return 
			StringUtils.equals(
				StringUtils.upperCase(DigestUtils.md5Hex(base)),
				authCode
			);
	}