Pay an order.

@author yansongda <me@yansongda.cn>

@param string $gateway
@param array  $params

@return Response|Collection
540248
public function pay($gateway, $params = [])
    {
        $this->payload['biz_content'] = json_encode($params);

        $gateway = get_class($this).'\\'.Str::studly($gateway).'Gateway';

        if (class_exists($gateway)) {
            return $this->makePay($gateway);
        }

        throw new InvalidGatewayException("Pay Gateway [{$gateway}] not exists");
    }
1309352
public function getGatewayInstance($gateway = null)
    {
        require __DIR__ . '/vendor/autoload.php';

        foreach ($this->getGateways() as $id) {
            $class = \Omnipay\Common\Helper::getGatewayClassName($id);
            if (class_exists($class)) {
                \Omnipay\Omnipay::register($id);
            }
        }

        $instances = array();
        foreach (\Omnipay\Omnipay::find() as $id) {
            $instances[$id] = \Omnipay\Omnipay::create($id);
        }

        if (isset($gateway)) {
            return empty($instances[$gateway]) ? null : $instances[$gateway];
        }

        return $instances;
    }
257992
protected function redirectToCas($gateway = false)
    {
        $query['service'] = self::getDefaultService();
        if ($gateway) {
            $query['gateway'] = 'true';
        }
        self::http_redirect($this->server['login_url'] . '?' . http_build_query($query));
        // never reached
        return true;
    }
1078570
public function createOrder($parameters = [])
    {
        $response = $this->client->post('transactions/orders', [
            'json' => $parameters,
        ]);
        return json_decode($response->getBody())->order;
    }
876097
protected function addShipping(array $params, array $options)
    {
        if ($address = Arr::get($options, 'shipping_address')) {
            $params['application_context']['shipping_preference'] = 'SET_PROVIDED_ADDRESS';
            $params['transactions'][0]['amount']['details']['shipping'] = $this->gateway
                ->amount(Arr::get($address, 'price', 0));

            $params['transactions'][0]['item_list']['shipping_address'] = [
                'recipient_name' => trim(Arr::get($options, 'name')),
                'line1'          => Arr::get($address, 'address1', ''),
                'line2'          => Arr::get($address, 'address2', ''),
                'city'           => Arr::get($address, 'city', ''),
                'country_code'   => Arr::get($address, 'country', ''),
                'postal_code'    => Arr::get($address, 'zip', ''),
                'state'          => Arr::get($address, 'state', ''),
                'phone'          => Arr::get($options, 'phone', ''),
            ];
        } else {
            $params['application_context']['shipping_preference'] = 'NO_SHIPPING';
        }

        return $params;
    }
1372091
public function createPayment($data, $filters = [])
    {
        return $this->client->orderPayments->createFor($this, $data, $filters);
    }
422604
protected function addOrder(array $params, $money, array $options)
    {
        return array_merge($params, [
            'amount'      => $this->gateway->amount($money),
            'currency'    => Arr::get($options, 'currency', $this->gateway->getCurrency()),
            'description' => Helper::ascii(Arr::get($options, 'description', 'PayMe Purchase')),
            'order_id'    => Arr::get($options, 'reference'),
        ]);
    }
738718
public function execute(array $params = []) : Result
    {
        $params = array_replace($this->parameters, $params);

        if (
            empty($this->fields)
            && empty($this->avgAggregate)
            && empty($this->countAggregate)
            && empty($this->minAggregate)
            && empty($this->maxAggregate)
            && empty($this->sumAggregate)
        ) {
            $this->fields = ['*'];
        }

        return $this->connection->select($this, $params);
    }
1320992
public function create(array $params = [])
    {
        return $this->executeRequest(
            RequestMethodEnum::POST,
            ResourceMethodEnum::CREATE,
            $params,
            null
        );
    }
992642
public function callback(array $params = null)
	{
		$this->cleanup();

		if(null === $params){
			if(!empty($_POST)){
				$params = $_POST;
			}
		}

		if (
			empty($params) ||
			empty($params['term']) ||
			empty($params['sign']) ||
			empty($params['type'])
		) {
			throw new GatewayException('Input params is failure');
		}

		$type = $params['type'];

		if(!isset(self::$customParams[$type])){
			throw new GatewayException('Undefined type value');
		}

		$sign = $this->sign($type, $params);

		if($sign !== $params['sign']){
			throw new GatewayException('Signature check fail');
		}

		$this->rawResponse = http_build_url($params);

		/** @var stdClass response */
		$this->response = (object)$params;

		if ($this->response->rc !== '00') {
			$this->error = array(
				'type'    => self::C_ERROR_PROCESSING,
				'message' => $this->response->message,
			);
		}

		return empty($this->error);

	}
1131870
public function createTransaction(array $params)
    {
        $this->sdk->Send = array_merge($this->sdk->Send, [
            'MerchantTradeNo' => '',
            'MerchantTradeDate' => date('Y/m/d H:i:s'),
            'LogisticsType' => '',
            'LogisticsSubType' => LogisticsSubType::UNIMART,
            'GoodsAmount' => 0,
            'CollectionAmount' => 0,
            'IsCollection' => IsCollection::NO,
            'GoodsName' => '',
            'SenderName' => '',
            'SenderPhone' => '',
            'SenderCellPhone' => '',
            'ReceiverName' => '',
            'ReceiverPhone' => '',
            'ReceiverCellPhone' => '',
            'ReceiverEmail' => '',
            'TradeDesc' => '',
            'ServerReplyURL' => '',
            'LogisticsC2CReplyURL' => '',
            'Remark' => '',
            'PlatformID' => '',
        ]);

        $this->sdk->SendExtend = [];

        $this->sdk->Send = array_replace(
            $this->sdk->Send,
            array_intersect_key($params, $this->sdk->Send)
        );

        $this->sdk->Send['GoodsAmount'] = (int) $this->sdk->Send['GoodsAmount'];
        $this->sdk->Send['CollectionAmount'] = (int) $this->sdk->Send['CollectionAmount'];

        if (empty($this->sdk->Send['LogisticsType']) === true) {
            $this->sdk->Send['LogisticsType'] = LogisticsType::CVS;
            switch ($this->sdk->Send['LogisticsSubType']) {
                case LogisticsSubType::TCAT:
                    $this->sdk->Send['LogisticsType'] = LogisticsType::HOME;
                    break;
            }
        }

        if ($this->sdk->Send['IsCollection'] === IsCollection::NO) {
            $this->sdk->Send['CollectionAmount'] = 0;
        } elseif (isset($this->sdk->Send['CollectionAmount']) === false) {
            $this->sdk->Send['CollectionAmount'] = (int) $this->sdk->Send['GoodsAmount'];
        }

        switch ($this->sdk->Send['LogisticsType']) {
            case LogisticsType::HOME:
                $this->sdk->SendExtend = array_merge($this->sdk->SendExtend, [
                    'SenderZipCode' => '',
                    'SenderAddress' => '',
                    'ReceiverZipCode' => '',
                    'ReceiverAddress' => '',
                    'Temperature' => '',
                    'Distance' => '',
                    'Specification' => '',
                    'ScheduledDeliveryTime' => '',
                ]);
                break;
            case LogisticsType::CVS:
                $this->sdk->SendExtend = array_merge($this->sdk->SendExtend, [
                    'ReceiverStoreID' => '',
                    'ReturnStoreID' => '',
                ]);
                break;
        }

        $this->sdk->SendExtend = array_replace(
            $this->sdk->SendExtend,
            array_intersect_key($params, $this->sdk->SendExtend)
        );

        return $this->sdk->BGCreateShippingOrder();
    }
387791
public static function doCardPayment($arg_params)
    {
        //validate params
        $data = self::getParams($arg_params);
        if(!empty($data['order'])){
            $data['rdata']['order'] = json_decode(json_encode($data['order']), true);
        }
        unset($data['order']);
        if(!empty($data['metadata'])){
            $data['metadata'] = json_decode(json_encode($data['metadata']),true);
        }
        $data['source_id'] = Due::getAppId();
        $data['rail_type'] = Due::getRailType();
        $data['amount'] = number_format(floatval($data['amount']), 2, '.', '');

        if(
            !empty($data['webhook_url']) &&
            (!preg_match("%^(http|https)://\S+%", $data['webhook_url']) ||
                filter_var($data['webhook_url'], FILTER_VALIDATE_URL) === false)
        ){
            throw new \Exception('invalid webhook url given',4040001);
        }

        //submit to api
        $customer_data = APIRequests::request(
            '/ecommerce/payments/card',
            APIRequests::METHOD_POST,
            array('payload'=>$data)
        );

        //return response
        return self::toObj($customer_data['body']);
    }
76783
protected function addPayment($params, $amount, $payment, $options)
    {
        return array_merge($params, [
            'payment' => [
                'external' => [
                    'transaction'     => Arr::get($options, 'reference'),
                    'application_key' => $this->gateway->getApplicationKey(),
                ],
                'reference' => [
                    'number'      => Arr::get($options, 'reference'),
                    'description' => Arr::get($options, 'description'),
                ],
                'total' => [
                    'amount'   => $this->gateway->amount($amount),
                    'currency' => Arr::get($options, 'currency', $this->gateway->getCurrency()),
                ],
                'origin'    => [
                    'ip'       => Arr::get($options, 'ip', ''),
                    'location' => [
                        'latitude'  => Arr::get($options, 'latitude', '0.00000'),
                        'longitude' => Arr::get($options, 'longitude', '0.00000'),
                    ],
                ],
            ],
            'recurrent' => $payment,
            'total'     => [
                'amount' => $this->gateway->amount($amount),
            ],
        ]);
    }
877124
public static function listAllPaymentsAsync(array $parameters = [])
    {
        return self::listAllPaymentsAsyncWithHttpInfo($page, $size, $sort)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }
176301
public function load($gatewayAccountId, $downtimeId, $params = [])
    {
        return $this->client()->get(
            'gateway-accounts/{gatewayAccountId}/downtime-schedules/{downtimeId}',
            ['downtimeId' => $downtimeId, 'gatewayAccountId' => $gatewayAccountId] + (array) $params
        );
    }
289277
public function buy($params = null)
    {
        $requestor = new Requestor($this->_apiKey);
        $url = $this->instanceUrl() . '/buy';

        list($response, $apiKey) = $requestor->request('post', $url, $params);
        $this->refreshFrom($response, $apiKey, true);

        return $this;
    }
926843
protected function setGateway($gateway = null)
    {
        $deferred = new Deferred();

        $buildParams = function ($gateway) use ($deferred) {
            $params = [
                'v'        => self::GATEWAY_VERSION,
                'encoding' => $this->encoding,
            ];

            $query         = http_build_query($params);
            $this->gateway = trim($gateway, '/').'/?'.$query;

            $deferred->resolve($this->gateway);
        };

        if (is_null($gateway)) {
            $this->http->get('gateway')->then(function ($response) use ($buildParams) {
                $buildParams($response->url);
            }, function ($e) use ($buildParams) {
                // Can't access the API server so we will use the default gateway.
                $buildParams('wss://gateway.discord.gg');
            });
        } else {
            $buildParams($gateway);
        }

        $deferred->promise()->then(function ($gateway) {
            $this->logger->info('gateway retrieved and set', ['gateway' => $gateway]);
        }, function ($e) {
            $this->logger->error('error obtaining gateway', ['e' => $e->getMessage()]);
        });

        return $deferred->promise();
    }