_currency = 'eur'; $this->_configs = new App_Service_ConfigManager(); $this->_ipManager = new App_Service_IpManager(); $this->_apiStripeTestAccount = false; if($this->_ipManager->allowedDevMode()){ $this->_apiStripeTestAccount = ($this->_configs->get('interrutore_stripe_test') == 'on') ? 1:0; } if ($this->_apiStripeTestAccount){ $this->_secretKey = self::TEST_SECRECT_KEY; $this->_publishableKey = self::TEST_PUBLISHABLE_KEY; } else{ $this->_secretKey = self::LIVE_SECRET_KEY; $this->_publishableKey = self::LIVE_PUBLISHABLE_KEY; } $this->_Stripe = new Stripe(); $this->_Stripe->setApiKey($this->_secretKey); } /** * @param $number * @param $exp_month * @param $exp_year * @param $cvc * @param null $extraData * * @return \Stripe\ApiOperations\ApiResource */ public function createToken($number, $exp_month, $exp_year, $cvc,$extraData = null) { $card = array( 'number' => $number, 'exp_month' => $exp_month, 'exp_year' => $exp_year, 'cvc' => $cvc ); //Nel caso in cui passo dei dati extra li aggiungo alla chiamata per la creazionde del token if($extraData && (is_array($extraData) || is_object($extraData))){ foreach($extraData as $key => $val){ $card[$key] = $val; } } $token = Token::create(array('card' => $card)); return $token; } /** * @param $amount * @param $token * @param string $description * * @return \Stripe\ApiOperations\ApiResource * @throws Exception */ public function createCharge($amount, $token,$description = self::DEFAULT_DESCRIPTION_TEXT) { if(!$token) throw new Exception("Il Token non รจ stato generato correttamente"); $charge = Charge::create(array( "amount" => $amount, "currency" => $this->_currency, "card" => $token, "description"=>$description )); return $charge; } }