Пример #1
0
 /**
  * Payment refund
  *
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param float $amount
  * @return $this
  * @throws \Magento\Framework\Validator\Exception
  */
 public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $transactionId = $payment->getParentTransactionId();
     try {
         \Stripe\Charge::retrieve($transactionId)->refund();
     } catch (\Exception $e) {
         $this->debugData(['transaction_id' => $transactionId, 'exception' => $e->getMessage()]);
         $this->_logger->error(__('Payment refunding error.'));
         throw new \Magento\Framework\Validator\Exception(__('Payment refunding error.'));
     }
     $payment->setTransactionId($transactionId . '-' . \Magento\Sales\Model\Order\Payment\Transaction::TYPE_REFUND)->setParentTransactionId($transactionId)->setIsTransactionClosed(1)->setShouldCloseParentTransaction(1);
     return $this;
 }
Пример #2
0
 public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     if (!$this->hmacIsValid()) {
         $this->_logger->error('HMAC SHA-256 from Monetra client ticket request failed verification.');
         throw new LocalizedException(__('Verification of payment information failed.'));
     }
     $ticket = $this->getInfoInstance()->getAdditionalInformation('ticket');
     try {
         $monetra = new MonetraInterface($this->getMonetraConfigData());
         $response = $monetra->authorize($ticket, $amount);
     } catch (MonetraException $e) {
         $this->_logger->critical("Error occurred while attempting Monetra authorization. Details: " . $e->getMessage());
         throw new LocalizedException(__($this->_scopeConfig->getValue('payment/monetra_client_ticket/user_facing_error_message')));
     }
     if ($response['code'] !== 'AUTH') {
         $this->_logger->info(sprintf('Monetra authorization failed for TTID %d. Verbiage: %s', $response['ttid'], $response['verbiage']));
         throw new LocalizedException(__($this->_scopeConfig->getValue('payment/monetra_client_ticket/user_facing_deny_message')));
     }
     $payment->setTransactionId($response['ttid']);
     $payment->setIsTransactionClosed(false);
     return $this;
 }
Пример #3
0
 /**
  * Order Payment
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param float $amount
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function order(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     $order = $payment->getOrder();
     $orderId = ltrim($order->getIncrementId(), '0');
     $data = ['transaction_id' => $this->getModuleHelper()->genTransactionId($orderId), 'transaction_types' => $this->getConfigHelper()->getTransactionTypes(), 'order' => ['currency' => $order->getBaseCurrencyCode(), 'language' => $this->getModuleHelper()->getLocale(), 'amount' => $amount, 'usage' => $this->getModuleHelper()->buildOrderUsage(), 'description' => $this->getModuleHelper()->buildOrderDescriptionText($order), 'customer' => ['email' => $this->getCheckoutSession()->getQuote()->getCustomerEmail()], 'billing' => $order->getBillingAddress(), 'shipping' => $order->getShippingAddress()], 'urls' => ['notify' => $this->getModuleHelper()->getNotificationUrl($this->getCode()), 'return_success' => $this->getModuleHelper()->getReturnUrl($this->getCode(), "success"), 'return_cancel' => $this->getModuleHelper()->getReturnUrl($this->getCode(), "cancel"), 'return_failure' => $this->getModuleHelper()->getReturnUrl($this->getCode(), "failure")]];
     $this->getConfigHelper()->initGatewayClient();
     try {
         $responseObject = $this->checkout($data);
         $payment->setTransactionId($responseObject->unique_id);
         $payment->setIsTransactionPending(true);
         $payment->setIsTransactionClosed(false);
         $this->getModuleHelper()->setPaymentTransactionAdditionalInfo($payment, $responseObject);
         $this->getCheckoutSession()->setEmerchantPayCheckoutRedirectUrl($responseObject->redirect_url);
         return $this;
     } catch (\Exception $e) {
         $this->getLogger()->error($e->getMessage());
         $this->getModuleHelper()->maskException($e);
     }
 }
Пример #4
0
 /**
  * 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();
     }
 }
 /**
  * @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
 }
Пример #6
0
 public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount)
 {
     if (!$this->canAuthorize()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The authorize action is not available.'));
     }
     $payment->getAdditionalInformation();
     $order = $payment->getOrder();
     $billing_address = $order->getBillingAddress();
     $shipping_address = $order->getShippingAddress();
     $params = array();
     $params["sellerId"] = $this->getConfigData("merchant_id");
     $params["privateKey"] = $this->getConfigData("private_key");
     $params["merchantOrderId"] = $order->getRealOrderId();
     $params["currency"] = $order->getOrderCurrencyCode();
     $params["token"] = $payment->getAdditionalInformation()['token'];
     $params["total"] = round($order->getGrandTotal(), 2);
     // Set billing info
     $params["billingAddr"] = array();
     $params["billingAddr"]["name"] = $billing_address->getName();
     $params["billingAddr"]["addrLine1"] = $billing_address->getStreet()[0];
     if (count($billing_address->getStreet()) > 1) {
         $params["billingAddr"]["addrLine2"] = $billing_address->getStreet()[1];
     }
     $params["billingAddr"]["city"] = $billing_address->getCity();
     $params["billingAddr"]["state"] = $billing_address->getRegion();
     $params["billingAddr"]["zipCode"] = $billing_address->getPostcode();
     $params["billingAddr"]["country"] = $billing_address->getCountryId();
     $params["billingAddr"]["email"] = $order->getCustomerEmail();
     $params["billingAddr"]["phoneNumber"] = $billing_address->getTelephone();
     if (isset($shipping_address)) {
         $params["shippingAddress"] = array();
         $params["shippingAddress"]["name"] = $shipping_address->getName();
         $params["shippingAddress"]["addrLine1"] = $shipping_address->getStreet()[0];
         if (count($shipping_address->getStreet()) > 1) {
             $params["shippingAddress"]["addrLine2"] = $shipping_address->getStreet()[1];
         }
         $params["shippingAddress"]["city"] = $shipping_address->getCity();
         $params["shippingAddress"]["state"] = $shipping_address->getRegion();
         $params["shippingAddress"]["zipCode"] = $shipping_address->getPostcode();
         $params["shippingAddress"]["country"] = $shipping_address->getCountryId();
     }
     $client = $this->_httpClientFactory->create();
     $path = $this->getConfigData('merchant_id') . "/rs/authService";
     $url = $this->getPaymentApiUrl();
     $client->setUri($url . $path);
     $client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
     $client->setHeaders(['Accept: application/json', 'Content-Type: application/json']);
     $client->setMethod(\Zend_Http_Client::POST);
     $client->setRawData(json_encode($params), 'application/json');
     try {
         $response = $client->request();
         $responseBody = json_decode($response->getBody(), true);
         if (isset($responseBody['exception'])) {
             throw new \Magento\Framework\Exception\LocalizedException(__($responseBody['exception']['errorMsg']));
         } elseif (!isset($responseBody['response'])) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Error placing transaction.'));
         }
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()));
     }
     $payment->setTransactionId($responseBody['response']['transactionId']);
     $payment->setIsTransactionClosed(0);
     $payment->setTransactionAdditionalInfo('tco_order_number', $responseBody['response']['orderNumber']);
     $payment->setAdditionalInformation('tco_order_number', $responseBody['response']['orderNumber']);
     $payment->setAdditionalInformation('tco_order_status', 'approved');
     return $this;
 }
Пример #7
0
 /**
  * Perform the payment review
  *
  * @param InfoInterface $payment
  * @param string $action
  * @return bool
  */
 public function reviewPayment(InfoInterface $payment, $action)
 {
     $request = $this->buildBasicRequest();
     $transactionId = $payment->getCcTransId() ? $payment->getCcTransId() : $payment->getLastTransId();
     $request->setTrxtype(self::TRXTYPE_ACCEPT_DENY);
     $request->setOrigid($transactionId);
     $request->setUpdateaction($action);
     $response = $this->postRequest($request, $this->getConfig());
     $payment->setAdditionalInformation((array) $response->getData());
     $this->processErrors($response);
     if (!$this->_isTransactionUnderReview($response->getOrigresult())) {
         $payment->setTransactionId($response->getOrigpnref())->setIsTransactionClosed(0);
         if ($response->getOrigresult() == self::RESPONSE_CODE_APPROVED) {
             $payment->setIsTransactionApproved(true);
         } elseif ($response->getOrigresult() == self::RESPONSE_CODE_DECLINED_BY_MERCHANT) {
             $payment->setIsTransactionDenied(true);
         }
     }
     $rawData = $response->getData();
     return $rawData ? $rawData : [];
 }
Пример #8
0
 /**
  * Void payment
  *
  * @param \Magento\Framework\Object|\Magento\Payment\Model\InfoInterface|Payment $payment
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function void(\Magento\Payment\Model\InfoInterface $payment)
 {
     //Switching to order transaction if needed
     if ($payment->getAdditionalInformation($this->_isOrderPaymentActionKey) && !$payment->getVoidOnlyAuthorization()) {
         $orderTransaction = $payment->lookupTransaction(false, Transaction::TYPE_ORDER);
         if ($orderTransaction) {
             $payment->setParentTransactionId($orderTransaction->getTxnId());
             $payment->setTransactionId($orderTransaction->getTxnId() . '-void');
         }
     }
     $this->_pro->void($payment);
     return $this;
 }
Пример #9
0
 /**
  * Process capture request
  *
  * @param \Magento\Authorizenet\Model\Directpost\Response $result
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function processCapture($result, $payment)
 {
     switch ($result->getXResponseCode()) {
         case self::RESPONSE_CODE_APPROVED:
         case self::RESPONSE_CODE_HELD:
             if (in_array($result->getXResponseReasonCode(), [self::RESPONSE_REASON_CODE_APPROVED, self::RESPONSE_REASON_CODE_PENDING_REVIEW, self::RESPONSE_REASON_CODE_PENDING_REVIEW_AUTHORIZED])) {
                 if (!$payment->getParentTransactionId() || $result->getXTransId() != $payment->getParentTransactionId()) {
                     $payment->setTransactionId($result->getXTransId());
                 }
                 $payment->setIsTransactionClosed(0)->setTransactionAdditionalInfo(self::REAL_TRANSACTION_ID_KEY, $result->getXTransId());
                 return $this;
             }
             throw new \Magento\Framework\Exception\LocalizedException($this->dataHelper->wrapGatewayError($result->getXResponseReasonText()));
         case self::RESPONSE_CODE_DECLINED:
         case self::RESPONSE_CODE_ERROR:
             throw new \Magento\Framework\Exception\LocalizedException($this->dataHelper->wrapGatewayError($result->getXResponseReasonText()));
         default:
             throw new \Magento\Framework\Exception\LocalizedException(__('Payment capturing error.'));
     }
 }
 /**
  * Initiate a Payment Gateway Reference Transaction
  *      - Capture
  *      - Refund
  *      - Void
  *
  * @param string $transactionType
  * @param \Magento\Payment\Model\InfoInterface $payment
  * @param array $data
  * @return \stdClass
  */
 protected function processReferenceTransaction($transactionType, \Magento\Payment\Model\InfoInterface $payment, $data)
 {
     $transactionType = ucfirst(strtolower($transactionType));
     $this->getConfigHelper()->initGatewayClient();
     $genesis = new \Genesis\Genesis("Financial\\{$transactionType}");
     foreach ($data as $key => $value) {
         $methodName = sprintf("set%s", \Genesis\Utils\Common::snakeCaseToCamelCase($key));
         $genesis->request()->{$methodName}($value);
     }
     $genesis->execute();
     $responseObject = $genesis->response()->getResponseObject();
     $payment->setTransactionId($responseObject->unique_id)->setParentTransactionId($data['reference_id'])->setShouldCloseParentTransaction(true)->setIsTransactionPending(false)->setIsTransactionClosed(true)->resetTransactionAdditionalInfo();
     $this->getModuleHelper()->setPaymentTransactionAdditionalInfo($payment, $responseObject);
     $payment->save();
     return $responseObject;
 }
Пример #11
0
 /**
  * Void payment
  * Void is in regards to the payment on the order invoice - to void the authorization, for instance - so that
  * the funds aren't subsequently captured. Payments have to be refunded after capture and cannot be voided.
  *
  * map this operation to APPROVEREVERSAL
  *
  * @param \Magento\Framework\DataObject|InfoInterface|\Magento\Sales\Model\Order\Payment $payment
  *
  * @return $this
  * @throws \Exception
  * @api
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function void(\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();
     $approveDone = false;
     foreach ($orderDetails->getOrder()->getPayments() as $wdPayment) {
         /** @var \WirecardCEE_QPay_Response_Toolkit_Order_Payment $wdPayment */
         $this->_logger->debug(__METHOD__ . ':operations allowed:' . implode(',', $wdPayment->getOperationsAllowed()));
         if (in_array('APPROVEREVERSAL', $wdPayment->getOperationsAllowed())) {
             $this->_logger->debug(__METHOD__ . ":{$orderNumber}");
             $ret = $backendClient->approveReversal($orderNumber);
             if ($ret->hasFailed()) {
                 throw new \Exception($ret->getError()->getMessage());
             }
             $approveDone = true;
             $orderTransaction = $this->_transactionRepository->getByTransactionType(Transaction::TYPE_ORDER, $payment->getId(), $payment->getOrder()->getId());
             if ($orderTransaction) {
                 $payment->setParentTransactionId($orderTransaction->getTxnId());
                 $payment->setTransactionId($orderTransaction->getTxnId() . '-void');
             }
             $payment->addTransactionCommentsToOrder($orderTransaction, 'approveReversal');
         }
     }
     if (!$approveDone) {
         throw new \Exception($this->_dataHelper->__('Void not possible anymore for this payment, please try cancel instead!'));
     }
     return $this;
 }