/**
  * Perform the refund to transfer the amount from seller
  * to buyer
  * 
  * @param string $refundAmount   amount to refund to the buyer
  * @param string $refundCurrency currency of the refund
  * 
  * @return void
  */
 public function refundToBuyer($refundAmount, $refundCurrency, $providerCreditReversalInfo = null)
 {
     $refund = new OffAmazonPaymentsService_Model_Price();
     $refund->setCurrencyCode($refundCurrency);
     $refund->setAmount($refundAmount);
     $refundRequest = new OffAmazonPaymentsService_Model_RefundRequest();
     $refundRequest->setSellerId($this->_sellerId);
     $refundRequest->setAmazonCaptureId($this->_amazonCaptureId);
     $refundRequest->setRefundReferenceId($this->_refundReferenceId);
     $refundRequest->setRefundAmount($refund);
     if ($providerCreditReversalInfo != null) {
         $refundRequest->setProviderCreditReversalList(new OffAmazonPaymentsService_Model_ProviderCreditReversalList());
         $values = array();
         $providerCreditReversal = new OffAmazonPaymentsService_Model_ProviderCreditReversal();
         $providerCreditReversal->setProviderId($providerCreditReversalInfo[0]);
         $creditReversalAmount = new OffAmazonPaymentsService_Model_Price();
         $creditReversalAmount->setAmount($providerCreditReversalInfo[1]);
         $creditReversalAmount->setCurrencyCode($refundCurrency);
         $providerCreditReversal->setCreditReversalAmount($creditReversalAmount);
         array_push($values, $providerCreditReversal);
         $refundRequest->getProviderCreditReversalList()->setmember($values);
     }
     return $this->_service->refund($refundRequest);
 }
Exemplo n.º 2
0
 public static function refund(AmzPayments $amz_payments, $service, $capture_id, $amount, $currency_code = 'EUR')
 {
     $order_ref = self::getOrderRefFromAmzId($capture_id);
     $refund = new OffAmazonPaymentsService_Model_Price();
     $refund->setCurrencyCode($currency_code);
     $refund->setAmount($amount);
     $refund_request = new OffAmazonPaymentsService_Model_RefundRequest();
     $refund_request->setSellerId($amz_payments->merchant_id);
     $refund_request->setAmazonCaptureId($capture_id);
     $refund_request->setRefundReferenceId(self::getNextRefundRef($order_ref));
     $refund_request->setRefundAmount($refund);
     try {
         $response = $service->refund($refund_request);
         $details = $response->getRefundResult()->getRefundDetails();
         $sql_arr = array('amz_tx_order_reference' => pSQL($order_ref), 'amz_tx_type' => 'refund', 'amz_tx_time' => pSQL(time()), 'amz_tx_expiration' => 0, 'amz_tx_amount' => pSQL($amount), 'amz_tx_status' => pSQL($details->getRefundStatus()->getState()), 'amz_tx_reference' => pSQL($details->getRefundReferenceId()), 'amz_tx_amz_id' => pSQL($details->getAmazonRefundId()), 'amz_tx_last_change' => pSQL(time()), 'amz_tx_last_update' => pSQL(time()));
         Db::getInstance()->insert('amz_transactions', $sql_arr);
     } catch (OffAmazonPaymentsService_Exception $e) {
         echo 'ERROR: ' . $e->getMessage();
     }
     return $response;
 }
Exemplo n.º 3
0
	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;
	}
Exemplo n.º 4
0
 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;
 }