/**
  * @param InfoInterface $payment
  * @param float $amount
  * @return $this
  * @throws LocalizedException
  */
 public function capture(InfoInterface $payment, $amount)
 {
     parent::capture($payment, $amount);
     $customerId = $payment->getOrder()->getCustomerId();
     $customer = $this->customerRepository->getById($customerId);
     $openpayCustomerId = $customer->getCustomAttribute('openpay_customer_id')->getValue();
     $cardId = $payment->getAdditionalInformation('customer_card_id');
     $deviceSessionId = $payment->getAdditionalInformation('device_session_id');
     $order = $payment->getOrder();
     $currency = $order->getOrderCurrencyCode();
     $useOrderId = $this->getConfigData('useOrderId');
     $paymentLeyend = $this->getConfigData('paymentLeyend');
     $orderId = $order->getIncrementId();
     $params = ['source_id' => $cardId, 'method' => self::OPENPAY_PAYMENT_METHOD_CARD, 'amount' => $amount, 'currency' => $currency, 'description' => __($paymentLeyend)->getText(), 'order_id' => $useOrderId ? $orderId : null, 'device_session_id' => $deviceSessionId];
     try {
         $transaction = $this->chargeAdapter->chargeCustomerCard($openpayCustomerId, $params);
         $payment->setTransactionId($transaction->getId())->setIsTransactionClosed(0);
         $this->openpayCustomerRepository->clearCustomerCache($openpayCustomerId);
     } catch (OpenpayException $e) {
         $this->debugData(['request' => $params, 'exception' => $e->getMessage()]);
         $this->_logger->error(__('Payment capturing error.'));
         throw new LocalizedException(new Phrase('[' . $e->getErrorCode() . ']' . $e->getMessage()));
     }
     return $this;
 }
 /**
  * @param $customerDataObject
  * @return array|\Openpay\Client\Type\OpenpayCustomerType
  */
 protected function getCustomerFromOpenpay($customerDataObject)
 {
     try {
         $customer = $this->openpayCustomerRepository->get($customerDataObject);
     } catch (\Exception $e) {
         $customer = ['error' => __('Could not retrieve available customer from OpenPay for the given user')];
     }
     return $customer;
 }
 /**
  * @param $customer
  * @return \Openpay\Client\Type\OpenpayCustomerType
  */
 protected function saveCustomerInOpenpay($customer)
 {
     $openpayCustomer = $this->openpayCustomerRepository->save($customer);
     return $openpayCustomer;
 }