Create a Charge

@param Object $authorized instanceof Shopify || User
@param array $options
@return $this
@throws Exception
198838
public function create($authorized, array $options)
    {

        if($authorized instanceof Shopify)
        {
            if(!$authorized->getUser())
                throw new Exception('Cannot charge user without getting their installation permissions!');

            $this->setRequestPath( $authorized );
            $token = $authorized->getUser()->token;
        }
        elseif($authorized instanceof User)
        {
            $this->setRequestPath($authorized->name);
            $token = $authorized->token;
        }
        else throw new \InvalidArgumentException('Argumant must be an instance of Shopify or Laravel\Socialite\Two\User');

        $this->options = $options;


        $createURL = $this->getChargeEndpoint() . '.json';


        $this->charge = $this->getCreateChargeResponse($createURL, $token);

        return $this;
    }
1254799
public function sendRequest(RequestInterface $request, array $options = [])
    {
        $request = $request->withHeader('Content-Type', 'application/json');
        $request = $this->credential->applyToRequest($request);
        if (static::$delayNextRequest) {
            usleep(1000000 * rand(3, 10));
        }
        try {
            $response = $this->getHttpClient()->send($request, $options);
        } catch (RequestException $exception) {
            $exception = new ClientException($request, $exception->getResponse(), $exception->getMessage());
            throw $exception;
        }
        list($callsMade, $callsLimit) = explode('/', $response->getHeaderLine('http_x_shopify_shop_api_call_limit'));
        static::$delayNextRequest = $callsMade / $callsLimit >= 0.8;

        return $response;
    }
268472
public function void($authorization, $options = array())
    {
        $this->required_options('pasref, order_id', $options);
        $this->buildVoidRequest($authorization, $options);

        return $this->commit();
    }
879536
public function create($token, array $options = [])
    {
        $entity = new Token(compact('token'));

        foreach (['user_id', 'type', 'extra', 'expiry'] as $key) {
            if (array_key_exists($key, $options)) {
                $entity->set($key, $options[$key]);
            }
        }

        if (!$this->getTable()->save($entity)) {
            $field = collection(array_keys($entity->getErrors()))->first();
            $error = collection(collection(($entity->getErrors()))->first())->first();

            throw new LogicException(sprintf('Error for `%s` field: %s', $field, lcfirst($error)));
        }

        return $entity->token;
    }
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);
    }
1252504
public function authorize($ability, $arguments = [])
    {
        if (!$response = app('scaffold.actions')->authorize($ability, $arguments)) {
            throw $this->createGateUnauthorizedException(
                $ability,
                $this->translator->trans('administrator::errors.unauthorized')
            );
        }

        return $response;
    }
1198569
public function charge($amount, array $options = []): Charge
    {
        $options = array_merge([
            'currency' => $this->preferredCurrency(),
        ], $options);

        $options['amount'] = $amount;

        if (!array_key_exists('source', $options) && $this->stripe_id) {
            $options['customer'] = $this->stripe_id;
        }

        if (!array_key_exists('source', $options) && !array_key_exists('customer', $options)) {
            throw new InvalidArgumentException('No payment source provided.');
        }

        return Charge::create($options, ['api_key' => $this->getStripeKey()]);
    }
1332543
public function authorize($money, CreditCard $creditcard, $options = array())
    {
        $this->required_options('address,order_id', $options);

        $this->post = array();

        $this->addInvoice($options);
        $this->addCreditcard($creditcard);
        $this->addAddress($options);
        $this->addCustomerData($options);
        $this->addOptionalData();

        $this->post['TotalAmount'] = $this->amount($money);

        return $this->commit('xmlauth', $money, $options);
    }
881018
public function newAuthorizeRequest($owner, $owner_id, $options)
  {
    return $this->getOAuth()->getAuthServer()
          ->getGrantType('authorization_code')
          ->newAuthoriseRequest($owner, $owner_id, $options);
  }
984161
public function connectOauth2($options)
    {
        $token = false;

        // source oauth provider
        $oauthProvider = $this->getProvider();

        // error
        if(\Craft\craft()->request->getParam('error'))
        {
            throw new \Exception("An error occured: ".\Craft\craft()->request->getParam('error'));
        }

        $state = \Craft\craft()->request->getParam('state');
        $code = \Craft\craft()->request->getParam('code');
        $oauth2state = \Craft\craft()->httpSession->get('oauth2state');

        if (is_null($code))
        {
            $authorizationOptions = $options['authorizationOptions'];

            if(count($options['scope']) > 0)
            {
                $authorizationOptions['scope'] = $options['scope'];
            }

            $authorizationUrl = $oauthProvider->getAuthorizationUrl($authorizationOptions);

            $state = $oauthProvider->getState();

            \Craft\craft()->httpSession->add('oauth2state', $state);

            OauthPlugin::log('OAuth 2.0 Connect - Redirect to the authorization URL'."\r\n".
	            "authorizationUrl: ".$authorizationUrl."\r\n".
	            "oauth2state: ".\Craft\craft()->httpSession->get('oauth2state')
	        , LogLevel::Info);

            \Craft\craft()->request->redirect($authorizationUrl);
        }
        elseif (!$state || $state !== $oauth2state)
        {
            OauthPlugin::log('OAuth 2.0 Connect - Invalid State'."\r\n".print_r([
                'state' => $state,
                'oauth2state' => $oauth2state,
            ], true), LogLevel::Info);

            \Craft\craft()->httpSession->remove('oauth2state');

            throw new \Exception("Invalid state");

        }
        else
        {
            OauthPlugin::log('OAuth 2.0 Connect - Authorization code retrieved: '.$code, LogLevel::Info);

            $token = $oauthProvider->getAccessToken('authorization_code', [
                'code' => $code
            ]);

            OauthPlugin::log("OAuth 2.0 Connect - Get Access Token\r\n".
	            "Access token: \r\n".
	            print_r($token, true)
	        , LogLevel::Info);
        }

        return $token;
    }
1354673
public function newAuthorizeRequest($owner, $owner_id, $options)
  {
    return $this->authServer->getGrantType('authorization_code')->newAuthoriseRequest($owner, $owner_id, $options);
  }
1073538
public function charge($amount = null)
    {
        return (new AuthorizationBuilder(TransactionType::SALE, $this))
                        ->withAmount($amount)
                        ->withOneTimePayment(true);
    }
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;
    }
149388
public function make($original, $options = null)
    {
        if (is_array($options)) {
            $this->setMemory($options['memory'])->setTime($options['time'])->setThreads($options['threads']);
        }

        $hash = password_hash($original, $this->algorithm(), [
            'memory_cost' => $this->getMemory(),
            'time_cost'   => $this->getTime(),
            'threads'     => $this->getThreads(),
        ]);

        if (empty($hash)) {
            throw new \Exception($this->algorithmKeys().' hashing not supported.', 500);
        }

        return $hash;
    }
1190757
public static function makeIf($condition, $options)
    {
        if (value($condition)) {
            return static::make($options);
        }

        return static::make()->authorized(false);
    }
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;
	}
668007
private function createCustomerWithUserAccount(
        $email,
        $password,
        $enabled = true,
        $firstName = null,
        $lastName = null,
        $role = null
    ) {
        /** @var ShopUserInterface $user */
        $user = $this->userFactory->createNew();

        /** @var CustomerInterface $customer */
        $customer = $this->customerFactory->createNew();

        $customer->setFirstName($firstName);
        $customer->setLastName($lastName);
        $customer->setEmail($email);

        $user->setUsername($email);
        $user->setPlainPassword($password);
        $user->setEnabled($enabled);
        if (null !== $role) {
            $user->addRole($role);
        }

        $customer->setUser($user);

        $this->sharedStorage->set('customer', $customer);

        return $customer;
    }