/**
  * 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)
 {
     $captureRequest = new OffAmazonPaymentsService_Model_CaptureRequest();
     $captureRequest->setSellerId($this->_sellerId);
     $captureRequest->setAmazonAuthorizationId($amazonAuthorizationId);
     $captureRequest->setCaptureReferenceId($amazonAuthorizationId . "-c01");
     $captureRequest->setCaptureAmount(new OffAmazonPaymentsService_Model_Price());
     $captureRequest->getCaptureAmount()->setAmount($captureAmount);
     $captureRequest->getCaptureAmount()->setCurrencyCode($this->_service->getMerchantValues()->getCurrency());
     return $this->_service->capture($captureRequest);
 }
Esempio n. 2
0
	private function capturePayment ($payments, $order) {
		$amazonAuthorizationId = $this->getAmazonAuthorizationId($payments);

		$this->loadAmazonClass('OffAmazonPaymentsService_Model_CaptureRequest');
		$this->loadAmazonClass('OffAmazonPaymentsService_Model_Price');
		$client = $this->getOffAmazonPaymentsService_Client();
		$captureRequest = new OffAmazonPaymentsService_Model_CaptureRequest();
		$captureRequest->setSellerId($this->_currentMethod->sellerId);
		$captureRequest->setAmazonAuthorizationId($amazonAuthorizationId);

		$captureRequest->setCaptureReferenceId($this->_order_number);
		$captureRequest->setCaptureAmount(new OffAmazonPaymentsService_Model_Price());
		$captureRequest->getCaptureAmount()->setAmount($this->getTotalInPaymentCurrency($client, $this->_amount, $order['details']['BT']->order_currency));
		$captureRequest->getCaptureAmount()->setCurrencyCode($this->getCurrencyCode3($client));

		try {
			$captureResponse = $client->capture($captureRequest);
			$amazonCaptureId = $captureResponse->getCaptureResult()->getCaptureDetails()->getAmazonCaptureId();
			$this->debugLog("<pre>" . var_export($captureRequest, true) . "</pre>", __FUNCTION__, 'debug');
			$this->debugLog("<pre>" . var_export($captureResponse, true) . "</pre>", __FUNCTION__, 'debug');

		} catch (Exception $e) {
			$msg = $e->getMessage();
			$log = "An exception was thrown when trying to capture 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');
			$this->amazonError(__FUNCTION__ . ' ' . $msg);
			return false;
		}
		$this->loadHelperClass('amazonHelperCaptureResponse');
		$amazonHelperCaptureResponse = new amazonHelperCaptureResponse($captureResponse, $this->_currentMethod);
		$amazonHelperCaptureResponse->onResponseUpdateOrderHistory($order);
		//$orderModel = VmModel::getModel('orders');

		//$orderModel->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order_history, TRUE);
		$storeInternalData = $amazonHelperCaptureResponse->getStoreInternalData();
		$this->storeAmazonInternalData($order, $captureRequest, $captureResponse, NULL, $this->renderPluginName($this->_currentMethod), $storeInternalData, NULL, $captureAmount);

		return $amazonCaptureId;
	}
 public static function capture(AmzPayments $amz_payments, $service, $auth_id, $amount, $currency_code = 'EUR', $display_error_message = false)
 {
     if ($auth_id) {
         $order_ref = self::getOrderRefFromAmzId($auth_id);
         $capture_request = new OffAmazonPaymentsService_Model_CaptureRequest();
         $capture_request->setAmazonAuthorizationId($auth_id);
         $capture_request->setSellerId($amz_payments->merchant_id);
         $capture_request->setCaptureReferenceId(self::getNextCaptureRef($order_ref));
         $capture_request->setCaptureAmount(new OffAmazonPaymentsService_Model_Price());
         $capture_request->getCaptureAmount()->setAmount($amount);
         $capture_request->getCaptureAmount()->setCurrencyCode($currency_code);
         if ($amz_payments->provocation == 'capture_decline' && $amz_payments->environment == 'SANDBOX') {
             $capture_request->setSellerCaptureNote('{"SandboxSimulation":{"State":"Declined", "ReasonCode":"AmazonRejected"}}');
         }
         try {
             $response = $service->capture($capture_request);
             $details = $response->getCaptureResult()->getCaptureDetails();
             $sql_arr = array('amz_tx_order_reference' => pSQL($order_ref), 'amz_tx_type' => 'capture', 'amz_tx_time' => pSQL(time()), 'amz_tx_expiration' => 0, 'amz_tx_amount' => pSQL($amount), 'amz_tx_status' => pSQL($details->getCaptureStatus()->getState()), 'amz_tx_reference' => pSQL($details->getCaptureReferenceId()), 'amz_tx_amz_id' => pSQL($details->getAmazonCaptureId()), 'amz_tx_last_change' => pSQL(time()), 'amz_tx_last_update' => pSQL(time()));
             Db::getInstance()->insert('amz_transactions', $sql_arr);
             self::setOrderStatusCapturedSuccesfully($order_ref);
         } catch (OffAmazonPaymentsService_Exception $e) {
             if ($display_error_message) {
                 echo 'ERROR: ' . $e->getMessage();
             }
             return false;
         }
         return $response;
     }
 }
 /**
  * Perform the capture for a single shipment
  * 
  * @param int    $shipmentNumber        order item index to capture
  * @param string $amazonAuthorizationId authorization to capture
  * 
  * @return OffAmazonPayments_Model_CaptureResponse service response
  */
 public function performCaptureForShipment($shipmentNumber, $amazonAuthorizationId)
 {
     $item = $this->_orderShipments[$shipmentNumber];
     $captureRequest = new OffAmazonPaymentsService_Model_CaptureRequest();
     $captureRequest->setSellerId($this->_sellerId);
     $captureRequest->setAmazonAuthorizationId($amazonAuthorizationId);
     $captureRequest->setCaptureReferenceId($this->_captureReferenceIdBase . $shipmentNumber);
     $captureRequest->setCaptureAmount(new OffAmazonPaymentsService_Model_Price());
     $captureRequest->getCaptureAmount()->setAmount($item->price);
     $captureRequest->getCaptureAmount()->setCurrencyCode($this->_service->getMerchantValues()->getCurrency());
     return $this->_service->capture($captureRequest);
 }
 /**
  * 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);
 }