Authorize a payment for future capture

@var Object $payment
@var Float $amount
515472
public function authorize($payment, $amount)
        {
            $error = false;

            // check for payment
            if($amount > 0) {

                $payment->setAmount($amount);

                // Map magento keys to moneris way
                $transaction = $this->_build($payment, self::TRANSACTION_PREAUTH);
                $response = $this->_send($transaction);

                $payment->setCcApproval($response->getReceiptId())
                    ->setLastTransId($response->getReceiptId())
                    ->setCcTransId($response->getTxnNumber())
                    ->setCcAvsStatus($response->getAuthCode())
                    ->setCcCidStatus($response->getResponseCode());


                if($response->getResponseCode() > 0 && $response->getResponseCode() <= self::ERROR_CODE_LIMIT) {
                    $payment->setStatus(self::STATUS_APPROVED);
                } else if($response->getResponseCode() > self::ERROR_CODE_LIMIT && $response->getResponseCode() < self::ERROR_CODE_UPPER_LIMIT) {
                    $error = $this->_errors[$response->getResponseCode()];
                } else {
                    $error = 'Incomplete transaction.';
                }
            } else {
                $error = 'Invalid amount for authorization.';
            }

            // we've got something bad here.
            if ($error !== false) {
                $this->_log($error);
            }
            return $this;
        }
599792
public function capture(InfoInterface $payment, $amount)
    {
        try {
            $order = $payment->getOrder();

            if ($amount <= 0) {
                throw new LocalizedException(__('Invalid amount for capture.'));
            }

            $realTransactionId = $payment->getAdditionalInformation('real_transaction_id');

            if (empty($realTransactionId)) {
                throw new LocalizedException(
                    __('Please wait while transaction get updated from Bolt.')
                );
            }

            $captureAmount = $amount * 100;

            //Get capture data
            $capturedData = [
                'transaction_id' => $realTransactionId,
                'amount'         => $captureAmount,
                'currency'       => $order->getOrderCurrencyCode()
            ];

            $apiKey = $this->configHelper->getApiKey();

            //Request Data
            $requestData = $this->dataObjectFactory->create();
            $requestData->setApiData($capturedData);
            $requestData->setDynamicApiUrl(ApiHelper::API_CAPTURE_TRANSACTION);
            $requestData->setApiKey($apiKey);

            //Build Request
            $request = $this->apiHelper->buildRequest($requestData);
            $result = $this->apiHelper->sendRequest($request);
            $response = $result->getResponse();

            if (empty($response)) {
                throw new LocalizedException(
                    __('Bad capture response from boltpay')
                );
            }

            if (!in_array(@$response->status, [self::TRANSACTION_AUTHORIZED, self::TRANSACTION_COMPLETED])) {
                throw new LocalizedException(__('Payment capture error.'));
            }

            $this->orderHelper->updateOrderPayment($order, null, $response->reference);

            return $this;
        } catch (\Exception $e) {
            $this->bugsnag->notifyException($e);
            throw $e;
        }
    }
1154594
private function _authorizePaymentAmountWithCaptureNow ($authorizationAmount, 
            $authorizationReferenceId)
    {
        $response = $this->callStepAndCheckForException('authorizePaymentAmountWithCaptureNow', 
                array(
                    $authorizationAmount,
                    $authorizationReferenceId
                ));
        
        $this->printResponseToWebpage("printAuthorizeOnBillingAgreementResponse", array(
            $response
        ));
        
        return getAmazonAuthorizationIdFromAuthorizeOnBillingAgreementResponse($response);
    }
1284273
protected function getPaymentIntent($payment)
    {
        $intent = null;

        switch ($payment->Status) {
            // We have to check for both states here, since the notification might come in before the gateway returns
            // if that's the case, the status of the payment will already be set to 'Authorized'
            case 'PendingAuthorization':
            case 'Authorized':
                $intent = ServiceFactory::INTENT_AUTHORIZE;
                break;
            case 'PendingCreateCard':
            case 'CardCreated':
                $intent = ServiceFactory::INTENT_CREATECARD;
                break;
            case 'PendingCapture':
                $intent = ServiceFactory::INTENT_CAPTURE;
                break;
            // Both states have to be checked (see explanation with 'Authorized')
            case 'PendingPurchase':
            case 'Captured':
                $intent = ServiceFactory::INTENT_PURCHASE;
                break;
            case 'PendingRefund':
                $intent = ServiceFactory::INTENT_REFUND;
                break;
            case 'PendingVoid':
            case 'Void':
                $intent = ServiceFactory::INTENT_VOID;
                break;
        }

        return $intent;
    }
255719
public function setPayment(Payment $payment)
    {
        $this->payment = $payment;

        if (!$payment->hasPaymentTransaction($this))
        {
            $payment->addPaymentTransaction($this);
        }

        return $this;
    }
665811
private function setRequestedAmount()
    {
        if ($this->simpleXml->{'requested-amount'}->count() < 1) {
            return;
        }

        $this->requestedAmount = new Amount(
            (float)$this->simpleXml->{'requested-amount'},
            (string)$this->simpleXml->{'requested-amount'}->attributes()->currency
        );
    }
426793
function DoAuthorization($txnID, $amount = 0, $currency = 'USD', $entity = 'Order') {
    $values['TRANSACTIONID'] = $txnID;
    $values['AMT'] = number_format($amount, 2, '.', ',');
    $values['TRANSACTIONENTITY'] = $entity;
    $values['CURRENCYCODE'] = $currency;
    return $this->_request($values, 'DoAuthorization');
  }
47929
public function create($amount, $payment, $options = [])
    {
        $params = [];

        $params['transaction'] = 'fail';

        if ($payment === 'success') {
            $params['transaction'] = 'success';
        }

        return $this->gateway->commit('post', 'charges', $params);
    }
1308437
public function authorize($amount = null)
    {
        if (is_null($amount)) {
            $amount = $this->getAmount()->total;
        }
        $path = sprintf('/%s/%s?payment_id=%s&amount=%s', self::SIMULATOR_PATH, 'authorize', $this->getId(), $amount);
        $response = $this->httpRequest($path, Requests::GET);

        if (empty($response)) {
            return true;
        }

        return false;
    }
103596
public function onPaymentPrepare(PaymentEvent $event)
    {
        $payment = $event->getPayment();

        $storage = $this->registry->getStorage(get_class($payment));

        $storage->update($payment);

        $captureToken = $this->factory->createCaptureToken(
            $payment->getMethod(),
            $payment,
            'ekyna_payment_done' // the route to redirect after capture
        );

        $event->setResponse(new RedirectResponse($captureToken->getTargetUrl()));
    }
205363
public function capture($transactionId, $amount)
    {
        HpsInputValidation::checkAmount($amount);

        $xml = new DOMDocument();
        $transaction = $xml->createElement('hps:Transaction');
        $capture = $xml->createElement('hps:AltPaymentCapture');

        $capture->appendChild($xml->createElement('hps:TransactionType', $this->_transactionType));
        $capture->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
        $capture->appendChild($xml->createElement('hps:Amt', $amount));

        $payment = $xml->createElement('hps:Payment');
        $nvp = $xml->createElement('hps:NameValuePair');
        $nvp->appendChild($xml->createElement('hps:Name', 'FullyCapturedFlag'));
        $nvp->appendChild($xml->createElement('hps:Value', 'true'));
        $payment->appendChild($nvp);

        $capture->appendChild($payment);
        $transaction->appendChild($capture);
        return $this->_submitTransaction($transaction, 'AltPaymentCapture');
    }
1338971
protected function userPayment()
    {
        $this->refId = Input::get('PayerID');
        $this->transactionSetRefId();
        $this->trackingCode = Input::get('token');
    }
814936
public function executePayment($amount, &$order)
    {
        $success = parent::executePayment($amount, $order);
        $session = $this->getSession();

        if ( ($session->getVariable('paymentid') == 'oxidpaypal')
             || ($session->getBasket()->getPaymentId() == 'oxidpaypal')
        ) {
            $this->setPayPalOxOrder($order);
            $success = $this->doExpressCheckoutPayment();
        }

        return $success;
    }
722111
public function payment(Payment $payment, &$paymentParams)
    {
        $wallet = WalletModel::findByUserID($payment->user_id, $payment->currency);
        $value = $wallet->money - $payment->money;

        $params = [
            'paymentId' => $payment->id,
            'money' => $payment->money,
        ];

        if ($payment->money < 0 || $value < 0) {
            $params['payId'] = '0';
            $params['status'] = 'failure';
            $params['message'] = 'Insufficient balance.';
        } else {
            $transaction = WalletModel::getDb()->beginTransaction();
            try {
                //更新用户钱包
                $wallet->updateAttributes(['money' => $value, 'updated_at' => time()]);
                //创建钱包操作日志
                $log = new WalletLog([
                    'wallet_id' => $wallet->id,
                    'currency' => $payment->currency,
                    'money' => $payment->money,
                    'action' => 'Purchase',
                    'msg' => '',
                    'type' => WalletLog::TYPE_DEC
                ]);
                $log->link('wallet', $wallet);
                $transaction->commit();
                $params['payId'] = $log->id;
                $params['status'] = 'completion';
                $params['message'] = 'Completion of payment.';
            } catch (\Exception $e) {
                $transaction->rollBack();
                $params['payId'] = '0';
                $params['status'] = 'failure';
                $params['message'] = 'Insufficient balance.';
            }
        }
        $params['sign'] = strtoupper(md5("{$params['paymentId']}&{$params['money']}&$this->md5Key"));
        $this->getRedirectResponse($params);
    }
504303
public function addMerchantPayment($application, \DateTime $effectiveDate, $amount, $token)
    {
        return $this->postDocument(
            '/v4/applications/' . $application . '/merchant-payments',
            [
                'amount' => $amount,
                'effective_date' => $effectiveDate->format('Y-m-d'),
            ],
            $token,
            'Add Merchant Payment'
        );
    }
818759
public function savePayerAccount($payer, $payment)
    {
        $result = null;
        $buc    = $payment->getDataValue('buc');
        if (!empty($buc) && !empty($payer) && $this->isKnownBankAccountForAddress($payer,
                $buc)) {
            $result = $this->assignBankAccountToAddress($payer, $payment);
        }
        return $result;
    }
408198
public function addPayment(Payment $payment)
    {
        if ($payment->getPaymentInstruction() !== $this) {
            throw new \InvalidArgumentException('This payment container belongs to another instruction.');
        }

        $this->payments->add($payment);
    }