You are here

protected function DatabaseQueue::tryClaimPaymentOnce in Payment 8.2

Tries to claim a payment once.

Parameters

integer $payment_id:

Return value

string|false An acquisition code to acquire the payment with on success, or FALSE if the payment could not be claimed.

1 call to DatabaseQueue::tryClaimPaymentOnce()
DatabaseQueue::claimPayment in src/DatabaseQueue.php
Claims a payment available for referencing through a field instance.

File

src/DatabaseQueue.php, line 170

Class

DatabaseQueue
Provides a database-based payment queue.

Namespace

Drupal\payment

Code

protected function tryClaimPaymentOnce($payment_id) {
  $acquisition_code = $this->randomGenerator
    ->string(255);
  $count = $this->database
    ->update('payment_queue', array(
    'return' => Database::RETURN_AFFECTED,
  ))
    ->condition('claimed', time() - $this
    ->getClaimExpirationPeriod(), '<')
    ->condition('payment_id', $payment_id)
    ->condition('queue_id', $this->queueId)
    ->fields(array(
    'acquisition_code' => $acquisition_code,
    'claimed' => time(),
  ))
    ->execute();
  return $count ? $acquisition_code : FALSE;
}