/** * Process DoCapture response * * @param \XLite\Model\Payment\BackendTransaction $transaction Transaction * @param string $responseData Response data OPTIONAL * * @return boolean */ protected function processRefundTransactionResponse(\XLite\Model\Payment\BackendTransaction $transaction, $responseData = null) { $result = false; if (!empty($responseData)) { $status = \XLite\Model\Payment\Transaction::STATUS_FAILED; if ('Success' === $responseData['ACK']) { $result = true; $status = \XLite\Model\Payment\Transaction::STATUS_SUCCESS; $transaction->getPaymentTransaction()->getOrder()->setPaymentStatus(\XLite\Model\Order\Status\Payment::STATUS_REFUNDED); // save transaction id for IPN $transaction->setDataCell('PPREF', $responseData['REFUNDTRANSACTIONID'], 'Unique PayPal transaction ID (REFUNDTRANSACTIONID)'); \XLite\Core\TopMessage::getInstance()->addInfo('Payment has bes refunded successfully'); } else { \XLite\Core\TopMessage::getInstance()->addError('Transaction failure. PayPal response: ' . $responseData['L_LONGMESSAGE0']); } $transaction->setStatus($status); $transaction->update(); } return $result; }
/** * Refund * * @param \XLite\Model\Payment\BackendTransaction $transaction Backend transaction * * @return boolean */ protected function doRefund(\XLite\Model\Payment\BackendTransaction $transaction) { $this->includeVelocityLibrary(); $backendTransactionStatus = $transaction::STATUS_FAILED; $errorData = ''; if ($this->getSetting('mode') == 'test') { $isTestAccount = true; } else { $isTestAccount = false; } try { $velocityProcessor = new \VelocityProcessor(self::$applicationprofileid, self::$merchantprofileid, self::$workflowid, $isTestAccount, self::$identitytoken); } catch (Exception $e) { $transaction->setDataCell('error_message', $e->getMessage(), 'Velocity error message'); $errorData .= $e->getMessage(); } $refund_amount = $transaction->getValue(); $txnid = $transaction->getPaymentTransaction()->getDataCell('velocity_payment_id')->getValue(); try { // request for refund $response = $velocityProcessor->returnById(array('amount' => $refund_amount, 'TransactionId' => $txnid)); $xml = \VelocityXmlCreator::returnByIdXML($refund_amount, $txnid); // got ReturnById xml object. $req = $xml->saveXML(); $obj_req = serialize($req); if (is_array($response) && !empty($response) && isset($response['Status']) && $response['Status'] == 'Successful') { $backendTransactionStatus = $transaction::STATUS_SUCCESS; $transaction->setDataCell('velocity_refund_id', $response['TransactionId'], 'Velocity Refund ID'); $transaction->setDataCell('approval_code', $response['ApprovalCode'], 'Velocity Approval Code'); $transaction->setDataCell('request_refund_object', $obj_req, 'Velocity Request Refund Object'); $transaction->setDataCell('response_refund_object', serialize($response), 'Velocity Response Refund Object'); $transaction->setDataCell('refund_status', $response['TransactionState'], 'Refund Transaction Status'); $transaction->setStatus($backendTransactionStatus); \XLite\Core\Database::getEM()->flush(); } else { if (is_array($response) && !empty($response)) { $transaction->setDataCell('error_message', $response['StatusMessage'], 'Velocity error message'); $errorData .= $response['StatusMessage']; } else { if (is_string($response)) { $transaction->setDataCell('error_message', $response, 'Velocity error message'); $errorData .= $response; } else { $transaction->setDataCell('error_message', 'Unknown Error please contact the site admin', 'Velocity error message'); $errorData .= 'Unknown Error please contact the site admin'; } } } } catch (Exception $e) { $transaction->setDataCell('error_message', $e->getMessage(), 'Velocity error message'); $errorData .= $e->getMessage(); } if (\XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS == $backendTransactionStatus) { $order = $transaction->getPaymentTransaction()->getOrder(); $paymentTransactionSums = $order->getRawPaymentTransactionSums(); $refunded = $paymentTransactionSums['refunded']; $status = $refunded < $transaction->getPaymentTransaction()->getValue() ? \XLite\Model\Order\Status\Payment::STATUS_PART_PAID : \XLite\Model\Order\Status\Payment::STATUS_REFUNDED; $order->setPaymentStatus($status); \XLite\Core\TopMessage::getInstance()->addInfo('Payment has been refunded successfully'); } else { $msg = 'Transaction failure'; if (!empty($errorData)) { $msg .= '-' . $errorData; } \XLite\Core\TopMessage::getInstance()->addError($msg); } return \XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS == $backendTransactionStatus; }
/** * Refund * * @param \XLite\Model\Payment\BackendTransaction $transaction Backend transaction * @param boolean $isDoVoid Is void action OPTIONAL * * @return boolean */ protected function doRefund(\XLite\Model\Payment\BackendTransaction $transaction, $isDoVoid = false) { $this->includeStripeLibrary(); $backendTransactionStatus = \XLite\Model\Payment\BackendTransaction::STATUS_FAILED; try { $payment = \Stripe_Charge::retrieve($transaction->getPaymentTransaction()->getDataCell('stripe_id')->getValue()); if ($transaction->getValue() != $transaction->getPaymentTransaction()->getValue()) { $payment->refund(array('id' => $transaction->getPaymentTransaction()->getDataCell('stripe_id')->getValue(), 'amount' => $this->formatCurrency($transaction->getValue()))); $refundTransaction = null; foreach ($payment->refunds as $r) { if (!$this->isRefundTransactionRegistered($r)) { $refundTransaction = $r; break; } } } else { $payment->refund(); $refundTransaction = reset($payment->refunds); } if ($refundTransaction) { $backendTransactionStatus = \XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS; $transaction->setDataCell('stripe_date', $refundTransaction->created); if ($refundTransaction->balance_transaction) { $transaction->setDataCell('stripe_b_txntid', $refundTransaction->balance_transaction); } } } catch (\Exception $e) { $transaction->setDataCell('errorMessage', $e->getMessage()); \XLite\Logger::getInstance()->log($e->getMessage(), LOG_ERR); \XLite\Core\TopMessage::addError($e->getMessage()); } $transaction->setStatus($backendTransactionStatus); return \XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS == $backendTransactionStatus; }
protected function doRefund(\XLite\Model\Payment\BackendTransaction $transaction, $isDoVoid = false) { $this->includeSecuresubmitLibrary(); $backendTransactionStatus = \XLite\Model\Payment\BackendTransaction::STATUS_FAILED; $transactionId = $transaction->getPaymentTransaction()->getDataCell('heartland_id')->getValue(); try { if ($isDoVoid) { $payment = $this->chargeService->void($transactionId); } else { $payment = $this->chargeService->refund($this->transaction->getValue(), 'usd', $transactionId); } $backendTransactionStatus = \XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS; $transaction->setDataCell('refund_txnid', $payment->transactionId); } catch (\Exception $e) { $transaction->setDataCell('errorMessage', $e->getMessage()); \XLite\Logger::getInstance()->log($e->getMessage(), LOG_ERR); \XLite\Core\TopMessage::addError($e->getMessage()); } $transaction->setStatus($backendTransactionStatus); return \XLite\Model\Payment\BackendTransaction::STATUS_SUCCESS == $backendTransactionStatus; }
/** * {@inheritDoc} */ public function setDataCell($name, $value, $label = NULL) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setDataCell', array($name, $value, $label)); return parent::setDataCell($name, $value, $label); }