Exemplo n.º 1
0
 /**
  * @param string $token
  * @throws LocalizedException
  * @return bool|string
  */
 public function generatePaymentMethodToken($token)
 {
     $result = $this->braintreePaymentMethod->createNonce($token);
     if (!$result->success) {
         throw new LocalizedException($this->errorHelper->parseBraintreeError($result));
     }
     return $result->paymentMethodNonce->nonce;
 }
Exemplo n.º 2
0
 /**
  * Voids transaction
  *
  * @param InfoInterface $payment
  * @throws LocalizedException
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function void(InfoInterface $payment)
 {
     $transactionIds = $this->getTransactionsToVoid($payment);
     $message = false;
     foreach ($transactionIds as $transactionId) {
         $transaction = $this->braintreeTransaction->find($transactionId);
         if ($transaction->status !== \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT && $transaction->status !== \Braintree_Transaction::AUTHORIZED) {
             throw new LocalizedException(__('Some transactions are already settled or voided and cannot be voided.'));
         }
         if ($transaction->status === \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             $message = __('Voided capture.');
         }
     }
     $errors = '';
     foreach ($transactionIds as $transactionId) {
         $this->_debug(['void-' . $transactionId]);
         $result = $this->braintreeTransaction->void($transactionId);
         $this->_debug($this->_convertObjToArray($result));
         if (!$result->success) {
             $errors .= ' ' . $this->errorHelper->parseBraintreeError($result)->getText();
         } elseif ($message) {
             $payment->setMessage($message);
         }
     }
     if ($errors) {
         throw new LocalizedException(__('There was an error voiding the transaction: %1.', $errors));
     } else {
         $match = true;
         foreach ($transactionIds as $transactionId) {
             $collection = $this->salesTransactionCollectionFactory->create()->addFieldToFilter('parent_txn_id', ['eq' => $transactionId])->addFieldToFilter('txn_type', PaymentTransaction::TYPE_VOID);
             if ($collection->getSize() < 1) {
                 $match = false;
             }
         }
         if ($match) {
             $payment->setIsTransactionClosed(true);
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * @param array $result
  * @param boolean $expected
  * @dataProvider parseBraintreeErrorDataProvider
  */
 public function testisparseBraintreeError($result, $expected)
 {
     $resultObj = new \Braintree_Result_Error($result);
     $result = $this->model->parseBraintreeError($resultObj);
     $this->assertEquals(new \Magento\Framework\Phrase($expected), $result);
 }