/**
  * Payment capturing
  *
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param float $amount
  * @return $this
  * @throws \Magento\Framework\Validator\Exception
  */
 public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     //throw new \Magento\Framework\Validator\Exception(__('Inside Stripe, throwing donuts :]'));
     /** @var \Magento\Sales\Model\Order $order */
     $order = $payment->getOrder();
     /** @var \Magento\Sales\Model\Order\Address $billing */
     $billing = $order->getBillingAddress();
     try {
         $requestData = ['amount' => $amount * 100, 'currency' => strtolower($order->getBaseCurrencyCode()), 'description' => sprintf('#%s, %s', $order->getIncrementId(), $order->getCustomerEmail()), 'card' => ['number' => $payment->getCcNumber(), 'exp_month' => sprintf('%02d', $payment->getCcExpMonth()), 'exp_year' => $payment->getCcExpYear(), 'cvc' => $payment->getCcCid(), 'name' => $billing->getName(), 'address_line1' => $billing->getStreetLine(1), 'address_line2' => $billing->getStreetLine(2), 'address_city' => $billing->getCity(), 'address_zip' => $billing->getPostcode(), 'address_state' => $billing->getRegion(), 'address_country' => $billing->getCountryId()]];
         $charge = \Stripe\Charge::create($requestData);
         $payment->setTransactionId($charge->id)->setIsTransactionClosed(0);
     } catch (\Exception $e) {
         $this->debugData(['request' => $requestData, 'exception' => $e->getMessage()]);
         $this->_logger->error(__('Payment capturing error.'));
         throw new \Magento\Framework\Validator\Exception(__('Payment capturing error.'));
     }
     return $this;
 }
 /**
  * Processes initial transactions
  *      - Authorize
  *      - Authorize3D
  *      - Sale
  *      - Sale3D
  *
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param $amount
  * @return $this
  * @throws \Exception
  * @throws \Genesis\Exceptions\ErrorAPI
  */
 protected function processInitialTransaction(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $transactionType = $this->getTransactionType();
     $order = $payment->getOrder();
     $helper = $this->getModuleHelper();
     $config = $helper->getTransactionConfig($transactionType);
     $this->getConfigHelper()->initGatewayClient();
     $billing = $order->getBillingAddress();
     if (empty($billing)) {
         throw new \Exception(__('Billing address is empty.'));
     }
     $shipping = $order->getShippingAddress();
     $genesis = new \Genesis\Genesis($config->request);
     $genesis->request()->setTransactionId($helper->genTransactionId($order->getIncrementId()))->setRemoteIp($order->getRemoteIp())->setUsage($helper->buildOrderDescriptionText($order))->setLanguage($helper->getLocale())->setCurrency($order->getBaseCurrencyCode())->setAmount($amount);
     if (!empty($payment->getCcOwner())) {
         $genesis->request()->setCardHolder($payment->getCcOwner());
     } else {
         $genesis->request()->setCardHolder($billing->getFirstname() . ' ' . $billing->getLastname());
     }
     $genesis->request()->setCardNumber($payment->getCcNumber())->setExpirationYear($payment->getCcExpYear())->setExpirationMonth($payment->getCcExpMonth())->setCvv($payment->getCcCid())->setCustomerEmail($order->getCustomerEmail())->setCustomerPhone($billing->getTelephone())->setBillingFirstName($billing->getFirstname())->setBillingLastName($billing->getLastname())->setBillingAddress1($billing->getStreetLine(1))->setBillingAddress2($billing->getStreetLine(2))->setBillingZipCode($billing->getPostcode())->setBillingCity($billing->getCity())->setBillingState($billing->getRegionCode())->setBillingCountry($billing->getCountryId());
     if (!empty($shipping)) {
         $genesis->request()->setShippingFirstName($shipping->getFirstname())->setShippingLastName($shipping->getLastname())->setShippingAddress1($shipping->getStreetLine(1))->setShippingAddress2($shipping->getStreetLine(2))->setShippingZipCode($shipping->getPostcode())->setShippingCity($shipping->getCity())->setShippingState($shipping->getRegionCode())->setShippinCountry($shipping->getCountryId());
     }
     if ($config->is3D) {
         $genesis->request()->setNotificationUrl($helper->getNotificationUrl($this->getCode()))->setReturnSuccessUrl($helper->getReturnUrl($this->getCode(), "success"))->setReturnCancelUrl($helper->getReturnUrl($this->getCode(), "cancel"))->setReturnFailureUrl($helper->getReturnUrl($this->getCode(), "failure"));
     }
     $genesis->execute();
     $this->setGenesisResponse($genesis->response()->getResponseObject());
     $genesis_response = $this->getModuleHelper()->getArrayFromGatewayResponse($this->getGenesisResponse());
     $payment->setTransactionId($this->getGenesisResponse()->unique_id)->setIsTransactionClosed($config->should_close)->setIsTransactionPending($config->is3D)->setTransactionAdditionalInfo(\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS, $genesis_response);
     $status = $this->getGenesisResponse()->status;
     $statusList = array(\Genesis\API\Constants\Transaction\States::DECLINED, \Genesis\API\Constants\Transaction\States::ERROR, \Genesis\API\Constants\Transaction\States::UNSUCCESSFUL);
     if (in_array($status, $statusList)) {
         throw new \Genesis\Exceptions\ErrorAPI($this->getGenesisResponse()->message);
     }
     if ($config->is3D) {
         $this->setRedirectUrl($this->getGenesisResponse()->redirect_url);
         $payment->setPreparedMessage('3D-Secure: Redirecting customer to a verification page.');
     } else {
         $this->unsetRedirectUrl();
     }
 }