Add savedCreditCards

@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since  2013-03-27

@param  \HarvestCloud\CoreBundle\Entity\Payment\SavedCreditCard $savedCreditCard

@return Profile
963385
public function addSavedCreditCard(\HarvestCloud\CoreBundle\Entity\Payment\SavedCreditCard $savedCreditCard)
    {
        $this->savedCreditCards[] = $savedCreditCard;

        $savedCreditCard->setProfile($this);

        return $this;
    }
1014089
public function setCreditCard($params = null)
    {

        if ($params instanceof PagSeguroCreditCardCheckout) {
            $this->creditCard = $params;
        } elseif (isset($params) && is_array($params)) {
            $this->creditCard = new PagSeguroCreditCardCheckout();
            if (isset($params['token'])) {
                $this->creditCard->setToken($params['token']);
            }
            if (isset($params['installment']) && $params['installment'] instanceof PagSeguroInstallment) {
                $this->creditCard->setInstallment($params['installment']);
            }
            if (isset($params['holder']) && $params['holder'] instanceof PagSeguroCreditCardHolder) {
                $this->creditCard->setHolder($params['holder']);
            }
            if (isset($params['billing']) && $params['billing'] instanceof PagSeguroBilling) {
                $this->creditCard->setBilling($params['billing']);
            }
        }
    }
929865
private function addCreditcard(CreditCard $creditcard, $complete = true)
    {
        $card = array(
            'number' => $creditcard->number,
            'name' => $creditcard->name(),
            'expiry_month' => $this->cc_format($creditcard->month, 'two_digits'),
            'expiry_year' => $this->cc_format($creditcard->year, 'two_digits'),
            'cvd' => $creditcard->verification_value,
            'complete' => $complete,
        );

        $this->post['card'] = $card;
    }
967100
public function updateCard($token)
    {
        $customer = $this->asStripeCustomer();

        $token = StripeToken::retrieve($token, ['api_key' => $this->getStripeKey()]);

        // If the given token already has the card as their default source, we can just
        // bail out of the method now. We don't need to keep adding the same card to
        // a model's account every time we go through this particular method call.
        if ($token[$token->type]->id === $customer->default_source) {
            return;
        }

        $card = $customer->sources->create(['source' => $token]);

        $customer->default_source = $card->id;

        $customer->save();

        // Next we will get the default source for this model so we can update the last
        // four digits and the card brand on the record in the database. This allows
        // us to display the information on the front-end when updating the cards.
        $source = $customer->default_source
                    ? $customer->sources->retrieve($customer->default_source)
                    : null;

        $this->fillCardDetails($source);

        $this->save();
    }
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);
    }
1208216
public function chargeWithCard(RequestModels\CardChargeCreate $requestModel)
	{

		$chargeMapper = new ChargesMapper($requestModel);

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

		);
		$processCharge = \com\checkout\helpers\ApiHttpClient::postRequest($this->_apiUrl->getCardChargesApiUri(),
			$this->_apiSetting->getSecretKey(),$requestPayload);
      
		$responseModel = new ResponseModels\Charge($processCharge);

		return $responseModel;
	}
514836
def OnAddCards(self, addedcards):
        """"""
        parentnode = self.root
        for cardtoadd in addedcards:
            childCard = self.AppendItem(parentnode, toHexString(cardtoadd.atr))
            self.SetItemText(childCard, toHexString(cardtoadd.atr))
            self.SetPyData(childCard, cardtoadd)
            self.SetItemImage(
                childCard, self.cardimageindex, wx.TreeItemIcon_Normal)
            self.SetItemImage(
                childCard, self.cardimageindex, wx.TreeItemIcon_Expanded)
            self.Expand(childCard)
        self.Expand(self.root)
        self.EnsureVisible(self.root)
        self.Repaint()
193234
public function store(CreditCard $creditcard, $options = array())
    {
        Options::required('email', $options);

        $this->post = array();
        $options = new Options($options);
        $this->addCreditcard($creditcard);
        $this->addAddress($options);
        $this->post['email'] = $options['email'];

        return $this->commit(self::STORE);
    }
257386
public function store(CreditCard $creditcard, $options = array())
    {
        $this->required_options('order_id', $options);
        $this->buildNewCardRequest($creditcard, $options);
        return $this->commit('recurring');
    }
1360751
def save(self, prepend_vault_id=''):
        
        assert self.is_valid()
        
        cc_details_map = {    # cc details
            'number': self.cleaned_data['cc_number'],
            'cardholder_name': self.cleaned_data['name'],
            'expiration_date': '%s/%s' %\
                (self.cleaned_data['expiration_month'], self.cleaned_data['expiration_year']),
            'cvv': self.cleaned_data['cvv'],
            'billing_address': {
                'postal_code': self.cleaned_data['zip_code'],
            }
        }
        
        if self.__user_vault:
            try:
                # get customer info, its credit card and then update that credit card
                response = Customer.find(self.__user_vault.vault_id)
                cc_info = response.credit_cards[0]
                return CreditCard.update(cc_info.token, params=cc_details_map)
            except Exception, e:
                logging.error('Was not able to get customer from vault. %s' % e)
                self.__user_vault.delete()  # delete the stale instance from our db
        
        # in case the above updating fails or user was never in the vault
        new_customer_vault_id = '%s%s' % (prepend_vault_id, md5_hash()[:24])
        respone = Customer.create({    # creating a customer, but we really just want to store their CC details
            'id': new_customer_vault_id,   # vault id, uniquely identifies customer. We're not caring about tokens (used for storing multiple CC's per user)
            'credit_card': cc_details_map
        })
        
        if respone.is_success:  # save a new UserVault instance
            UserVault.objects.create(user=self.__user, vault_id=new_customer_vault_id)
        
        return respone
166182
public function addCredits($customerId, $amount)
    {
        $requestData = new AddCredits\RequestData($customerId, $amount);
        $request = new AddCredits\Request($requestData);

        return $this->sendRequest($request, AddCredits\ApiResponse::class);
    }
995522
public function customWxcard($card_id = '', $card_ext = [], $openid, $kf_account = '')
    {
        $queryStr                       = [];
        $queryStr['touser']             = $openid;
        $queryStr['msgtype']            = 'wxcard';
        $queryStr['wxcard']['card_id']  = $card_id;
        $queryStr['wxcard']['card_ext'] = $card_ext;

        $queryStr['customservice']['kf_account'] = $kf_account;

        $this->module = 'message';

        $res = $this->_post('custom/send', $queryStr);

        return $res;
    }
144589
public function create(array $card, $customerId = null) {
        $expiryMonth    = str_pad($card['expiryMonth'], 2, '0', STR_PAD_LEFT);
        $expiryYear     = $card['expiryYear'];
        $expiresAt      = $this->getExpirationDate($expiryMonth, $expiryYear);
        $ccType         = $this->ccTypeAdapter->getFromGateway($card['paymentMethod']);

        /** @var PaymentTokenInterface $paymentToken */
        $paymentToken = $this->creditCardTokenFactory->create();
        $paymentToken->setExpiresAt($expiresAt);

        if( array_key_exists('id', $card) ) {
            $paymentToken->setGatewayToken($card['id']);
        }

        $tokenDetails = [
            'type'              => $ccType,
            'maskedCC'          => $card['last4'],
            'expirationDate'    => $expiryMonth . '/' . $expiryYear,
        ];

        $paymentToken->setTokenDetails($this->convertDetailsToJSON($tokenDetails));
        $paymentToken->setIsActive(true);
        $paymentToken->setPaymentMethodCode(ConfigProvider::CODE);

        if($customerId) {
            $paymentToken->setCustomerId($customerId);
        }

        $paymentToken->setPublicHash($this->generatePublicHash($paymentToken));

        return $paymentToken;
    }
422809
protected function fillCardDetails($card)
    {
        if ($card) {
            $this->card_brand = $card->brand;
            $this->card_last_four = $card->last4;
        }

        return $this;
    }
606258
public function setCreditCardHash($hash, Holder $holder, $store = true)
    {
        $this->data->fundingInstrument->method = self::METHOD_CREDIT_CARD;
        $this->data->fundingInstrument->creditCard = new stdClass();
        $this->data->fundingInstrument->creditCard->hash = $hash;
        $this->data->fundingInstrument->creditCard->store = $store;
        $this->setCreditCardHolder($holder);

        return $this;
    }
708623
public function store(CreditCard $creditcard, $options = array())
    {
        $this->post = array();

        $this->addCreditcard($creditcard);

        return $this->commit('credit_cards');
    }
283563
public function toProfiles($profiles, $card)
	{
		$card = array_merge(['profile_uids' => $profiles], $card);

		$card['canvas'] = isset($card['canvas']) ? $card['canvas'] : self::DEFAULT_CANVAS;

		return $this->request->send('POST', "/profiles/cards", $card);
	}