Add payment method to request.

@param string[] $params
@param mixed    $payment
@param string[] $options

@return array
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;
    }
26292
protected function makeTransaction(OrderInterface $order, PaymentInterface $payment, array $options = []): TransactionInterface
    {
        $transaction = new Transaction([
            'type' => Transaction::TYPE_PAYMENT,
            'status' => Transaction::STATUS_PENDING,
            'amount' => $payment->getAmount(),
            'driver' => $this->getShop(),
            'client' => $payment->getClient()->getId(),
            'options' => $options,
        ]);

        $transaction->order()->associate($order);

        $transaction->save();

        return $transaction;
    }
283681
public function getFor(Payment $payment, $captureId, array $parameters = [])
    {
        return $this->getForId($payment->id, $captureId, $parameters);
    }
7494
public function authorize($money, Merchant_Billing_CreditCard $creditcard, $options = array())
  {
      $this->required_options('customer_email', $options);
      $this->build_xml($money, 'PreAuth', $creditcard, $options);

      return $this->commit();
  }
1077212
protected function addAdditionData(array $params, array $options)
    {
        if (isset($options['application']) && ctype_digit((string) $options['application'])) {
            $params['sponsor_id'] = (int) $options['application'];
        }

        if (isset($options['notify_url'])) {
            $params['notification_url'] = $options['notify_url'];
        }

        return $params;
    }
333228
public function getList(array $options = array())
    {
        $methods = &gplcart_static(gplcart_array_hash(array('payment.methods' => $options)));

        if (isset($methods)) {
            return $methods;
        }

        $methods = $this->getDefaultList();
        $this->hook->attach('payment.methods', $methods, $this);

        $weights = array();
        foreach ($methods as $id => &$method) {

            $method['id'] = $id;

            if (!isset($method['weight'])) {
                $method['weight'] = 0;
            }

            if (!empty($options['status']) && empty($method['status'])) {
                unset($methods[$id]);
                continue;
            }

            if (!empty($options['module'])
                && (empty($method['module']) || !in_array($method['module'], (array) $options['module']))) {
                unset($methods[$id]);
                continue;
            }

            $weights[] = $method['weight'];
        }

        if (empty($methods)) {
            return array();
        }

        // Sort by weight then by key
        array_multisort($weights, SORT_ASC, array_keys($methods), SORT_ASC, $methods);
        return $methods;
    }
563905
public function syncAll(array $options = [])
    {
        $sites = $this->siteRepository->findAll();

        foreach ($sites as $site) {
            $paymentMethods = \GuzzleHttp\json_decode((string) $this->api->settings->getPaymentMethods($site->getExternalId())->getBody());

            foreach ($paymentMethods as $paymentMethod) {
                $entity = $this->paymentMethodUpdater->updateFromApiResponse(DandomainFoundation\objectToArray($paymentMethod), $site->getCurrency()->getIsoCodeAlpha());
                $this->repository->save($entity);
            }
        }
    }
270331
public static function charge(array $options = array())
    {
        $api = new Api\Charge();

        if (isset($options['pincode'])) {
            $api->setPincode($options['pincode']);
        }
        if (isset($options['cardNumber'])) {
            $api->setCardNumber($options['cardNumber']);
        }
        if (isset($options['amount'])) {
            $api->setAmount(round($options['amount'] * 100));
        }
        $result = $api->doRequest();

        return $result['request']['result'] == 1;
    }
246223
protected function addPaymentMethod(array $params, $amount, $payment, array $options)
    {
        if (is_string($payment)) {
            if ($payment == 'spei') {
                $params['charges'][0]['payment_method']['type'] = 'spei';
                $params['charges'][0]['payment_method']['expires_at'] = Arr::get($options, 'expires', strtotime(date('Y-m-d H:i:s')) + 172800);
            } elseif ($payment == 'oxxo') {
                $params['charges'][0]['payment_method']['type'] = 'oxxo';
                $params['charges'][0]['payment_method']['expires_at'] = Arr::get($options, 'expires', strtotime(date('Y-m-d H:i:s')) + 172800);
            } elseif ($payment == 'oxxo_cash') {
                $params['charges'][0]['payment_method']['type'] = 'oxxo_cash';
                $params['charges'][0]['payment_method']['expires_at'] = Arr::get($options, 'expires', strtotime(date('Y-m-d H:i:s')) + 172800);
            } elseif (Helper::startsWith($payment, 'cus_')) {
                $params['customer_info']['customer_id'] = $payment;
                $params['charges'][0]['payment_method']['type'] = 'default';
            } elseif (Helper::startsWith($payment, 'payee_')) {
                $params['charges'][0]['payment_method']['type'] = 'payout';
                $params['charges'][0]['payment_method']['payee_id'] = $payment;
            } else {
                $params['charges'][0]['payment_method']['type'] = 'card';
                $params['charges'][0]['payment_method']['token_id'] = $payment;
            }
        } elseif ($payment instanceof CreditCard) {
            $params['charges'][0]['payment_method']['card'] = [];
            $params['charges'][0]['payment_method']['card']['name'] = $payment->getName();
            $params['charges'][0]['payment_method']['card']['cvc'] = $payment->getCvv();
            $params['charges'][0]['payment_method']['card']['number'] = $payment->getNumber();
            $params['charges'][0]['payment_method']['card']['exp_month'] = $payment->getExpiryMonth();
            $params['charges'][0]['payment_method']['card']['exp_year'] = $payment->getExpiryYear();
            $params['charges'][0]['payment_method']['card'] = $this->addAddress($params['charges'][0]['source']['card'], $options);
        }

        if (isset($options['monthly_installments']) && in_array($options['monthly_installments'], [3, 6, 9, 12])) {
            $params['charges'][0]['payment_method']['monthly_installments'] = (int) $options['monthly_installments'];
        }

        $params['charges'][0]['amount'] = (int) $this->gateway->amount($amount);

        return $params;
    }
577858
def make_payment(options = {})
      response = JSON.parse(@client.patch("items/#{send(:id)}/make_payment", options).body)
      @attributes = response['items']
      true
    end
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);
    }
1264907
public function create($amount, $payment, $options = [])
    {
        $params = [];

        $params = $this->addPayment($params, $amount, $payment, $options);

        $params = Encryption::encryptParametersWithString($params);
        $params = $this->addMetadata($params, $amount, $options);

        return $this->gateway->commit('post', $this->gateway->buildUrlFromString('payment/card'), $params);
    }
235606
public function charge($amount, array $options = array())
	{
		// $options = array_merge([
		// 	'currency' => $this->getCurrency(),
		// ], $options);
		
		$options['amount'] = $amount / 100;
		
		// if (! array_key_exists('source', $options) && $this->billable->hasBraintreeId()) {
		// 	$options['customer'] = $this->billable->getBraintreeId();
		// }
		
		// if (! array_key_exists('source', $options) && ! array_key_exists('customer', $options)) {
		// 	throw new InvalidArgumentException("No payment source provided.");
		// }
		
		// try {
			$response = BraintreeCharge::sale($options);
		// }
		// catch (StripeErrorCard $e) {
		// 	return false;
		// }
		
		return $response;
	}
1330746
public function PaymentOrderCreate(array $params)
    {
        $request = new Request();
        $request->setMethod('POST');

        foreach (array('PaymentPageId', 'Amount', 'Currency', 'MerchantUrls') as $param) {
            if (!isset($params[$param])) {
                throw new InvalidArgumentException($param);
            }
        }

        $params['MerchantId'] = $this->options['merchantId'];
        $request->setContent(json_encode(array('PaymentOrder' => $params)));

        return $this->doRequest('PaymentOrder/Create', $request)->getContentJson();
    }
812883
public function createPayment(array $options = [], array $filters = [])
    {
        return $this->client->customerPayments->createFor($this, $options, $filters);
    }
1014894
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([
                'body' => !empty($payment->model_id) ? $payment->model_id : '充值',
                'out_trade_no' => $payment->id,
                'total_fee' => round($payment->money * 100),
                'fee_type' => $payment->currency,
                'spbill_create_ip' => $payment->ip,
                'trade_type' => $this->tradeTypeMap[$payment->trade_type],
            ]);
            if ($payment->trade_type == Payment::TYPE_JS_API) {//微信扫码付必须得字段
                $params['openid'] = $payment->user->wechat->openid;
            }
            $params['sign'] = $this->createSign($params);
            /** @var \yii\httpclient\Response $response */
            $response = $this->api('https://api.mch.weixin.qq.com/pay/unifiedorder', 'POST', $params);//统一下单
            if ($response->isOk && $response->data['return_code'] == 'SUCCESS') {
                $payment->updateAttributes(['pay_id' => $response->data['prepay_id']]);
                if ($payment->trade_type == Payment::TYPE_JS_API) {
                    $paymentParams = [
                        'appId' => $this->appId,
                        'timeStamp' => time(),
                        'nonceStr' => md5(uniqid()),
                        'package' => 'prepay_id=' . $response->data['prepay_id'],
                        'signType' => 'MD5',
                    ];
                    $paymentParams['paySign'] = $this->makeSign($paymentParams);
                    return;
                } elseif ($payment->trade_type == Payment::TYPE_NATIVE) {
                    $paymentParams['url'] = $response->data['code_url'];
                    $paymentParams['data'] = (new QrCode())->setText($response->data['code_url'])->setSize(240)->setPadding(10)->getDataUri();
                    return;
                }
            } else {
                $paymentParams = $response->data;
            }
        }
    }
485490
public function charge($amount, array $options = []): Successful
    {
        $response = BraintreeTransaction::sale(array_merge([
            'amount' => number_format($amount * (1 + ($this->taxPercentage() / 100)), 2, '.', ''),
            'paymentMethodToken' => $this->paymentMethod()->token,
            'options' => [
                'submitForSettlement' => true,
            ],
            'recurring' => true,
        ], $options));

        if (! $response->success) {
            throw new Exception('Braintree was unable to perform a charge: '.$response->message);
        }

        return $response;
    }