getParameter('apiKey'); } /** * Set the gateway API Key. * * @return AbstractRequest provides a fluent interface. */ public function setApiKey($value) { return $this->setParameter('apiKey', $value); } /** * @deprecated */ public function getCardToken() { return $this->getCardReference(); } /** * @deprecated */ public function setCardToken($value) { return $this->setCardReference($value); } /** * Get the customer reference. * * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * Set the customer reference. * * Used when calling CreateCard on an existing customer. If this * parameter is not set then a new customer is created. * * @return AbstractRequest provides a fluent interface. */ public function setCustomerReference($value) { return $this->setParameter('customerReference', $value); } public function getMetadata() { return $this->getParameter('metadata'); } public function setMetadata($value) { return $this->setParameter('metadata', $value); } /** * Connect only * * @return mixed */ public function getConnectedStripeAccountHeader() { return $this->getParameter('connectedStripeAccount'); } /** * @param string $value * * @return \Omnipay\Common\Message\AbstractRequest */ public function setConnectedStripeAccountHeader($value) { return $this->setParameter('connectedStripeAccount', $value); } /** * Connect only * * @return mixed */ public function getIdempotencyKeyHeader() { return $this->getParameter('idempotencyKey'); } /** * @param string $value * * @return \Omnipay\Common\Message\AbstractRequest */ public function setIdempotencyKeyHeader($value) { return $this->setParameter('idempotencyKey', $value); } abstract public function getEndpoint(); /** * Get HTTP Method. * * This is nearly always POST but can be over-ridden in sub classes. * * @return string */ public function getHttpMethod() { return 'POST'; } /** * @return array */ public function getHeaders() { $headers = array(); if ($this->getConnectedStripeAccountHeader()) { $headers['Stripe-Account'] = $this->getConnectedStripeAccountHeader(); } if ($this->getIdempotencyKeyHeader()) { $headers['Idempotency-Key'] = $this->getIdempotencyKeyHeader(); } return $headers; } /** * @param $data * @param array $headers * * @return \Guzzle\Http\Message\RequestInterface */ protected function createClientRequest($data, array $headers = null) { // Stripe only accepts TLS >= v1.2, so make sure Curl is told $config = $this->httpClient->getConfig(); $curlOptions = $config->get('curl.options'); $curlOptions[CURLOPT_SSLVERSION] = 6; $config->set('curl.options', $curlOptions); $this->httpClient->setConfig($config); // don't throw exceptions for 4xx errors $this->httpClient->getEventDispatcher()->addListener( 'request.error', function ($event) { if ($event['response']->isClientError()) { $event->stopPropagation(); } } ); $httpRequest = $this->httpClient->createRequest( $this->getHttpMethod(), $this->getEndpoint(), $headers, $data ); return $httpRequest; } /** * {@inheritdoc} */ public function sendData($data) { $headers = array_merge( $this->getHeaders(), array('Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':')) ); $httpRequest = $this->createClientRequest($data, $headers); $httpResponse = $httpRequest->send(); $this->response = new Response($this, $httpResponse->json()); if ($httpResponse->hasHeader('Request-Id')) { $this->response->setRequestId((string) $httpResponse->getHeader('Request-Id')); } return $this->response; } /** * @return mixed */ public function getSource() { return $this->getParameter('source'); } /** * @param $value * * @return AbstractRequest provides a fluent interface. */ public function setSource($value) { return $this->setParameter('source', $value); } /** * Get the card data. * * Because the stripe gateway uses a common format for passing * card data to the API, this function can be called to get the * data from the associated card object in the format that the * API requires. * * @return array */ protected function getCardData() { $card = $this->getCard(); $card->validate(); $data = array(); $data['object'] = 'card'; $data['number'] = $card->getNumber(); $data['exp_month'] = $card->getExpiryMonth(); $data['exp_year'] = $card->getExpiryYear(); if ($card->getCvv()) { $data['cvc'] = $card->getCvv(); } $data['name'] = $card->getName(); $data['address_line1'] = $card->getAddress1(); $data['address_line2'] = $card->getAddress2(); $data['address_city'] = $card->getCity(); $data['address_zip'] = $card->getPostcode(); $data['address_state'] = $card->getState(); $data['address_country'] = $card->getCountry(); $data['email'] = $card->getEmail(); return $data; } }