/** * Get payflow transaction id from parent transaction * * @param Varien_Object $payment * @return string */ protected function _getParentTransactionId(Varien_Object $payment) { if ($payment->getParentTransactionId()) { return $payment->getTransaction($payment->getParentTransactionId())->getAdditionalInformation(Mage_PaypalUk_Model_Pro::TRANSPORT_PAYFLOW_TXN_ID); } return $payment->getParentTransactionId(); }
public function refund(Varien_Object $payment, $amount) { $transactionId = $payment->getParentTransactionId(); try { Stripe_Charge::retrieve($transactionId)->refund(); } catch (Exception $e) { $this->debugData($e->getMessage()); Mage::throwException(Mage::helper('paygate')->__('Payment refunding error.')); } $payment->setTransactionId($transactionId . '-' . Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND)->setParentTransactionId($transactionId)->setIsTransactionClosed(1)->setShouldCloseParentTransaction(1); return $this; }
public function refund(Varien_Object $payment, $amount) { $pagarme = Mage::getModel('pagarme/api'); $transaction = $pagarme->refund($payment->getPagarmeTransactionId()); if ($transaction->getErrors()) { $messages = array(); foreach ($transaction->getErrors() as $error) { $messages[] = $error->getMessage() . '.'; } Mage::throwException(implode("\n", $messages)); } $payment->setTransactionId($payment->getPagarmeTransactionId() . '-' . Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND)->setParentTransactionId($payment->getParentTransactionId())->setIsTransactionClosed(1)->setShouldCloseParentTransaction(1)->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('status' => $transaction->getStatus())); return $this; }
public function refund(Varien_Object $payment, $amount) { $payment instanceof Mage_Sales_Model_Order_Payment; $order = $payment->getOrder(); $store = $order->getStore(); $serviceId = Mage::getStoreConfig('pay_payment/general/serviceid', $store); $apiToken = Mage::getStoreConfig('pay_payment/general/apitoken', $store); //todo: Doe iets met de api $parentTransactionId = $payment->getParentTransactionId(); $apiRefund = Mage::helper('pay_payment/api_refund'); $apiRefund instanceof Pay_Payment_Helper_Api_Refund; $apiRefund->setApiToken($apiToken); $apiRefund->setServiceId($serviceId); $apiRefund->setTransactionId($parentTransactionId); $amount = (int) round($amount * 100); $apiRefund->setAmount($amount); $apiRefund->doRequest(); // die($parentTransactionId); return $this; }
public function refund(Varien_Object $payment, $amount) { $order = $payment->getOrder(); $store = $order->getStore(); $serviceId = Mage::getStoreConfig('pay_payment/general/serviceid', $store); $apiToken = Mage::getStoreConfig('pay_payment/general/apitoken', $store); $useBackupApi = Mage::getStoreConfig('pay_payment/general/use_backup_api', $store); $backupApiUrl = Mage::getStoreConfig('pay_payment/general/backup_api_url', $store); if ($useBackupApi == 1) { Pay_Payment_Helper_Api::_setBackupApiUrl($backupApiUrl); } $parentTransactionId = $payment->getParentTransactionId(); $apiRefund = Mage::helper('pay_payment/api_refund'); $apiRefund instanceof Pay_Payment_Helper_Api_Refund; $apiRefund->setApiToken($apiToken); $apiRefund->setServiceId($serviceId); $apiRefund->setTransactionId($parentTransactionId); $amount = (int) round($amount * 100); $apiRefund->setAmount($amount); $apiRefund->doRequest(); return $this; }
/** * Capture payment * * @param Mage_Sales_Model_Order_Payment $payment * @return Mage_Paypal_Model_Payflowpro */ public function capture(Varien_Object $payment, $amount) { if ($payment->getParentTransactionId()) { $request = $this->_buildBasicRequest($payment); $request->setTrxtype(self::TRXTYPE_DELAYED_CAPTURE); $request->setOrigid($payment->getParentTransactionId()); } else { $request = $this->_buildPlaceRequest($payment, $amount); $request->setTrxtype(self::TRXTYPE_SALE); } $response = $this->_postRequest($request); $this->_processErrors($response); switch ($response->getResultCode()) { case self::RESPONSE_CODE_APPROVED: $payment->setTransactionId($response->getPnref())->setIsTransactionClosed(0); break; case self::RESPONSE_CODE_FRAUDSERVICE_FILTER: $payment->setTransactionId($response->getPnref())->setIsTransactionClosed(0); $payment->setIsTransactionPending(true); $payment->setIsFraudDetected(true); break; } return $this; }
/** * Void payment * * @param Varien_Object $invoicePayment * @return Mage_Payment_Model_Abstract */ public function void(Varien_Object $payment) { //parent::void($payment); if ($authTransactionId = $payment->getParentTransactionId()) { $request = $this->_getApiRequest(); $request->setData('transaction_id', $authTransactionId); $this->_getApi()->doVoid($request); } else { Mage::throwException(Mage::helper('enterprise_pbridge')->__('Authorization transaction is required to void.')); } return $this->_getApi()->getResponse(); }
/** * Void the payment through gateway * * @param Varien_Object $payment * @return Mage_Paygate_Model_Authorizenet * @throws Mage_Core_Exception */ public function void(Varien_Object $payment) { if ($payment->getParentTransactionId()) { $data = $this->_prepareData(); $data['ordertype'] = "VOID"; $data["oid"] = $payment->getParentTransactionId(); $merchantinfo = array(); $merchantinfo['configfile'] = $data['storenumber']; $merchantinfo['keyfile'] = $data['key']; $data = array_merge($data, $merchantinfo); $result = $this->_postRequest($data); if (is_array($result) && count($result) > 0) { if (array_key_exists("r_approved", $result)) { if ($result["r_approved"] != "APPROVED") { Mage::throwException("Gateway error : {" . (string) $result["r_error"] . "}"); } else { $payment->setStatus(self::STATUS_SUCCESS); return $this; } } else { Mage::throwException("No approval found"); } } else { Mage::throwException("No response found"); } } $payment->setStatus(self::STATUS_ERROR); Mage::throwException('Invalid transaction ID.'); }
/** * Void payment * * @param Varien_Object $payment * @return Mage_Payment_Model_Abstract */ public function void(Varien_Object $payment) { //parent::void($payment); if ($authTransactionId = $payment->getParentTransactionId()) { $request = $this->_getApiRequest(); $this->_setAdditionalRequestParameters($request, $payment); $request->addData(array('transaction_id' => $authTransactionId, 'amount' => $payment->getOrder()->getBaseTotalDue())); $this->_getApi()->doVoid($request); } else { Mage::throwException(Mage::helper('enterprise_pbridge')->__('Authorization transaction is required to void.')); } return $this->_getApi()->getResponse(); }
/** * Preapare basic paramters for transaction * * @param Varien_Object $payment * @param decimal $amount * @return array */ protected function _prepareTxnDetails(Varien_Object $payment, $amount) { if ($payment->getParentTransactionId()) { $txnDetails = array('txn_type' => self::TRANSACTION_TYPE_CAPTURE, 'capture_transaction_id' => $payment->getParentTransactionId()); } else { $billingAddress = $payment->getOrder()->getBillingAddress(); if ($payment->getOrder()->getCustomerEmail()) { $customerEmail = $payment->getOrder()->getCustomerEmail(); } elseif ($billingAddress->getEmail()) { $customerEmail = $billingAddress->getEmail(); } else { $customerEmail = ''; } $txnDetails = array('card_holder_name' => $payment->getCcOwner(), 'card_number' => $payment->getCcNumber(), 'card_type' => $this->_convertCcType($payment->getCcType()), 'card_expiry' => sprintf('%02d', $payment->getCcExpMonth()) . substr($payment->getCcExpYear(), 2, 2), 'card_csc' => $payment->getCcCid(), 'customer_email' => $customerEmail); if ($this->getConfigData('payment_action') == self::ACTION_AUTHORIZE) { $txnDetails['txn_type'] = self::TRANSACTION_TYPE_AUTHORISE; } else { $txnDetails['txn_type'] = self::TRANSACTION_TYPE_PURCHASE; } } $accountId = $payment->getFlo2cashAccountId(); //if transaction type is authorize & capture or only authorize if (is_null($accountId)) { $accountId = $this->getAccountId(); } $txnDetails = array_merge($txnDetails, array('merchant_reference' => $payment->getOrder()->getIncrementId(), 'paynz_account_id' => $accountId, 'amount' => sprintf('%.2f', $amount))); return $txnDetails; }
/** * Void the payment through gateway * * @param Varien_Object $payment * @return Mage_Paygate_Model_Authorizenet * @throws Mage_Core_Exception */ public function void(Varien_Object $payment) { if ($payment->getParentTransactionId()) { $payment->setAnetTransType(self::REQUEST_TYPE_VOID); $request = $this->_buildRequest($payment); $request->setXTransId($payment->getParentTransactionId()); $result = $this->_postRequest($request); if ($result->getResponseCode() == self::RESPONSE_CODE_APPROVED) { $payment->setStatus(self::STATUS_SUCCESS); return $this; } $payment->setStatus(self::STATUS_ERROR); Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText())); } $payment->setStatus(self::STATUS_ERROR); Mage::throwException(Mage::helper('paygate')->__('Invalid transaction ID.')); }
public function refund(Varien_Object $payment, $amount) { $payment->setAmount($amount); $payment->setOpcode(self::OPCODE_REFUND); $this->setTransactionId($payment->getParentTransactionId()); $request = $this->_buildRequest($payment); $result = $this->_postRequest($request); $payment->setStatus(self::STATUS_APPROVED)->setTransactionId($result->getTransaction())->setIsTransactionClosed(1); return $this; }
public function cancel(Varien_Object $payment) { $session = Mage::getSingleton('adminhtml/session'); if (Mage::app()->getRequest()->getActionName() == 'save') { $order = $payment->getOrder(); $_totalDatas = $order->getData(); $childOrder = Mage::getModel('sales/order')->loadByIncrementId($_totalDatas['relation_child_real_id']); if ($childOrder->getBaseGrandTotal() <= $order->getBaseGrandTotal()) { $childPayment = $childOrder->getPayment(); $write = Mage::getSingleton('core/resource')->getConnection('core_write'); $write->query('update epay_order_status set orderid = "' . $_totalDatas['relation_child_real_id'] . '" WHERE orderid = "' . $order->getIncrementId() . '"'); $transactionId = $payment->getParentTransactionId(); $childPayment->setTransactionId($transactionId)->setIsTransactionClosed(0); $transaction = $childPayment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH); $transaction->setAdditionalInformation("Transaction ID", $transactionId); $transaction->save(); } else { $session->addError("The transaction could not be moved because the amount of the edited order exceeds the transaction amount - Go to the ePay administration to handle the payment manually."); } return; } // // Verify if remote interface is enabled // if ((int) $this->getConfigData('remoteinterface', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null) != 1) { $this->addOrderComment($payment->getOrder(), Mage::helper('epay')->__('EPAY_LABEL_75')); return; } try { // // Read info directly from the database // $read = Mage::getSingleton('core/resource')->getConnection('core_read'); $row = $read->fetchRow("select * from epay_order_status where orderid = '" . $payment->getOrder()->getIncrementId() . "'"); if ($row["status"] == '1') { $tid = $row["tid"]; $param = array('merchantnumber' => $this->getConfigData('merchantnumber', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null), 'transactionid' => $tid, 'group' => '', 'epayresponse' => 0, 'pwd' => $this->getConfigData('remoteinterfacepassword', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null)); $client = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL'); $result = $client->delete($param); if ($result->deleteResult == 1) { // // Success - transaction deleted! // $this->addOrderComment($payment->getOrder(), "Transaction deleted with transaction id: " . $tid); $payment->getOrder()->save(); } else { if ($result->epayresponse != -1) { if ($result->epayresponse == -1002) { $this->addOrderComment($payment->getOrder(), "Transaction could not be deleted by ePay: " . $result->epayresponse . ". Forretningsnummeret findes ikke."); throw new Exception("Transaction could not be deleted by ePay: " . $result->epayresponse . ". Forretningsnummeret findes ikke."); } elseif ($result->epayresponse == -1003 || $result->epayresponse == -1006) { $this->addOrderComment($payment->getOrder(), "Transaction could not be captured by ePay: " . $result->epayresponse . ". Der er ikke adgang til denne funktion (API / Remote Interface)."); throw new Exception("Transaction could not be deleted by ePay: " . $result->epayresponse . ". Der er ikke adgang til denne funktion (API / Remote Interface)."); } else { $this->addOrderComment($payment->getOrder(), 'Transaction could not be deleted by ePay: ' . $result->epayresponse . '. ' . $this->getEpayErrorText($result->epayresponse)); throw new Exception('Transaction could not be deleted by ePay: ' . $result->epayresponse . '. ' . $this->getEpayErrorText($result->epayresponse)); } } else { throw new Exception('Unknown response from ePay: ' . $result->epayresponse); } } } elseif ($row["status"] == '0') { // // Do nothing - the order is to be canceled without any communication to ePay // } else { // // Somehow the order was not found - this must be an error! // throw new Exception("Order not found - please check the epay_order_status table!"); } } catch (Exception $e) { $session->addException($e, $e->getMessage() . " - Go to the ePay administration to credit the payment manually."); } }
/** * void * * @access public * @param string $payment Varien_Object object * @return Mage_Payment_Model_Abstract */ public function void(Varien_Object $payment) { $error = false; if ($payment->getParentTransactionId()) { $payment->setTrxtype(self::TRXTYPE_DELAYED_VOID); $payment->setTransactionId($payment->getParentTransactionId()); $request = $this->_buildBasicRequest($payment); $result = $this->_postRequest($request); if ($result->getResultCode() == self::RESPONSE_CODE_APPROVED) { $payment->setStatus(self::STATUS_SUCCESS); $payment->setCcTransId($result->getPnref()); $payment->setTransactionId($result->getPnref()); } else { $payment->setStatus(self::STATUS_ERROR); $error = $result->getRespmsg(); } } else { $payment->setStatus(self::STATUS_ERROR); $error = Mage::helper('paypal')->__('Invalid transaction ID.'); } if ($error !== false) { Mage::throwException($error); } return $this; }
/** * Void previously *authorized* payment. * * @param Varien_Object $payment * @return Mage_Payment_Model_Abstract */ public function void(Varien_Object $payment) { list($transactionId, ) = explode('-', $payment->getParentTransactionId()); $parameters = array('transactionId' => $transactionId); $result = $this->_apiCall('CancelTransaction', $parameters); $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array_merge($result, $parameters)); return $this; }
protected function _call(Varien_Object $payment, $callby = '', $amountcalled) { if ($this->getDebug()) { $writer = new Zend_Log_Writer_Stream($this->getLogPath()); $logger = new Zend_Log($writer); $logger->info("paymentAction: " . $this->getPaymentAction()); $storeId = $payment->getOrder()->getStoreId(); $logger->info("Storeid: " . $storeId); } //print "<pre>"; print_r($payment); print "</pre>"; exit; $ExpirationDate = $payment->getCcExpYear() . '-' . str_pad($payment->getCcExpMonth(), 2, '0', STR_PAD_LEFT); $invoiceno = $payment->getOrder()->getIncrementId(); $CustomerEmail = $payment->getOrder()->getCustomerEmail(); $CustomerId20 = $payment->getOrder()->getCustomerId(); $storeId = $payment->getOrder()->getStoreId(); $billToWho = $payment->getOrder()->getBillingAddress(); $shipToWho = $payment->getOrder()->getShippingAddress(); $tax = $payment->getOrder()->getTaxAmount(); $cvv = $payment->getCcCid(); if ($this->getStrictCVV()) { if (!$cvv) { $cvv = "111"; } } $ccnum = $payment->getCcNumber(); $ponum = $payment->getPoNumber(); if ($ccnum == '') { $ccnum = "tkn-{$ponum}"; } if ($ponum == '') { $ponum = $ccnum; } $cim = $payment->getCcSsStartMonth(); if ($this->getDebug()) { $logger->info("CcNumber PoNumber: {$ccnum}, {$ponum} SaveCimCC: {$cim}\n"); } if ($amountcalled < 1) { $amountcalled = $this->getAmount(); } $url = $this->getGatewayUrl(); if (strpos($ccnum, 'tkn') !== FALSE) { $fields = preg_split('/-/', $ccnum); $CustomerProfileID = $fields[1]; $PaymentProfileID = $fields[2]; $fields2 = preg_split('/-/', $ponum); $Approval = $fields2[2]; $fullcarddata = true; } else { $fields = preg_split('/-/', $ponum); $CustomerProfileID = $fields[0]; $fullcarddata = true; if (isset($fields[1]) and $callby != 'authorize' and strpos($ccnum, '-') !== FALSE) { $PaymentProfileID = $fields[1]; } else { $PaymentProfileID = 0; } if (isset($fields[2])) { $Approval = $fields[2]; } else { $Approval = 0; } } $authtransID = $payment->getOrder()->getTransactionId(); if ($authtransID < 1) { $authtransID = $payment->getParentTransactionId(); } if ($authtransID < 1) { $authtransID = $payment->getCcTransId(); } $authtrans2 = preg_split('/-/', $authtransID); $authtransID = $authtrans2[0]; if ($this->getDebug()) { $logger->info("from database: {$CustomerProfileID}, {$PaymentProfileID}, {$authtransID}\n"); } /* If we have the Customer ID and Payment ID, we can just do the transaction */ if ($CustomerProfileID > 0 and $PaymentProfileID > 0) { $TxRqXML = $this->createTransXML($amountcalled, $tax, $CustomerProfileID, $PaymentProfileID, $callby, $invoiceno, $authtransID, $Approval, $storeId); $TxRqResponse = $this->processRequest($url, $TxRqXML); if (isset($shipToWho['lastname']) and $shipToWho['lastname'] > '') { $createCustomerShippingAddressXML = $this->createCustomerShippingAddressXML($CustomerProfileID, $shipToWho, $storeId); $response = $this->processRequest($url, $createCustomerShippingAddressXML); if ($this->getDebug()) { $logger->info("\n\n Shipping Address Response: {$response}\n\n"); } } } else { /* First try to create a Customer Profile */ $CustProfileXML = $this->createCustomerXML($ccnum, $CustomerEmail, $ExpirationDate, $CustomerId20, $billToWho, $cvv, $storeId); $response = $this->processRequest($url, $CustProfileXML); $resultErrorCode = $this->parseXML('<code>', '</code>', $response); /* Get Customer Profile ID */ $CustomerProfileID = (int) $this->parseXML('<customerProfileId>', '</customerProfileId>', $response); /* Get Payment Profile ID */ $PaymentProfileID = (int) $this->parseXML('<customerPaymentProfileIdList><numericString>', '</numericString></customerPaymentProfileIdList>', $response); $ExistingCustProfile = $CustomerProfileID; $resultText = $this->parseXML('<text>', '</text>', $response); $resultCode = $this->parseXML('<resultCode>', '</resultCode>', $response); if ($resultErrorCode == 'E00039') { if ($this->getDebug()) { $logger->info("\n\n ALREADY HAVE A CUST PROFILE \n\n"); } $split = preg_split('/ /', $resultText); $ExistingCustProfile = $split[5]; $CustomerProfileID = $ExistingCustProfile; $addPaymentProfileXML = $this->addPaymentProfileXML($ExistingCustProfile, $ccnum, $ExpirationDate, $billToWho, $cvv, $storeId); $response = $this->processRequest($url, $addPaymentProfileXML); $PaymentProfileID = (int) $this->parseXML('<customerPaymentProfileId>', '</customerPaymentProfileId>', $response); $resultErrorCode = $this->parseXML('<code>', '</code>', $response); if ($resultErrorCode == 'E00039') { // Using an existing card already if ($this->getDebug()) { $logger->info("\n\n ALREADY HAVE A PAYMENT PROFILE WITH THE CARD \n\n"); } //Get Correct PaymentProfileID $getCustXML = $this->getProfileXML($ExistingCustProfile, $storeId); $responseGET = $this->processRequest($url, $getCustXML); $PaymentProfileID = $this->parseMultiXML($responseGET, $ccnum); if ($fullcarddata) { $updatePaymentProfileXML = $this->updatePaymentProfileXML($ExistingCustProfile, $PaymentProfileID, $ccnum, $ExpirationDate, $billToWho, $cvv, $storeId); $response = $this->processRequest($url, $updatePaymentProfileXML); if ($this->getDebug()) { $logger->info("\n\n UPDATED PROFILE {$PaymentProfileID} \n\n"); } } if ($this->getDebug()) { $logger->info("\n\ngetCustXML: {$getCustXML} ...\n...\nresponseGET{$responseGET} \n\n"); } } if ($PaymentProfileID == '0') { // Using an existing card already if ($this->getDebug()) { $logger->info("\n\n PROFILE ERROR \n\n"); } //Get Correct PaymentProfileID $getCustXML = $this->getProfileXML($ExistingCustProfile, $storeId); $responseGET = $this->processRequest($url, $getCustXML); $PaymentProfileID = $this->parseMultiXML($responseGET, $ccnum); if ($this->getDebug()) { $logger->info("\n\ngetCustXML: {$getCustXML} ...\n...\nresponseGET{$responseGET} \n\n"); } } if ($this->getDebug()) { $logger->info("\nUSING {$CustomerProfileID} - {$PaymentProfileID}"); } } if (isset($shipToWho['lastname']) and $shipToWho['lastname'] > '') { $createCustomerShippingAddressXML = $this->createCustomerShippingAddressXML($ExistingCustProfile, $shipToWho, $storeId); $response = $this->processRequest($url, $createCustomerShippingAddressXML); if ($this->getDebug()) { $logger->info("\n\n Shipping Address Response: {$response}\n\n"); } } $TxRqXML = $this->createTransXML($amountcalled, $tax, $CustomerProfileID, $PaymentProfileID, $callby, $invoiceno, $authtransID, $Approval, $storeId); $TxRqResponse = $this->processRequest($url, $TxRqXML); } $resultText = $this->parseXML('<text>', '</text>', $TxRqResponse); $resultCode = $this->parseXML('<resultCode>', '</resultCode>', $TxRqResponse); $resultErrorCode = $this->parseXML('<code>', '</code>', $TxRqResponse); $transauthidar = $this->parseXML('<directResponse>', '</directResponse>', $TxRqResponse); $fieldsAU = preg_split('/,/', $transauthidar); $responsecode = $fieldsAU[0]; if (!$responsecode == "1") { $resultCode = "No"; } if (isset($fieldsAU[4])) { $approval = $fieldsAU[4]; } else { $approval = 0; } if (strlen($approval) < 6) { $approval = $Approval; } if (isset($fieldsAU[6])) { $transno = $fieldsAU[6]; } else { $transno = 0; } if ($this->getDebug()) { $logger->info("TransID = {$transno} \n"); } if ($this->getDebug()) { $logger->info("Approval Code = {$approval} \n"); } $paymentInfo = $this->getInfoInstance(); if ($CustomerProfileID > '0' and $PaymentProfileID > '0') { $token = "{$CustomerProfileID}-{$PaymentProfileID}-{$approval}"; $paymentInfo->setCybersourceToken($token); $paymentInfo->setPoNumber($token); $paymentInfo->getOrder()->setTransactionId(); if ($paymentInfo->getCcSsStartMonth() == "on") { $paymentInfo->setCcSsStartMonth('1'); } else { if ($paymentInfo->getCcSsStartMonth() != "1") { $paymentInfo->setCcSsStartMonth('0'); } } } $result['Status']['transno'] = $transno; $result['Status']['approval'] = $approval; $result['Status']['CustomerProfileID'] = $CustomerProfileID; $result['Status']['PaymentProfileID'] = $PaymentProfileID; $result['Status']['statusCode'] = $resultCode; $result['Status']['code'] = $resultErrorCode; $result['Status']['statusDescription'] = $resultText; if ($this->getDebug()) { $logger->info("STATUS CODE = {$resultErrorCode} - {$resultCode} - {$resultText}"); } return $result; }
/** * Return true if the payment has already been preAuthorized. * * @param Varien_Object $payment * @return bool */ protected function _isPreAuthorized($payment) { if ($payment->getParentTransactionId()) { return true; } return false; }
/** * Refund a capture transaction * * @param Varien_Object $payment * @param float $amount */ public function refund(Varien_Object $payment, $amount) { $captureTxnId = $payment->getParentTransactionId(); if ($captureTxnId) { $api = $this->getApi(); $order = $payment->getOrder(); $api->setPayment($payment)->setTransactionId($captureTxnId)->setAmount($amount)->setCurrencyCode($order->getBaseCurrencyCode()); $canRefundMore = $order->canCreditmemo(); // TODO: fix this to be able to create multiple refunds $isFullRefund = !$canRefundMore && 0 == (double) $order->getBaseTotalOnlineRefunded() + (double) $order->getBaseTotalOfflineRefunded(); $api->setRefundType($isFullRefund ? Mage_Paypal_Model_Config::REFUND_TYPE_FULL : Mage_Paypal_Model_Config::REFUND_TYPE_PARTIAL); $api->callRefundTransaction(); $payment->setTransactionId($api->getRefundTransactionId())->setIsTransactionClosed(1)->setShouldCloseParentTransaction(!$canRefundMore); Mage::getModel('paypal/info')->importToPayment($api, $payment); } else { Mage::throwException(Mage::helper('paypal')->__('Impossible to issue a refund transaction, because capture transaction does not exist.')); } }
/** * Capture payment via reference transaction * * @param Mage_Sales_Model_Order_Payment $payment * @param float $amount * @return CLS_Paypal_Model_Paypal_Stored_Payflow */ public function capture(Varien_Object $payment, $amount) { if ($payment->getParentTransactionId()) { // Perform 'Delayed capture' in a usual way return parent::capture($payment, $amount); } else { // Capture funds via Reference Transaction return $this->_placeOrder($payment, $amount, self::TRXTYPE_SALE); } }
public function cancel(Varien_Object $payment) { $sveaOrderId = $payment->getParentTransactionId(); $request = $this->_getCancelOrderRequest($payment, $sveaOrderId); $response = $request->cancelCardOrder()->doRequest(); if ($response->accepted === 0) { $message = 'cancelCardOrder failed for transaction ' . $sveaOrderId . ': ' . $response->errormessage . ' (' . $response->resultcode . ')'; Mage::throwException($message); } $result = $this->_flatten($response); $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $result); return $this; }
/** * Parent transaction id getter * * @param Varien_Object $payment * @return string */ protected function _getParentTransactionId(Varien_Object $payment) { return $payment->getParentTransactionId(); }
/** * Send capture request to gateway * * @param Varien_Object $payment * @param decimal $amount * @return Start_Gateway_Model_Paymentmethod * @throws Mage_Core_Exception */ public function capture(Varien_Object $payment, $amount) { if ($amount <= 0) { Mage::throwException('Invalid amount for capture.'); } $payment->setAmount($amount); if ($payment->getParentTransactionId()) { $payment->setAnetTransType(self::REQUEST_TYPE_PRIOR_AUTH_CAPTURE); $payment->setXTransId($this->_getRealParentTransactionId($payment)); } else { $payment->setAnetTransType(self::REQUEST_TYPE_AUTH_CAPTURE); } //please call this function or some function to call API with token and email to capture authorized amount //$this->collectPayment($payment, $amount); //returning this as all good but it should return $this in case success and throw exception in case of error return $this; }
/** * Refund (fully) both the card and direct bank payments. Payments need * to be captured fully before they can be refunded. Otherwise you will * get "Illegal transaction status (105)". * * @param Varien_Object $payment * @param float $amount * @return $this * @throws Mage_Core_Exception */ public function refund(Varien_Object $payment, $amount) { list($sveaOrderId, ) = explode('-', $payment->getParentTransactionId()); $order = $payment->getOrder(); $paymentMethodConfig = $this->getSveaStoreConfClass($order->getStoreId()); $config = new SveaMageConfigProvider($paymentMethodConfig); $countryId = $order->getBillingAddress()->getCountryId(); $creditAmount = $amount * 100; $creditTransaction = new Svea\HostedService\CreditTransaction($config); $creditTransaction->transactionId = $sveaOrderId; $creditTransaction->creditAmount = $creditAmount; $creditTransaction->countryCode = $countryId; $response = $creditTransaction->doRequest(); if ($response->accepted === 0) { $message = 'CreditTransaction failed for transaction ' . $sveaOrderId . ': ' . $response->errormessage . ' (' . $response->resultcode . ')'; Mage::throwException($message); } $result = $this->_flatten($response); $transactionString = $sveaOrderId . '-refund-' . (int) microtime(true); $payment->setTransactionId($transactionString)->setIsTransactionClosed(true)->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $result); return $this; }
/** * Set reference transaction data into request * * @param Varien_Object $payment * @param Varien_Object $request * @return Mage_Paypal_Model_Payflowlink */ protected function _setReferenceTransaction(Varien_Object $payment, $request) { if ($payment->getParentTransactionId()) { $request->setOrigid($payment->getParentTransactionId()); $request->unsAcct(); $request->unsExpdate(); $request->unsCvv2(); } return $this; }
public function capture(Varien_Object $payment, $amount) { $session = Mage::getSingleton('adminhtml/session'); // // Verify if remote interface is enabled // if (!$this->_canDoCapture($payment->getOrder())) { return $this; } if ((int) $this->getConfigData('remoteinterface', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null) != 1) { $this->addOrderComment($payment->getOrder(), Mage::helper('epay')->__('EPAY_LABEL_73')); return $this; } try { // // Read info directly from the database $read = Mage::getSingleton('core/resource')->getConnection('core_read'); $row = $read->fetchRow("select * from epay_order_status where orderid = '" . $payment->getOrder()->getIncrementId() . "'"); if ($row["status"] == '1') { $epayamount = (string) ($amount * 100); $tid = $row["tid"]; $param = array('merchantnumber' => $this->getConfigData('merchantnumber', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null), 'transactionid' => $tid, 'amount' => $epayamount, 'group' => '', 'pbsResponse' => 0, 'epayresponse' => 0, 'pwd' => $this->getConfigData('remoteinterfacepassword', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null)); $client = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL'); $result = $client->capture($param); if ($result->captureResult == 1) { // // Success - transaction captured! // $this->addOrderComment($payment->getOrder(), "Transaction with id: " . $tid . " has been captured by amount: " . number_format($amount, 2, ",", ".")); if (!$payment->getParentTransactionId() || $tid != $payment->getParentTransactionId()) { $payment->setTransactionId($tid); } $payment->setIsTransactionClosed(0); } else { if ($result->epayresponse != -1) { if ($result->epayresponse == -1002) { $this->addOrderComment($payment->getOrder(), "Transaction could not be deleted by ePay: " . $result->epayresponse . ". Forretningsnummeret findes ikke."); throw new Exception("Transaction could not be captured by ePay: " . $result->epayresponse . ". Forretningsnummeret findes ikke."); } else { if ($result->epayresponse == -1003 || $result->epayresponse == -1006) { $this->addOrderComment($payment->getOrder(), "Transaction could not be captured by ePay: " . $result->epayresponse . ". Der er ikke adgang til denne funktion (API / Remote Interface)."); throw new Exception("Transaction could not be captured by ePay: " . $result->epayresponse . ". Der er ikke adgang til denne funktion (API / Remote Interface)."); } else { $this->addOrderComment($payment->getOrder(), 'Transaction could not be captured by ePay: ' . $result->epayresponse . '. ' . $this->getEpayErrorText($result->epayresponse)); throw new Exception('Transaction could not be captured by ePay: ' . $result->epayresponse . '. ' . $this->getEpayErrorText($result->epayresponse)); } } } else { throw new Exception("Transaction could not be captured by ePay: " . $result->pbsResponse . '. ' . $this->getPbsErrorText($result->pbsResponse)); } } } else { // // Somehow the order was not found - this must be an error! // throw new Exception("Order not found - please check the epay_order_status table!"); } } catch (Exception $e) { $session->addException($e, $e->getMessage() . " - Go to the ePay administration to capture the payment manually."); } return $this; }
/** * refund the amount with transaction id * * @param string $payment Varien_Object object * @return Mage_Authorizenet_Model_Directpost * @throws Mage_Core_Exception */ protected function _refund(Varien_Object $payment, $amount) { if ($amount <= 0) { Mage::throwException(Mage::helper('paygate')->__('Invalid amount for refund.')); } if (!$payment->getParentTransactionId()) { Mage::throwException(Mage::helper('paygate')->__('Invalid transaction ID.')); } $payment->setAnetTransType(self::REQUEST_TYPE_CREDIT); $payment->setAmount($amount); $payment->setXTransId($this->_getRealParentTransactionId($payment)); $request = $this->_buildRequest($payment); $result = $this->_postRequest($request); switch ($result->getResponseCode()) { case self::RESPONSE_CODE_APPROVED: if ($result->getResponseReasonCode() == self::RESPONSE_REASON_CODE_APPROVED) { if ($result->getTransactionId() != $payment->getParentTransactionId()) { $payment->setTransactionId($result->getTransactionId()); } $shouldCloseCaptureTransaction = $payment->getOrder()->canCreditmemo() ? 0 : 1; $payment->setIsTransactionClosed(1)->setShouldCloseParentTransaction($shouldCloseCaptureTransaction)->setTransactionAdditionalInfo($this->_realTransactionIdKey, $result->getTransactionId()); return $this; } Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText())); case self::RESPONSE_CODE_DECLINED: case self::RESPONSE_CODE_ERROR: Mage::throwException($this->_wrapGatewayError($result->getResponseReasonText())); default: Mage::throwException(Mage::helper('paygate')->__('Payment refunding error.')); } }
/** * Refund the payment transaction * * @param Mage_Sale_Model_Order_Payment $payment * @param flaot $amount * @return Mage_Cybersource_Model_Soap */ public function refund(Varien_Object $payment, $amount) { $error = false; if ($payment->getParentTransactionId() && $payment->getRefundCybersourceToken() && $amount > 0) { $soapClient = $this->getSoapApi(); $this->iniRequest(); $ccCreditService = new stdClass(); $ccCreditService->run = "true"; $ccCreditService->captureRequestToken = $payment->getCybersourceToken(); $ccCreditService->captureRequestID = $payment->getParentTransactionId(); $this->_request->ccCreditService = $ccCreditService; $purchaseTotals = new stdClass(); $purchaseTotals->grandTotalAmount = $amount; $this->_request->purchaseTotals = $purchaseTotals; try { $result = $soapClient->runTransaction($this->_request); if ($result->reasonCode == self::RESPONSE_CODE_SUCCESS) { $payment->setTransactionId($result->requestID)->setIsTransactionClosed(1)->setLastCybersourceToken($result->requestToken); } else { $error = Mage::helper('cybersource')->__('There is an error in processing the payment. Please try again or contact us.'); } } catch (Exception $e) { Mage::throwException(Mage::helper('cybersource')->__('Gateway request error: %s', $e->getMessage())); } } else { $error = Mage::helper('cybersource')->__('Error in refunding the payment.'); } if ($error !== false) { Mage::throwException($error); } return $this; }