Populate a credit card from the paymnent form.

@param CreditCard            $card        The credit card to populate.
@param CreditCardPaymentForm $paymentForm The payment form.

@return void
338840
public function populateCard($card, CreditCardPaymentForm $paymentForm)
    {
        if (!$card instanceof CreditCard) {
            return;
        }

        $card->setFirstName($paymentForm->firstName);
        $card->setLastName($paymentForm->lastName);
        $card->setNumber($paymentForm->number);
        $card->setExpiryMonth($paymentForm->month);
        $card->setExpiryYear($paymentForm->year);
        $card->setCvv($paymentForm->cvv);
    }
911997
public function registerPayment(Payable $invoice, AbstractPayment $payment)
    {
        $classname = $this->getType($invoice);

        if (intval($invoice->getId()) == 0) {
            $invoice->save($this->getService($classname));
        }
        $idProperty = strtolower($classname) . 'Id';
        $payment->setData(array(
            $idProperty => $invoice->getId()
        ));

        $response = $this->request(
            $this->buildUrl($invoice, null, '/payments'), 'POST', $this->mapper->mapToStorage($payment)
        );

        return $this->mapper->mapFromStorage($response);
    }
432
public function tokenizeCard(CreditCard $card)
    {
        $tokenizeCardRequest = new TokenizeCardRequest($this->merchant, $this->environment);

        return $tokenizeCardRequest->execute($card);
    }
308230
public function addPaymentTransaction(PaymentTransaction $paymentTransaction)
    {
        if (!$this->hasPaymentTransaction($paymentTransaction))
        {
            $this->paymentTransactions[] = $paymentTransaction;
        }

        if ($paymentTransaction->getPayment() !== $this)
        {
            $paymentTransaction->setPayment($this);
        }

        return $this;
    }
599747
public function addPayment(\OxidEsales\PayPalModule\Model\OrderPayment $payment)
    {
        //order payment info
        if ($this->getOrderId()) {
            $payment->setOrderId($this->getOrderId());
            $payment->save();
        }

        $this->load($this->getOrderId());

        return $payment;
    }
894388
public function setPaymentMethod($paymentMethod)
    {
        if ($this->paymentMethod !== $paymentMethod) {
            $this->paymentMethod      = (string)$paymentMethod;
            $this->isShopSumChanged   = true;
            $this->isClientSumChanged = true;
        }

        return $this;
    }
92378
protected function addBillingData(\SimpleXMLElement $data)
    {
        /** @var CreditCard $card */
        if ($card = $this->getCard()) {
            $req = $data->addChild('billTo');
            // A card is present, so include billing details
            $req->firstName = $card->getBillingFirstName();
            $req->lastName = $card->getBillingLastName();
            $req->company = $card->getBillingCompany();
            $req->address = trim($card->getBillingAddress1() . " \n" . $card->getBillingAddress2());
            $req->city = $card->getBillingCity();
            $req->state = $card->getBillingState();
            $req->zip = $card->getBillingPostcode();
            $req->country = $card->getBillingCountry();

            $defaultBillTo = $this->getParameter('defaultBillTo');
            if (is_array($defaultBillTo)) {
                // A configuration parameter to populate billTo has been specified
                foreach ($defaultBillTo as $field => $value) {
                    if (empty($req->{$field}) && !empty($value)) {
                        // This particular field is empty and default value in populateBillTo has been specified
                        // so use it
                        $req->{$field} = $value;
                    }
                }
            }

            $req = $data->addChild('payment');
            if ($this->getOpaqueDataDescriptor() && $this->getOpaqueDataValue()) {
                //Use opaqueData if available instead of card data
                $req->opaqueData->dataDescriptor = $this->getOpaqueDataDescriptor();
                $req->opaqueData->dataValue = $this->getOpaqueDataValue();
            } else {
                $req->creditCard->cardNumber = $card->getNumber();
                $req->creditCard->expirationDate = $card->getExpiryDate('Y-m');
                if ($card->getCvv()) {
                    $req->creditCard->cardCode = $card->getCvv();
                } else {
                    $this->setValidationMode(self::VALIDATION_MODE_NONE);
                }
            }
        }
    }
200772
private function isValidPaymentType(string $paymentType): void
    {
        $allowedPaymentType = $this->getAllowedPaymentType();
        if (!\in_array($paymentType, $allowedPaymentType, true)) {
            throw new InvalidTypeException(sprintf(
                'paymentType must be either "%s".',
                implode(', ', $allowedPaymentType)
            ));
        }
    }
34776
public function create($payment, $paymentId = null)
    {
        if (isset($paymentId)) {
            return $this->client()->put($payment, 'payments/{paymentId}', ['paymentId' => $paymentId]);
        }

        return $this->client()->post($payment, 'payments');
    }
748553
private function _setPayments($paymentEntries)
    {
        $payments = Array();
        foreach ($paymentEntries as $paymentEntry) {
            switch ($paymentEntry['paymentType']) {
                case self::$PAYMENTTYPE_PAYPAL:
                    $payments[] = new WirecardCEE_QPay_Response_Toolkit_Order_Payment_Paypal($paymentEntry);
                    break;
                case self::$PAYMENTTYPE_SOFORTUEBERWEISUNG:
                    $payments[] = new WirecardCEE_QPay_Response_Toolkit_Order_Payment_Sofortueberweisung($paymentEntry);
                    break;
                case self::$PAYMENTTYPE_IDEAL:
                    $payments[] = new WirecardCEE_QPay_Response_Toolkit_Order_Payment_Ideal($paymentEntry);
                    break;
                default:
                    $payments[] = new WirecardCEE_QPay_Response_Toolkit_Order_Payment($paymentEntry);
                    break;
            }
        }
        $this->_payments = new WirecardCEE_QPay_Response_Toolkit_Order_PaymentIterator($payments);
    }
908248
public function createAction(Request $request)
    {
        $entity = new Contract();
        $form = $this->createCreateForm($entity);
        $planForm = $this->createForm(new PlanType(), new Plan(), array(
            'action' => $this->generateUrl('ecommerce_plan_new'),
            'method' => 'POST',
        ));
        
        $form->handleRequest($request);

        if ($form->isValid()) {
            
            //check payment method
            $data = $form->getNormData();
            print_r($data);die();
            
            $em = $this->getDoctrine()->getManager();
            
            
            
            $agreement = $entity->getAgreement();
            $agreement->setContract($entity);
            $agreement->setStatus('Created');
            
            
            try {
                $em->persist($entity);
                $em->persist($entity->getAgreement());
                $em->flush();
              
            } catch (\Exception $exc) {
                $this->get('session')->getFlashBag()->add('danger', 'contract.duplicated');
            }
            
           
            
            //paypal workflow
            $checkoutManager = $this->get('checkout_manager');
            //create agreement paypal
            $creditCard = $form->getNormData()->getAgreement()->getCreditCard();
            $cc = array(
                "number" => $creditCard['cardNo'],
                "type" => $creditCard['cardType'],
                "expire_month" => $creditCard['expirationDate']->format('m'),
                "expire_year" =>  $creditCard['expirationDate']->format('Y'),
                "cvv2" =>  $creditCard['CVV'],
                "first_name" => $creditCard['firstname'],
                "last_name" => $creditCard['lastname']
            );  
            $payPalAgreement = $checkoutManager->createPaypalAgreement($entity->getAgreement(), $cc);

            if($entity->getAgreement()->getPaymentMethod() == 'paypal'){
                $this->get('session')->getFlashBag()->add('success', 'contract.created.approval');
                $transactions = $entity->getAgreement()->getTransactions();
                return $this->redirect($this->generateUrl('ecommerce_transaction_show', array('id' => $transactions->last()->getId())));

            }else {
                $this->get('session')->getFlashBag()->add('success', 'contract.created');
            }

            return $this->redirect($this->generateUrl('ecommerce_contract_show', array('id' => $entity->getId())));

        }

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
            'planForm' => $planForm->createView(),
        );
    }
672492
public function createNewCreditCard(CreditCard $creditCard, $id = null)
    {
        if (! $id) {
            $id = $this->data->id;
        }

        $creditCard->setContext(Moip::PAYMENT);

        $this->data = new stdClass;
        $this->data->method = 'CREDIT_CARD';
        $this->data->creditCard = $creditCard->getData();

        $response = $this->client->post('{id}/fundinginstruments', [$id], $this->data);

        $this->populate($response);

        return $this;
    }
255719
public function setPayment(Payment $payment)
    {
        $this->payment = $payment;

        if (!$payment->hasPaymentTransaction($this))
        {
            $payment->addPaymentTransaction($this);
        }

        return $this;
    }
1038377
public function withPaymentMethod($paymentMethod)
    {
        $this->paymentMethod = $paymentMethod;
        if ($paymentMethod instanceof EBTCardData && $paymentMethod->serialNumber !== null) {
            $this->transactionModifier = TransactionModifier::VOUCHER;
        }
        return $this;
    }
807589
private function insertData($amount, CreditCard $creditcard, $type, $options = array())
    {
        $month = $this->cc_format($creditcard->month, 'two_digits');
        $year = $this->cc_format($creditcard->year, 'two_digits');

        $this->xml .= <<<XML
 <OrderFormDoc>
 <Mode DataType="String">{$this->payment_mode}</Mode>
 <Consumer>
 <PaymentMech>
 <Type DataType="String">{$this->payment_mech_type}</Type>
 <CreditCard>
 <Number DataType="String">{$creditcard->number}</Number>
 <Expires DataType="ExpirationDate">{$month}/{$year}</Expires>
 <Cvv2Val DataType="String">{$creditcard->verification_value}</Cvv2Val>
 <Cvv2Indicator DataType="String">1</Cvv2Indicator>
 </CreditCard>
 </PaymentMech>
 </Consumer>
XML;
        $this->addTransactionElement($amount, $type, $options);
        $this->addBillingAddress($options);
        $this->addShippingAddress($options);
    }
735961
public function processPayment(StripeMethod $paymentMethod, $amount)
    {
        /**
         * check and set payment data.
         */
        $chargeParams = $this->prepareData(
            $paymentMethod,
            $amount
        );

        /**
         * make payment.
         */
        $transaction = $this
            ->transactionFactory
            ->create($chargeParams);

        /**
         * 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'.
         */
        if ($transaction['paid'] != 1) {

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

            throw new PaymentException();
        }

        $paymentMethod
            ->setTransactionId($transaction['id'])
            ->setTransactionStatus('paid')
            ->setTransactionResponse($transaction);

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

        return $this;
    }
1318440
public function void($paymentId, $amount)
    {

        $this->debugData[] = __METHOD__;

        $method = 'PUT';
        $uri = $this->config['apiUri'] . \sprintf('/sales/%s/void', $paymentId);
        $options = [
            'headers' => $this->headers
        ];

        if ($amount) {
            $uri .= sprintf('?amount=%s', (float)$amount);
        }

        $this->debugData[][__LINE__]['method'] = $method;
        $this->debugData[][__LINE__]['uri'] = $uri;
        $this->debugData[][__LINE__]['options'] = $uri;

        try {

            $response = $this->http()->request($method, $uri, $options);

            $this->debugData[][__LINE__]['response'] = $response;

            $result = \json_decode($response->getBody()->getContents(), true);

            $this->debugData[][__LINE__]['result'] = $result;

        } catch (RequestException $e) {

            $result = array(
                'code'=>$e->getCode(),
                'message'=>$e->getMessage()
                );

            $this->debugData[][__LINE__]['exception'] = $e->getMessage();

        }

        return $result;
    }