private function refundPayment ($payments, $order) { $amazonCaptureId = $this->getAmazonCaptureId($payments); if (empty($amazonCaptureId)) { vmError(vmText::_('VMPAYMENT_AMAZON_UPDATEPAYMENT_NOAMAZONCAPTUREID')); return false; } $this->loadAmazonClass('OffAmazonPaymentsService_Model_RefundRequest'); $this->loadAmazonClass('OffAmazonPaymentsService_Model_Price'); $client = $this->getOffAmazonPaymentsService_Client(); $refund = new OffAmazonPaymentsService_Model_Price(); $refund->setCurrencyCode($this->getCurrencyCode3($client)); $refund->setAmount($this->getTotalInPaymentCurrency($client, $this->_amount, $order['details']['BT']->order_currency)); $refundRequest = new OffAmazonPaymentsService_Model_RefundRequest(); $refundRequest->setSellerId($this->_currentMethod->sellerId); $refundRequest->setAmazonCaptureId($amazonCaptureId); $refundRequest->setRefundReferenceId($this->getUniqueReferenceId($order['details']['BT']->order_number)); // random string $refundRequest->setRefundAmount($refund); try { $refundResponse = $client->refund($refundRequest); $amazonRefundId = $refundResponse->getRefundResult()->getRefundDetails()->getAmazonRefundId(); $this->debugLog("<pre>" . var_export($refundRequest, true) . "</pre>", __FUNCTION__, 'debug'); $this->debugLog("<pre>" . var_export($refundResponse, true) . "</pre>", __FUNCTION__, 'debug'); } catch (Exception $e) { $msg = $e->getMessage(); $log = "An exception was thrown when trying to refund payment:" . $e->getMessage() . "\n" . $e->getTraceAsString(); while ($e = $e->getPrevious()) { $log .= ("Caused by: " . $e->getMessage() . "\n" . $e->getTraceAsString() . ""); $msg .= "Reason: " . $e->getMessage() . "<br />"; $log .= "\n"; } $this->debugLog($log, __FUNCTION__, 'debug'); vmError(__FUNCTION__ . ' ' . $msg); return false; } $this->loadHelperClass('amazonHelperRefundResponse'); $amazonHelperRefundResponse = new amazonHelperRefundResponse($refundResponse, $this->_currentMethod); $storeInternalData = $amazonHelperRefundResponse->getStoreInternalData(); $this->storeAmazonInternalData($order, $refundRequest, $refundResponse, NULL, $this->renderPluginName($this->_currentMethod), $storeInternalData, NULL, $amount); return $amazonRefundId; }
private function refundPayment($payments, $order) { $amazonCaptureId = $this->getAmazonCaptureId($payments); if (empty($amazonCaptureId)) { vmError(vmText::_('VMPAYMENT_AMAZON_UPDATEPAYMENT_NOAMAZONCAPTUREID')); return false; } $this->loadAmazonClass('OffAmazonPaymentsService_Model_RefundRequest'); $this->loadAmazonClass('OffAmazonPaymentsService_Model_Price'); $client = $this->getOffAmazonPaymentsService_Client(); if ($client == NULL) { return; } $refund = new OffAmazonPaymentsService_Model_Price(); $refund->setCurrencyCode($this->getCurrencyCode3($client)); $refund->setAmount($this->_amount); $refundRequest = new OffAmazonPaymentsService_Model_RefundRequest(); $refundRequest->setSellerId($this->_currentMethod->sellerId); $refundRequest->setAmazonCaptureId($amazonCaptureId); $refundRequest->setRefundReferenceId($this->getUniqueReferenceId($order['details']['BT']->order_number)); // random string $refundRequest->setSellerRefundNote($this->getSellerRefundNote()); $refundRequest->setRefundAmount($refund); try { $refundResponse = $client->refund($refundRequest); $amazonRefundId = $refundResponse->getRefundResult()->getRefundDetails()->getAmazonRefundId(); $this->debugLog("<pre>" . var_export($refundRequest, true) . "</pre>", __FUNCTION__, 'debug'); $this->debugLog("<pre>" . var_export($refundResponse, true) . "</pre>", __FUNCTION__, 'debug'); } catch (Exception $e) { $msg = $e->getMessage(); $log = "An exception was thrown when trying to refund payment:" . $e->getMessage() . "\n" . $e->getTraceAsString(); if ($this->_currentMethod->debug) { while ($e = $e->getPrevious()) { $log .= "Caused by: " . $e->getMessage() . "\n" . $e->getTraceAsString() . ""; $msg .= "Reason: " . $e->getMessage() . "<br />"; $log .= "\n"; } $this->debugLog($log, __FUNCTION__, 'debug'); } vmError(__FUNCTION__ . ' ' . $msg); return false; } $this->loadHelperClass('amazonHelperRefundResponse'); $amazonHelperRefundResponse = new amazonHelperRefundResponse($refundResponse, $this->_currentMethod); $storeInternalData = $amazonHelperRefundResponse->getStoreInternalData(); $this->storeAmazonInternalData($order, $refundRequest, $refundResponse, NULL, $this->renderPluginName($this->_currentMethod), $storeInternalData, NULL, $refund); // refund will issue a notification in all cases. The notification will inform if the refund operation has been accepted or not. // so the order status is updated but the customer is not notified. // He will be notified when the notification arrives vRequest::setVar('customer_notified', 0); $orders = vRequest::getVar('orders'); $virtuemart_order_id = $payments[0]->virtuemart_order_id; if (isset($orders[$virtuemart_order_id]) and isset($orders[$virtuemart_order_id]['customer_notified'])) { vRequest::setVar($orders[$virtuemart_order_id]['customer_notified'], 0); } return true; }