去支付
@param Payment $payment
@param array $paymentParams 支付参数
@return void
502947
public function payment(Payment $payment, &$paymentParams)
    {
        if (!$this->checkCurrency($payment->currency)) {
            Yii::$app->session->setFlash(Yii::t('payment', 'The gateway does not support the current currency!'));
        } else {
            $params = $this->buildPaymentParameter([
                'out_trade_no' => $payment->id,
                'subject' => !empty($payment->model_id) ? $payment->model_id . '付款' : '账号充值',
                'total_fee' => round($payment->money, 2),
            ]);
            //签名结果与签名方式加入请求提交参数组中
            $paraFilter = $this->paraFilter($params);
            $paraSort = $this->argSort($paraFilter);
            //把数组所有元素，按照“参数=参数值”的模式用“&”字符拼接成字符串
            $preStr = $this->createLinkString($paraSort);

            $params['sign'] = $this->createSign($preStr);
            $params['sign_type'] = strtoupper($this->signType);
            $this->getRedirectResponse($params);
        }
    }
496365
protected function addPaymentMethod(array $params, $payment, array $options)
    {
        $params['payment_methods'] = [];

        if (isset($options['monthly_installments'])) {
            $params['payment_methods']['installments'] = in_array($options['monthly_installments'], [3, 6, 9, 12])
                ? (int) Arr::get($options, 'monthly_installments')
                : 1;
        }

        if (isset($options['enabled_brands'])) {
            $paymentTypes = ['prepaid_card', 'digital_currency', 'credit_card', 'debit_card', 'ticket', 'atm', 'bank_transfer'];
            $enabledTypes = Arr::get($options, 'enabled_brands', []);

            $excludedTypes = array_map(function ($type) {
                return ['id' => $type];
            }, array_values(array_filter($paymentTypes, function ($type) use ($enabledTypes) {
                return !in_array($type, $enabledTypes);
            })));

            $params['payment_methods']['excluded_payment_types'] = $excludedTypes;
        }

        return $params;
    }
184830
protected function addCard(array $params, $payment, array $options)
    {
        if (is_string($payment)) {
            if (Helper::startsWith($payment, 'cus')) {
                $params['customer'] = $payment;
            } else {
                $params['source'] = $payment;
            }
        }

        return $params;
    }
265831
public function notice(Request $request, &$paymentId, &$money, &$message, &$payId)
    {
        $xml = $request->getRawBody();

        //如果返回成功则验证签名
        try {
            $params = $this->convertXmlToArray($xml);
            $paymentId = $params['out_trade_no'];
            $money = $params['total_fee'];
            $message = $params['return_code'];
            $payId = $params['transaction_id'];
            if ($params['return_code'] == 'SUCCESS') {
                if ($params['sign'] == $this->createSign($params)) {
                    echo '<xml>
  <return_code><![CDATA[SUCCESS]]></return_code>
  <return_msg><![CDATA[OK]]></return_msg>
</xml>';
                    return true;
                }
            }
        } catch (\Exception $e) {

        }
        echo '<xml>
  <return_code><![CDATA[FAIL]]></return_code>
  <return_msg><![CDATA[FAIL]]></return_msg>
</xml>';
        return false;
    }
712926
public function setPayment(\HarvestCloud\CoreBundle\Entity\Payment\Payment $payment = null)
    {
        $this->payment = $payment;

        return $this;
    }
663617
public function authorize(Varien_Object $payment, $amount)
    {
        parent::authorize($payment, $amount);
        $payment->setLastTransId($this->getTransactionId())->setIsTransactionPending(true);

        /** @var Mage_Sales_Model_Order $order */
        $order = $payment->getOrder();
        $amount = $order->getGrandTotal();

        // check if a zero auth should be done for this order
        $useZeroAuth = (bool)Mage::helper('adyen')->getConfigData('use_zero_auth', null, $order->getStoreId());
        $zeroAuthDateField = Mage::helper('adyen')->getConfigData(
            'base_zero_auth_on_date', null,
            $order->getStoreId()
        );

        if ($useZeroAuth) { // zero auth should be used
            // only orders that are scheduled to be captured later than
            // the auth valid period use zero auth
            // the period is 7 days since this works for most payment methods
            $scheduledDate = strtotime($order->getData($zeroAuthDateField));
            if ($scheduledDate > strtotime("+7 days")) { // scheduled date is higher than now + 7 days
                $amount = 0; // set amount to 0 for zero auth
            }
        }

        /*
         * ReserveOrderId for this quote so payment failed notification
         * does not interfere with new successful orders
         */
        $incrementId = $order->getIncrementId();
        $quoteId = $order->getQuoteId();
        $quote = Mage::getModel('sales/quote')
            ->load($quoteId)
            ->setReservedOrderId($incrementId)
            ->save();

        // by zero authentication payment is authorised when api responds is succesfull
        if ($order->getGrandTotal() == 0) {
            $payment->setIsTransactionPending(false);
        }

        /*
         * Do not send a email notification when order is created.
         * Only do this on the AUHTORISATION notification.
         * For Boleto and Multibanco send it on order creation
         */
        if (!in_array($this->getCode(), array('adyen_boleto', 'adyen_multibanco'))) {
            $order->setCanSendNewEmailFlag(false);
        }

        if ($this->getCode() == 'adyen_boleto' || $this->getCode() == 'adyen_cc' || substr(
            $this->getCode(), 0,
            14
        ) == 'adyen_oneclick' || $this->getCode() == 'adyen_sepa' || $this->getCode() == 'adyen_apple_pay' || $this->getCode() == 'adyen_multibanco') {
            if (substr($this->getCode(), 0, 14) == 'adyen_oneclick') {
                // set payment method to adyen_oneclick otherwise backend can not view the order
                $payment->setMethod("adyen_oneclick");

                $recurringDetailReference = $payment->getAdditionalInformation("recurring_detail_reference");

                // load agreement based on reference_id (option to add an index on reference_id in database)
                $agreement = Mage::getModel('sales/billing_agreement')->load($recurringDetailReference, 'reference_id');

                // agreement could be a empty object
                if ($agreement && $agreement->getAgreementId() > 0 && $agreement->isValid()) {
                    $agreement->addOrderRelation($order);
                    $agreement->setIsObjectChanged(true);
                    $order->addRelatedObject($agreement);
                    $message = Mage::helper('adyen')->__(
                        'Used existing billing agreement #%s.',
                        $agreement->getReferenceId()
                    );

                    $comment = $order->addStatusHistoryComment($message);
                    $order->addRelatedObject($comment);
                }
            }

            $_authorizeResponse = $this->_processRequest($payment, $amount, "authorise");
        }

        return $this;
    }
259736
public function display(Request $request, Payment $payment, ConfigServiceInterface $configService)
    {
        return $this->render('@c975LPayment/pages/display.html.twig', array(
            'payment' => $payment,
            'siteName' => $configService->getParameter('c975LCommon.site'),
        ));
    }
946597
public function showPaymentInstructions(Payment $payment): string
	{
		if (empty($_REQUEST['tp_radio_value']) || empty($_REQUEST['tp_radio_is_offline'])) {
			return '';
		}

		$this->clearCookies();

		$href = "{$this->config->gateUrl}radiobuttons/style/radiobuttons.css?v=" . time();
		$href = Escaper::htmlEntityEncode($href);
		$out = "<link href=\"{$href}\" type=\"text/css\" rel=\"stylesheet\" />\n";

		$out .= "<script type=\"text/javascript\">\n";

		$payment->setMethodId(intval($_REQUEST['tp_radio_value']));
		$queryArgs = $payment->getArgs();
		$queryArgs['signature'] = $payment->getSignature();
		$thepayGateUrl = "{$this->config->gateUrl}?" . http_build_query($queryArgs);
		$thepayGateUrl = Escaper::jsonEncode($thepayGateUrl);
		$out .= "\tvar thepayGateUrl = {$thepayGateUrl},\n";

		$thepayDisablePopupCss = Escaper::jsonEncode($this->disablePopupCss);
		$out .= "\tthepayDisablePopupCss = {$thepayDisablePopupCss};\n";

		$out .= "</script>\n";

		$src = "{$this->config->gateUrl}radiobuttons/js/jquery.js?v=" . time();
		$src = Escaper::htmlEntityEncode($src);
		$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>";

		$src = "{$this->config->gateUrl}radiobuttons/js/radiobuttons.js?v=" . time();
		$src = Escaper::htmlEntityEncode($src);
		$out .= "<script type=\"text/javascript\" src=\"{$src}\" async=\"async\"></script>";

		$out .= '<div id="thepay-method-result"></div>';

		return $out;
	}
289566
protected function validatePaymentTransaction(PaymentTransaction $paymentTransaction)
    {
        $this->validateQueryConfig($paymentTransaction);

        $errorMessage   = '';
        $missedFields   = array();
        $invalidFields  = array();

        foreach (static::$requestFieldsDefinition as $fieldDescription)
        {
            list($fieldName, $propertyPath, $isFieldRequired, $validationRule) = $fieldDescription;

            $fieldValue = PropertyAccessor::getValue($paymentTransaction, $propertyPath, false);

            if (!empty($fieldValue))
            {
                try
                {
                    Validator::validateByRule($fieldValue, $validationRule);
                }
                catch (ValidationException $e)
                {
                    $invalidFields[] = "Field '{$fieldName}' from property path '{$propertyPath}', {$e->getMessage()}.";
                }
            }
            elseif ($isFieldRequired)
            {
                $missedFields[] = "Field '{$fieldName}' from property path '{$propertyPath}' missed or empty.";
            }
        }

        if (!empty($missedFields))
        {
            $errorMessage .= "Some required fields missed or empty in PaymentTransaction: \n" .
                             implode("\n", $missedFields) . "\n";
        }

        if (!empty($invalidFields))
        {
            $errorMessage .= "Some fields invalid in PaymentTransaction: \n" .
                             implode("\n", $invalidFields) . "\n";
        }

        if (!empty($errorMessage))
        {
            throw new ValidationException($errorMessage);
        }
    }
447992
protected function updatePaymentTransaction(PaymentTransaction $paymentTransaction, CallbackResponse $callbackResponse)
    {
        $paymentTransaction->setStatus($callbackResponse->getStatus());
        $paymentTransaction->getPayment()->setPaynetId($callbackResponse->getPaymentPaynetId());

        if ($callbackResponse->isError() || $callbackResponse->isDeclined())
        {
            $paymentTransaction->addError($callbackResponse->getError());
        }
    }
722412
public function isActionAvailable($action, $payment = null)
    {
        if ($payment) {
            $this->setPayment($payment);
        }

        $payment = $this->getPayment();

        $isAvailable = in_array($action, $this->getAvailableActions($payment->getAction(), $payment->getStatus()));

        if ($isAvailable) {
            $isAvailable = false;

            switch ($action) {
                case 'refund':
                    $isAvailable = ($payment->getAmount() > $payment->getRefundedAmount());
                    break;
            }
        }

        return $isAvailable;
    }
912963
private function processTransaction(Transaction $transaction, PaymillMethod $paymentMethod)
    {
        /**
         * Payment paid done
         *
         * Paid process has ended ( No matters result )
         */
        $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod);

        /**
         * when a transaction is successful, it is marked as 'closed'
         */
        $transactionStatus = $transaction->getStatus();
        if (empty($transactionStatus) || $transactionStatus != 'closed') {

            /**
             * Payment paid failed
             *
             * Paid process has ended failed
             */
            $paymentMethod->setTransaction($transaction);
            $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod);

            throw new PaymentException();
        }

        /**
         * Adding to PaymentMethod transaction information
         *
         * This information is only available in PaymentOrderSuccess event
         */
        $paymentMethod
            ->setTransactionId($transaction->getId())
            ->setTransactionStatus($transactionStatus)
            ->setTransaction($transaction);

        /**
         * Payment paid successfully
         *
         * Paid process has ended successfully
         */
        $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod);

        return $this;
    }
579247
public function process(PaymentTransaction $transaction)
    {
        if (!isset($transaction->gateway)) {
            throw new CException('Cannot start transaction without a payment gateway.');
        }
        if (!isset($transaction->shippingContactId)) {
            throw new CException('Cannot start transaction without a shipping contact.');
        }
        if (!count($transaction->items)) {
            throw new CException('Cannot start transaction without any items.');
        }

        $gateway = $this->createGateway($transaction->gateway);
        try {
            $gateway->prepareTransaction($transaction);
            $this->changeTransactionStatus(PaymentTransaction::STATUS_STARTED, $transaction);
            $gateway->processTransaction($transaction);
            $this->changeTransactionStatus(PaymentTransaction::STATUS_PROCESSED, $transaction);
            $gateway->resolveTransaction($transaction);
        } catch (CException $e) {
            $this->changeTransactionStatus(PaymentTransaction::STATUS_FAILED, $transaction);
            throw $e;
        }
    }
1179757
public function create($amount, $payment, $options = [])
    {
        $params = [];

        $params = $this->addPaymentMethod($params, $payment, $options);
        $params = $this->addOrder($params, $amount, $options);
        $params = $this->addCustomer($params, $options);

        return $this->gateway->commit('post', $this->gateway->buildUrlFromString('charges'), $params);
    }
628162
protected static function deletePaymentTransactionByIdAsyncWithHttpInfo($payment_transaction_id) 
    {
        $returnType = '';  
        $request = self::deletePaymentTransactionByIdRequest($payment_transaction_id); 

        return self::getHttpClient()
            ->sendAsync($request, self::createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
686372
private function compareStatus($order, $payment)
    {
        if (! (in_array($order->getStatus(), [
                $this->getStatusFromPaymentKey(1),
                $this->getStatusFromPaymentKey(2)
            ]) || in_array($payment->getStatus(), [1, 2]))) {
            return false;
        }
        return true;
    }
283681
public function getFor(Payment $payment, $captureId, array $parameters = [])
    {
        return $this->getForId($payment->id, $captureId, $parameters);
    }