/**
  * Perform the reverseProviderCredit to transfer the amount from provider
  * to merchant
  *
  * @param string $reverseProviderCreditAmount
  *        	amount to reverseProviderCredit to the merchant
  * @param string $reverseProviderCreditCurrency
  *        	currency of the reverseProviderCredit
  *        	
  * @return void
  */
 public function reverseToMerchant($amazonProviderCreditId, $reverseAmount, $creditReversalReferenceId)
 {
     $reversePrice = new OffAmazonPaymentsService_Model_Price();
     $reversePrice->setCurrencyCode($this->_service->getMerchantValues()->getCurrency());
     $reversePrice->setAmount($reverseAmount);
     $reverseProviderCreditRequest = new OffAmazonPaymentsService_Model_ReverseProviderCreditRequest();
     $reverseProviderCreditRequest->setSellerId($this->_sellerId);
     $reverseProviderCreditRequest->setAmazonProviderCreditId($amazonProviderCreditId);
     $reverseProviderCreditRequest->setCreditReversalReferenceId($creditReversalReferenceId);
     $reverseProviderCreditRequest->setCreditReversalAmount($reversePrice);
     return $this->_service->reverseProviderCredit($reverseProviderCreditRequest);
 }
 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;
 }
 /**
  * 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);
 }
Example #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();
		$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;
	}
 /**
  * Perform the authorize call for the order
  * 
  * Cancel order reference can now be called at any point between a
  * ConfirmOrderReference call and a cancelOrderReference call
  * In this example we will call it following a single authorization for
  * half of the order total
  *
  * @return OffAmazonPaymentsService_Model_AuthorizeResponse service response
  */
 public function performAuthorization()
 {
     $authorizationAmountPrice = new OffAmazonPaymentsService_Model_Price();
     $authorizationAmountPrice->setCurrencyCode($this->_currencyCode);
     $authorizationAmountPrice->setAmount($this->_orderTotalAmount);
     $authorizeRequest = new OffAmazonPaymentsService_Model_AuthorizeRequest();
     $authorizeRequest->setAmazonOrderReferenceId($this->_amazonOrderReferenceId);
     $authorizeRequest->setSellerId($this->_sellerId);
     $authorizeRequest->setAuthorizationReferenceId($this->_authorizationReferenceId);
     $authorizeRequest->setAuthorizationAmount($authorizationAmountPrice);
     return $this->_service->authorize($authorizeRequest);
 }
 /**
  * Perform the capture call for the order
  *
  * @param float  $captureAmount         amount to capture from the buyer
  * @param string $amazonAuthorizationId auth id to perform the capture on
  *
  * @return OffAmazonPaymentsService_Model_CaptureResponse service response
  */
 public function captureOrderAmount($captureAmount, $amazonAuthorizationId, $providerCreditInfo = null)
 {
     $captureRequest = new OffAmazonPaymentsService_Model_CaptureRequest();
     $captureRequest->setSellerId($this->_sellerId);
     $captureRequest->setAmazonAuthorizationId($amazonAuthorizationId);
     $captureRequest->setCaptureReferenceId($this->_captureReferenceId);
     $captureRequest->setCaptureAmount(new OffAmazonPaymentsService_Model_Price());
     $captureRequest->getCaptureAmount()->setAmount($captureAmount);
     $captureRequest->getCaptureAmount()->setCurrencyCode($this->_service->getMerchantValues()->getCurrency());
     if ($providerCreditInfo != null) {
         $captureRequest->setProviderCreditList(new OffAmazonPaymentsService_Model_ProviderCreditList());
         $values = array();
         $providerCredit = new OffAmazonPaymentsService_Model_ProviderCredit();
         $providerCredit->setProviderId($providerCreditInfo[0]);
         $creditAmount = new OffAmazonPaymentsService_Model_Price();
         $creditAmount->setAmount($providerCreditInfo[1]);
         $creditAmount->setCurrencyCode($this->_service->getMerchantValues()->getCurrency());
         $providerCredit->setCreditAmount($creditAmount);
         array_push($values, $providerCredit);
         $captureRequest->getProviderCreditList()->setmember($values);
     }
     return $this->_service->capture($captureRequest);
 }
Example #7
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;
 }