@param StripeLocalCharge $charge

@return $this
493009
public function addCharge(StripeLocalCharge $charge)
    {
        // If the cards is already set
        if (false === $this->charges->contains($charge)) {
            // Add the card to the collection
            $this->charges->add($charge);
        }

        return $this;
    }
307356
public function syncLocalFromStripe(StripeLocalResourceInterface $localResource, ApiResource $stripeResource)
    {
        /** @var StripeLocalCard $localResource */
        if ( ! $localResource instanceof StripeLocalCard) {
            throw new \InvalidArgumentException('CardSyncer::hydrateLocal() accepts only StripeLocalCard objects as first parameter');
        }

        /** @var Card $stripeResource */
        if ( ! $stripeResource instanceof Card) {
            throw new \InvalidArgumentException('CardSyncer::hydrateLocal() accepts only Stripe\Card objects as second parameter.');
        }

        $reflect = new \ReflectionClass($localResource);

        foreach ($reflect->getProperties() as $reflectedProperty) {
            // Set the property as accessible
            $reflectedProperty->setAccessible(true);

            /*
             * Guess the kind and set its value (Customer has to be StripeLocalCustomerObject set before the Card
             * $localResource is passed to this hydration method!)
             */
            switch ($reflectedProperty->getName()) {
                case 'id':
                    $reflectedProperty->setValue($localResource, $stripeResource->id);
                    break;

                case 'addressCity':
                    $reflectedProperty->setValue($localResource, $stripeResource->address_city);
                    break;

                case 'addressCountry':
                    $reflectedProperty->setValue($localResource, $stripeResource->address_country);
                    break;

                case 'addressLine1':
                    $reflectedProperty->setValue($localResource, $stripeResource->address_line1);
                    break;

                case 'addressLine1Check':
                    $reflectedProperty->setValue($localResource, $stripeResource->address_line1_check);
                    break;

                case 'addressLine2':
                    $reflectedProperty->setValue($localResource, $stripeResource->address_line2);
                    break;

                case 'addressState':
                    $reflectedProperty->setValue($localResource, $stripeResource->address_state);
                    break;

                case 'addressZip':
                    $reflectedProperty->setValue($localResource, $stripeResource->address_zip);
                    break;

                case 'addressZipCheck':
                    $reflectedProperty->setValue($localResource, $stripeResource->address_zip_check);
                    break;

                case 'brand':
                    $reflectedProperty->setValue($localResource, $stripeResource->brand);
                    break;

                case 'country':
                    $reflectedProperty->setValue($localResource, $stripeResource->country);
                    break;

                case 'customer':
                    $localCustomer = $this->getLocalCustomer($stripeResource->customer);

                    if (false !== $localCustomer) {
                        $reflectedProperty->setValue($localResource, $localCustomer);
                    }
                    break;

                case 'cvcCheck':
                    $reflectedProperty->setValue($localResource, $stripeResource->cvc_check);
                    break;

                case 'dynamicLast4':
                    $reflectedProperty->setValue($localResource, $stripeResource->dynamic_last4);
                    break;

                case 'expMonth':
                    $reflectedProperty->setValue($localResource, $stripeResource->exp_month);
                    break;

                case 'expYear':
                    $reflectedProperty->setValue($localResource, $stripeResource->exp_year);
                    break;

                case 'fingerprint':
                    $reflectedProperty->setValue($localResource, $stripeResource->fingerprint);
                    break;

                case 'funding':
                    $reflectedProperty->setValue($localResource, $stripeResource->funding);
                    break;

                case 'last4':
                    $reflectedProperty->setValue($localResource, $stripeResource->last4);
                    break;

                case 'metadata':
                    $reflectedProperty->setValue($localResource, $stripeResource->metadata->__toArray());
                    break;

                case 'name':
                    $reflectedProperty->setValue($localResource, $stripeResource->name);
                    break;

                case 'tokenizationMethod':
                    $reflectedProperty->setValue($localResource, $stripeResource->tokenization_method);
                    break;
            }
        }
    }
1033738
public function setCardNumber($sCardNumber)
    {
        //  Validate
        if (preg_match('/[^\d ]/', $sCardNumber)) {
            throw new ChargeRequestException('Invalid card number; can only contain digits and spaces.', 1);

        }
        $this->oCard->number = $sCardNumber;
        return $this;
    }
1196781
public function execute($iAmount, $sCurrency)
    {
        //  Ensure we have a driver
        if (empty($this->oDriver)) {
            throw new ChargeRequestException('No driver selected.', 1);
        }

        //  Ensure we have an invoice
        if (empty($this->oInvoice)) {
            throw new ChargeRequestException('No invoice selected.', 1);
        }

        // --------------------------------------------------------------------------

        if (!is_int($iAmount) || $iAmount <= 0) {
            throw new ChargeRequestException('Amount must be a positive integer.', 1);
        }

        // --------------------------------------------------------------------------

        //  @todo: validate currency

        // --------------------------------------------------------------------------

        //  Create a charge against the invoice if one hasn't been specified
        if (empty($this->oPayment)) {

            $iPaymentId = $this->oPaymentModel->create(
                [
                    'driver'       => $this->oDriver->getSlug(),
                    'description'  => $this->getDescription(),
                    'invoice_id'   => $this->oInvoice->id,
                    'currency'     => $sCurrency,
                    'amount'       => $iAmount,
                    'url_continue' => $this->getContinueUrl(),
                    'custom_data'  => $this->oCustomData,
                ]
            );

            if (empty($iPaymentId)) {
                throw new ChargeRequestException('Failed to create new payment.', 1);
            }

            $this->setPayment($iPaymentId);
        }

        $mFields = $this->oDriver->getPaymentFields();

        if (!empty($mFields) && $mFields == 'CARD') {
            $oDriverData = $this->oCard;
        } else {
            $oDriverData = $this->oCustomField;
        }

        //  Return URL for drivers which implement a redirect flow
        $sSuccessUrl = site_url('invoice/payment/' . $this->oPayment->id . '/' . $this->oPayment->token . '/complete');
        $sFailUrl    = site_url('invoice/invoice/' . $this->oInvoice->ref . '/' . $this->oInvoice->token . '/pay');

        //  Execute the charge
        $oChargeResponse = $this->oDriver->charge(
            $iAmount,
            $sCurrency,
            $oDriverData,
            $this->oCustomData,
            $this->getDescription(),
            $this->oPayment,
            $this->oInvoice,
            $sSuccessUrl,
            $sFailUrl,
            $this->getContinueUrl()
        );

        //  Validate driver response
        if (empty($oChargeResponse)) {
            throw new ChargeRequestException('Response from driver was empty.', 1);
        }

        if (!($oChargeResponse instanceof ChargeResponse)) {
            throw new ChargeRequestException(
                'Response from driver must be an instance of \Nails\Invoice\Factory\ChargeResponse.',
                1
            );
        }

        //  Handle the response
        if ($oChargeResponse->isRedirect() && $this->isAutoRedirect()) {

            /**
             * Driver uses a redirect flow, determine whether we can use a basic header redirect,
             * or if we need to POST some data to the endpoint
             */

            $sRedirectUrl = $oChargeResponse->getRedirectUrl();
            $aPostData    = $oChargeResponse->getRedirectPostData();

            if (empty($aPostData)) {

                redirect($sRedirectUrl);

            } else {

                $oCi = get_instance();
                echo $oCi->load->view('structure/header/blank', getControllerData(), true);
                echo $oCi->load->view(
                    'invoice/pay/post',
                    [
                        'redirectUrl' => $sRedirectUrl,
                        'postFields'  => $aPostData,
                    ],
                    true
                );
                echo $oCi->load->view('structure/footer/blank', getControllerData(), true);
                exit();
            }

        } elseif ($oChargeResponse->isProcessing()) {

            //  Driver has started processing the charge, but it hasn't been confirmed yet
            $this->setPaymentProcessing(
                $oChargeResponse->getTxnId(),
                $oChargeResponse->getFee()
            );

        } elseif ($oChargeResponse->isComplete()) {

            //  Driver has confirmed that payment has been taken.
            $this->setPaymentComplete(
                $oChargeResponse->getTxnId(),
                $oChargeResponse->getFee()
            );

        } elseif ($oChargeResponse->isFailed()) {

            //  Update the payment
            $sPaymentClass = get_class($this->oPaymentModel);
            $bResult       = $this->oPaymentModel->update(
                $this->oPayment->id,
                [
                    'status'    => $sPaymentClass::STATUS_FAILED,
                    'fail_msg'  => $oChargeResponse->getError()->msg,
                    'fail_code' => $oChargeResponse->getError()->code,
                ]
            );

            if (empty($bResult)) {
                throw new ChargeRequestException('Failed to update existing payment.', 1);
            }
        }

        //  Set the success and fail URLs
        $oChargeResponse->setSuccessUrl($sSuccessUrl);
        $oChargeResponse->setFailUrl($sFailUrl);
        $oChargeResponse->setContinueUrl($this->getContinueUrl());

        //  Lock the response so it cannot be altered
        $oChargeResponse->lock();

        return $oChargeResponse;
    }
784938
public function updateBillingInfo($code = null, $data = [])
    {
        $payload = [];

        if (! $code) {
            $code = $this->data->code;
        }

        if (! empty($data)) {
            $payload['credit_card'] = $data;
        } elseif (isset($this->data->billing_info)) {
            $payload = $this->data->billing_info;
        }

        $this->client->put('/{code}/billing_infos', [$code], $payload);

        return $this;
    }
798225
public function incrementAndInvoice($count = 1)
    {
        $this->incrementQuantity($count);

        $this->user->invoice(['subscription' => $this->stripe_id]);

        return $this;
    }
156480
public function callLocal(...$args)
    {
        if (!sizeof($args)) {
            return $this;
        }
        $method = array_shift($args);
        $p = [
            'method' => $method,
            'arguments' => $args,
        ];
        $this->onPacket($p);
        return $this;
    }
481225
public function refundCardChargeRequest(RequestModels\ChargeRefund
	                                        $requestModel)
	{

		$chargeMapper = new ChargesMapper($requestModel);

		$requestPayload = array (
			'authorization' => $this->_apiSetting->getSecretKey(),
			'mode'          => $this->_apiSetting->getMode(),
			'postedParam'   => $chargeMapper->requestPayloadConverter(),

		);
		$refundUri = sprintf ($this->_apiUrl->getChargeRefundsApiUri(),$requestModel->getChargeId());

		$processCharge = \com\checkout\helpers\ApiHttpClient::postRequest($refundUri,
			$this->_apiSetting->getSecretKey(),$requestPayload);

		$responseModel = new ResponseModels\Charge($processCharge);


		return $responseModel;
	}
227220
public function upcomingInvoice(): ?Invoice
    {
        try {
            $stripeInvoice = StripeInvoice::upcoming(
                ['customer' => $this->stripe_id], ['api_key' => $this->getStripeKey()]
            );

            return new Invoice($this, $stripeInvoice);
        } catch (InvalidRequest $e) {
        }
    }
1257384
def capture(self):
		

		captured_charge = self.api_retrieve().capture()
		return self.__class__.sync_from_stripe_data(captured_charge)
929754
public function capture($charge)
    {
        $result = $this->request('POST', '/charges/' . $charge . '/capture');

        return $this->objectConverter->convert($result);
    }
12654
protected function getLocalCustomer($stripeCustomerId)
    {
        // First try to get the customer from the database
        $localCustomer = $this->getEntityManager()->getRepository('SHQStripeBundle:StripeLocalCustomer')->findOneByStripeId($stripeCustomerId);

        // If we found it, return it
        if (null !== $localCustomer) {
            return $localCustomer;
        }

        // Try to find the customer in the newly created one that are not already persisted
        return $this->getEntityManager()->getUnitOfWork()->tryGetById($stripeCustomerId, StripeLocalCustomer::class);
    }
808542
public function postChangeCard(BillingRequest $request)
    {
        try {
            $payload = $request->all();
            $creditCardToken = $payload['stripeToken'];
            auth()->user()->meta->updateCard($creditCardToken);
            return redirect('user/billing/details')->with('message', 'Your subscription has been updated!');
        } catch (Exception $e) {
            Log::error($e->getMessage());
            return back()->withErrors(['Could not process the billing please try again.']);
        }

        return back()->withErrors(['Could not complete billing, please try again.']);
    }
983357
public function createCharge(array $attributes)
    {
        // Log Debug
        $this->flow->getLogger()->debug('Charging: ' . json_encode($attributes));

        return $this->makeCharge(
            $this->flow->send(
                'post',
                $this->endpoint . '/charge',
                $attributes
            )
        );
    }
992111
public function setLocalOnly($value = false) {
    	$this->_localOnly = $value;
    	$this->_scope = $value ? $this->_worksheet : null;
    	return $this;
    }
590972
public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        parent::collect($address);

        // Makes sure you only use the address type shipping
        $items = $this->_getAddressItems($address);
        if (!count($items)) {
            return $this;
        }

        // reset totals by default (needed for some external checkout modules)
        $address->setPaymentInstallmentFeeAmount(0);
        $address->setBasePaymentInstallmentFeeAmount(0);

        $quote = $address->getQuote();

        if ($address->getAllItems()) {
            $currentAmount = $address->getPaymentInstallmentFeeAmount();
            $payment = $quote->getPayment();

            if ($payment && !empty($payment)) {
                $paymentMethod = $quote->getPayment()->getMethod();

                if ($paymentMethod == "adyen_cc" || substr($paymentMethod, 0, 14) == 'adyen_oneclick') {
                    $info = $payment->getMethodInstance();

                    $instance = $info->getInfoInstance();
                    $numberOfInstallments = $instance->getAdditionalInformation('number_of_installments');

                    if ($numberOfInstallments > 0) {
                        // get the Interest Rate of this installment

                        // get cc type
                        $ccType = $instance->getCcType();

                        // get installment for this specific card type
                        $ccTypeInstallments = "installments_" . $ccType;

                        $all_installments = Mage::helper('adyen/installments')->getInstallments(
                            null,
                            $ccTypeInstallments
                        );
                        if (empty($all_installments)) {
                            // use default installments
                            $all_installments = Mage::helper('adyen/installments')->getInstallments();
                        }

                        $installmentKey = $numberOfInstallments - 1;
                        $installment = $all_installments[$installmentKey];

                        if ($installment != null && is_array($installment)) {
                            // check if interest rate is filled in
                            if (isset($installment[3]) && $installment[3] > 0) {
                                $this->_setAmount(0);
                                $this->_setBaseAmount(0);

                                $interestRate = $installment[3];
                                $baseGrandTotal = $address->getGrandTotal();
                                $fee = ($baseGrandTotal / 100) * $interestRate;

                                $balance = $fee - $currentAmount;

                                $address->setPaymentInstallmentFeeAmount($address->getQuote()->getStore()->convertPrice($balance));
                                $address->setBasePaymentInstallmentFeeAmount($balance);

                                $address->setGrandTotal($address->getGrandTotal() + $address->getPaymentInstallmentFeeAmount());
                                $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBasePaymentInstallmentFeeAmount());
                            }
                        }
                    }
                }
            }
        }

        return $this;
    }
715488
public function orWhereRaw(string $condition): self
    {
        $this->condition->orWhere([new RawExp($condition)]);

        return $this;
    }