示例#1
0
 /**
  * Capture payment
  *
  * @param InfoInterface|Payment $payment
  * @param float $amount
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @throws \Magento\Framework\Exception\State\InvalidTransitionException
  */
 public function capture(InfoInterface $payment, $amount)
 {
     /** @var Payment $payment */
     $token = $payment->getAdditionalInformation(self::PNREF);
     parent::capture($payment, $amount);
     if ($token && !$payment->getAuthorizationTransaction()) {
         $this->createPaymentToken($payment, $token);
     }
     return $this;
 }
 /**
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param float $amount
  * @return $this
  * @throws LocalizedException
  */
 public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $senderCustomer = $payment->getAdditionalInformation('destination_customer');
     $customerId = $payment->getOrder()->getCustomerId();
     $customer = $this->customerRepository->getById($customerId);
     $destinationCustomer = $customer->getCustomAttribute('openpay_customer_id')->getValue();
     $paymentLeyend = __('Refund for: ') . __($this->getConfigData('paymentLeyend'))->getText();
     $order = $payment->getOrder();
     $useOrderId = $this->getConfigData('useOrderId');
     $orderId = $order->getIncrementId();
     $params = ['customer_id' => $destinationCustomer, 'amount' => $amount, 'description' => $paymentLeyend, 'order_id' => $useOrderId ? $orderId . '-refund' : null];
     try {
         $transaction = $this->transferAdapter->transfer($senderCustomer, $params);
         $payment->setTransactionId($transaction->getId())->setIsTransactionClosed(0);
         $this->openpayCustomerRepository->clearCustomerCache($senderCustomer);
         $this->openpayCustomerRepository->clearCustomerCache($destinationCustomer);
     } catch (OpenpayException $e) {
         $this->debugData(['request' => $params, 'exception' => $e->getMessage()]);
         $this->_logger->error(__('Payment capturing error.'));
         throw new LocalizedException(__('[' . $e->getErrorCode() . ']' . $e->getMessage()));
     }
     return parent::refund($payment, $amount);
     // TODO: Change the autogenerated stub
 }
示例#3
0
 /**
  * Check whether can do payment review
  *
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @return bool
  */
 public function canReviewPayment(\Magento\Payment\Model\InfoInterface $payment)
 {
     $pendingReason = $payment->getAdditionalInformation(\Magento\Paypal\Model\Info::PENDING_REASON_GLOBAL);
     return $this->_isPaymentReviewRequired($payment) && $pendingReason != \Magento\Paypal\Model\Info::PAYMENTSTATUS_REVIEW;
 }
示例#4
0
 /**
  * Capture payment
  *
  * @param \Magento\Framework\DataObject|\Magento\Payment\Model\InfoInterface|Payment $payment
  * @param float $amount
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $authorizationTransaction = $payment->getAuthorizationTransaction();
     $authorizationPeriod = abs(intval($this->getConfigData('authorization_honor_period')));
     $maxAuthorizationNumber = abs(intval($this->getConfigData('child_authorization_number')));
     $order = $payment->getOrder();
     $isAuthorizationCreated = false;
     if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey)) {
         $voided = false;
         if (!$authorizationTransaction->getIsClosed() && $this->_isTransactionExpired($authorizationTransaction, $authorizationPeriod)) {
             //Save payment state and configure payment object for voiding
             $isCaptureFinal = $payment->getShouldCloseParentTransaction();
             $payment->setShouldCloseParentTransaction(false);
             $payment->setParentTransactionId($authorizationTransaction->getTxnId());
             $payment->unsTransactionId();
             $payment->setVoidOnlyAuthorization(true);
             $payment->void(new \Magento\Framework\DataObject());
             //Revert payment state after voiding
             $payment->unsAuthorizationTransaction();
             $payment->unsTransactionId();
             $payment->setShouldCloseParentTransaction($isCaptureFinal);
             $voided = true;
         }
         if ($authorizationTransaction->getIsClosed() || $voided) {
             if ($payment->getAdditionalInformation($this->_authorizationCountKey) > $maxAuthorizationNumber - 1) {
                 $this->_exception->create(['phrase' => __('The maximum number of child authorizations is reached.')]);
             }
             $api = $this->_callDoAuthorize($amount, $payment, $authorizationTransaction->getParentTxnId());
             //Adding authorization transaction
             $this->_pro->importPaymentInfo($api, $payment);
             $payment->setTransactionId($api->getTransactionId());
             $payment->setParentTransactionId($authorizationTransaction->getParentTxnId());
             $payment->setIsTransactionClosed(false);
             $formatedPrice = $order->getBaseCurrency()->formatTxt($amount);
             if ($payment->getIsTransactionPending()) {
                 $message = __('We\'ll authorize the amount of %1 as soon as the payment gateway approves it.', $formatedPrice);
             } else {
                 $message = __('The authorized amount is %1.', $formatedPrice);
             }
             $transaction = $this->transactionBuilder->setPayment($payment)->setOrder($order)->setTransactionId($payment->getTransactionId())->setFailSafe(true)->build(Transaction::TYPE_AUTH);
             $payment->addTransactionCommentsToOrder($transaction, $message);
             $payment->setParentTransactionId($api->getTransactionId());
             $isAuthorizationCreated = true;
         }
         //close order transaction if needed
         if ($payment->getShouldCloseParentTransaction()) {
             $orderTransaction = $this->getOrderTransaction($payment);
             if ($orderTransaction) {
                 $orderTransaction->setIsClosed(true);
                 $order->addRelatedObject($orderTransaction);
             }
         }
     }
     if (false === $this->_pro->capture($payment, $amount)) {
         $this->_placeOrder($payment, $amount);
     }
     if ($isAuthorizationCreated && isset($transaction)) {
         $transaction->setIsClosed(true);
     }
     return $this;
 }
 public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     if ($amount <= 0) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Invalid amount for refund.'));
     }
     if (!$payment->getParentTransactionId()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Invalid transaction ID.'));
     }
     $orderNumber = $payment->getAdditionalInformation('tco_order_number');
     $args = array('sale_id' => $orderNumber, 'category' => 5, 'comment' => 'Refund issued by merchant.', 'amount' => $amount, 'currency' => 'vendor');
     $client = $this->_httpClientFactory->create();
     $path = 'sales/refund_invoice';
     $url = $this->getApiUrl();
     $client->setUri($url . $path);
     $client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
     $client->setAuth($this->getConfigData('api_user'), $this->getConfigData('api_pass'));
     $client->setHeaders(['Accept: application/json']);
     $client->setParameterPost($args);
     $client->setMethod(\Zend_Http_Client::POST);
     try {
         $response = $client->request();
         $responseBody = json_decode($response->getBody(), true);
         if (isset($responseBody['errors'])) {
             $this->_logger->critical(sprintf('Error Refunding Invoice: "%s"', $responseBody['errors'][0]['message']));
             throw new \Magento\Framework\Exception\LocalizedException(__($responseBody['errors'][0]['message']));
         } elseif (!isset($responseBody['response_code']) || !isset($responseBody['response_message'])) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Error refunding transaction.'));
         } elseif ($responseBody['response_code'] != 'OK') {
             throw new \Magento\Framework\Exception\LocalizedException(__($responseBody['response_message']));
         }
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()));
     }
     return $this;
 }
示例#6
0
 /**
  * Performs authorize transaction
  *
  * @param \Magento\Payment\Model\InfoInterface|Object $payment
  * @param float $amount
  * @return $this
  * @throws InvalidTransitionException
  * @throws LocalizedException
  */
 public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $request = $this->buildBasicRequest();
     $order = $payment->getOrder();
     if (!empty($order)) {
         $request = $this->fillCustomerContacts($order, $request);
     }
     $request->setTrxtype(self::TRXTYPE_AUTH_ONLY);
     $request->setOrigid($payment->getAdditionalInformation('pnref'));
     $request->setAmt(round($amount, 2));
     $response = $this->postRequest($request, $this->getConfig());
     $this->processErrors($response);
     try {
         $this->responseValidator->validate($response);
     } catch (LocalizedException $exception) {
         $payment->setParentTransactionId($response->getPnref());
         $this->void($payment);
         throw new LocalizedException(__('Error processing payment, please try again later.'));
     }
     $this->setTransStatus($payment, $response);
     $payment->unsAdditionalInformation('pnref');
     return $this;
 }
示例#7
0
 /**
  * Capture payment
  *
  * @param InfoInterface|Payment|Object $payment
  * @param float $amount
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @throws \Magento\Framework\Exception\State\InvalidTransitionException
  */
 public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     if ($payment->getAdditionalInformation(self::PNREF)) {
         $request = $this->buildBasicRequest();
         $request->setAmt(round($amount, 2));
         $request->setTrxtype(self::TRXTYPE_SALE);
         $request->setOrigid($payment->getAdditionalInformation(self::PNREF));
         $payment->unsAdditionalInformation(self::PNREF);
     } elseif ($payment->getParentTransactionId()) {
         $request = $this->buildBasicRequest();
         $request->setOrigid($payment->getParentTransactionId());
         $captureAmount = $this->_getCaptureAmount($amount);
         if ($captureAmount) {
             $request->setAmt($captureAmount);
         }
         $trxType = $this->getInfoInstance()->hasAmountPaid() ? self::TRXTYPE_SALE : self::TRXTYPE_DELAYED_CAPTURE;
         $request->setTrxtype($trxType);
     } else {
         $request = $this->_buildPlaceRequest($payment, $amount);
         $request->setTrxtype(self::TRXTYPE_SALE);
     }
     $this->addRequestOrderInfo($request, $payment->getOrder());
     $response = $this->postRequest($request, $this->getConfig());
     $this->processErrors($response);
     $this->setTransStatus($payment, $response);
     return $this;
 }
 /**
  * If gateway actions are locked return true
  *
  * @param  \Magento\Payment\Model\InfoInterface $payment
  * @return bool
  */
 protected function isGatewayActionsLocked($payment)
 {
     return $payment->getAdditionalInformation(self::GATEWAY_ACTIONS_LOCKED_STATE_KEY);
 }
示例#9
0
文件: Info.php 项目: nja78/magento2
 /**
  * Render info item
  *
  * @param array $keys
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param bool $labelValuesOnly
  * @return array
  */
 protected function _getFullInfo(array $keys, \Magento\Payment\Model\InfoInterface $payment, $labelValuesOnly)
 {
     $result = [];
     foreach ($keys as $key) {
         if (!isset($this->_paymentMapFull[$key])) {
             $this->_paymentMapFull[$key] = [];
         }
         if (!isset($this->_paymentMapFull[$key]['label'])) {
             if (!$payment->hasAdditionalInformation($key)) {
                 $this->_paymentMapFull[$key]['label'] = false;
                 $this->_paymentMapFull[$key]['value'] = false;
             } else {
                 $value = $payment->getAdditionalInformation($key);
                 $this->_paymentMapFull[$key]['label'] = (string) $this->_getLabel($key);
                 $this->_paymentMapFull[$key]['value'] = $this->_getValue($value, $key);
             }
         }
         if (!empty($this->_paymentMapFull[$key]['value'])) {
             if ($labelValuesOnly) {
                 $result[$this->_paymentMapFull[$key]['label']] = $this->_paymentMapFull[$key]['value'];
             } else {
                 $result[$key] = $this->_paymentMapFull[$key];
             }
         }
     }
     return $result;
 }
示例#10
0
 public function testInitAdditionalInformationWithUnserialize()
 {
     $data = serialize(['key1' => 'data1', 'key2' => 'data2']);
     $this->info->setData('additional_information', $data);
     $this->assertEquals(unserialize($data), $this->info->getAdditionalInformation());
 }
示例#11
0
文件: main.php 项目: mage2pro/core
/**
 * 2016-08-08
 * @used-by \Df\Payment\Charge::iia()
 * @used-by \Df\Payment\Method::iia()
 * @param II|OP|QP $payment
 * @param string|string[]|null $keys  [optional]
 * @return mixed|array(string => mixed)
 */
function dfp_iia(II $payment, $keys = null)
{
    /** @var mixed|array(string => mixed) $result */
    if (is_null($keys)) {
        $result = $payment->getAdditionalInformation();
    } else {
        if (!is_array($keys)) {
            $keys = df_tail(func_get_args());
        }
        $result = 1 === count($keys) ? $payment->getAdditionalInformation(df_first($keys)) : dfa_select_ordered($payment->getAdditionalInformation(), $keys);
    }
    return $result;
}
示例#12
0
 /**
  * Cancel payment
  * Cancelaltion, is when the order can no longer be modified. While an order payment might be voided a new
  * invoice can always be generated. Cancellation of an order prevents any future change from being made to it.
  *
  * If REFUND is available do a refund, otherwise do a DEPOSITREVERSAL
  * Dont make APPROVEREVERSAL (decision by PM)
  *
  * @param \Magento\Framework\DataObject|InfoInterface|\Magento\Sales\Model\Order\Payment $payment
  *
  * @return $this
  * @throws \Exception
  * @api
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function cancel(\Magento\Payment\Model\InfoInterface $payment)
 {
     if (!$this->_dataHelper->isBackendAvailable()) {
         return $this;
     }
     $orderNumber = $payment->getAdditionalInformation('orderNumber');
     if (!strlen($orderNumber)) {
         /* dont throw an exception here, might be a pending payment */
         $this->_logger->debug(__METHOD__ . ':No order number found.');
         return $this;
     }
     $orderDetails = $this->getOrderDetails($orderNumber);
     $backendClient = $this->_dataHelper->getBackendClient();
     $log = sprintf("%s", $orderNumber);
     /* if refund op is available order already has been closed */
     /* otherwise revert each single payment */
     if (in_array('REFUND', $orderDetails->getOrder()->getOperationsAllowed())) {
         $log .= sprintf(" action:REFUND %s", $orderDetails->getOrder()->getAmount());
         $ret = $backendClient->refund($orderNumber, $orderDetails->getOrder()->getAmount(), $orderDetails->getOrder()->getCurrency());
         if ($ret->hasFailed()) {
             throw new \Exception($ret->getError()->getMessage());
         }
     } else {
         foreach ($orderDetails->getOrder()->getPayments() as $payment) {
             /** @var \WirecardCEE_QPay_Response_Toolkit_Order_Payment $payment */
             if (in_array('DEPOSITREVERSAL', $payment->getOperationsAllowed())) {
                 $log .= " action:DEPOSITREVERSAL APPROVEREVERSAL";
                 $ret = $backendClient->depositReversal($orderNumber, $payment->getPaymentNumber());
                 if ($ret->hasFailed()) {
                     throw new \Exception($ret->getError()->getMessage());
                 }
             }
         }
     }
     $this->_logger->debug(__METHOD__ . ":{$log}");
     return $this;
 }