public static function authorize(AmzPayments $amz_payments, $service, $order_ref, $amount, $currency_code = 'EUR', $timeout = 1440, $comment = '') { if ($currency_code == '0') { $currency_code = 'EUR'; } $authorize_request = new OffAmazonPaymentsService_Model_AuthorizeRequest(); $authorize_request->setAmazonOrderReferenceId($order_ref); $authorize_request->setSellerId($amz_payments->merchant_id); $authorize_request->setTransactionTimeout($timeout); $authorize_request->setSoftDescriptor($comment); if ($amz_payments->capture_mode == 'after_auth') { $authorize_request->setCaptureNow(true); } if ($amz_payments->provocation == 'hard_decline' && $amz_payments->environment == 'SANDBOX') { $authorize_request->setSellerAuthorizationNote('{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}'); } if ($amz_payments->provocation == 'soft_decline' && $amz_payments->environment == 'SANDBOX') { Context::getContext()->cookie->setHadErrorNowWallet = 1; $authorize_request->setSellerAuthorizationNote('{"SandboxSimulation": {"State":"Declined", "ReasonCode":"InvalidPaymentMethod", "PaymentMethodUpdateTimeInMins":2}}'); } $authorize_request->setAuthorizationReferenceId(self::getNextAuthRef($order_ref)); $authorize_request->setAuthorizationAmount(new OffAmazonPaymentsService_Model_Price()); $authorize_request->getAuthorizationAmount()->setAmount($amount); $authorize_request->getAuthorizationAmount()->setCurrencyCode($currency_code); try { $response = $service->authorize($authorize_request); $details = $response->getAuthorizeResult()->getAuthorizationDetails(); $sql_arr = array('amz_tx_order_reference' => pSQL($order_ref), 'amz_tx_type' => 'auth', 'amz_tx_time' => pSQL(time()), 'amz_tx_expiration' => pSQL(strtotime($details->getExpirationTimestamp())), 'amz_tx_amount' => pSQL($amount), 'amz_tx_status' => pSQL($details->getAuthorizationStatus()->getState()), 'amz_tx_reference' => pSQL($details->getAuthorizationReferenceId()), 'amz_tx_amz_id' => pSQL($details->getAmazonAuthorizationId()), '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; }
/** * @param $client * @param $cart * @param $order */ private function getAuthorization ($client, $cart, $order, $redirect = true) { $shouldRetry = false; $retries = 0; $this->loadAmazonClass('OffAmazonPaymentsService_Model_AuthorizeRequest'); $this->loadAmazonClass('OffAmazonPaymentsService_Model_Price'); $this->loadHelperClass('amazonHelperAuthorizeResponse'); do { $authorizeRequest = new OffAmazonPaymentsService_Model_AuthorizeRequest(); $authorizeRequest->setAmazonOrderReferenceId($this->_amazonOrderReferenceId); $authorizeRequest->setSellerId($this->_currentMethod->sellerId); $authorizeRequest->setAuthorizationReferenceId($this->_order_number); $authorizeRequest->setSellerAuthorizationNote($this->getSellerAuthorizationNote()); $authorizeRequest->setTransactionTimeout($this->getAuthorizationTransactionTimeout()); // directly do the capture without the need to call the Capture Request if ($this->isCaptureImmediate($cart)) { $authorizeRequest->setCaptureNow(true); } else { $authorizeRequest->setCaptureNow(false); } $authorizeRequest->setAuthorizationAmount(new OffAmazonPaymentsService_Model_Price()); $authorizeRequest->getAuthorizationAmount()->setAmount($this->getTotalInPaymentCurrency($client, $this->_amount, $this->getCurrencyId($client))); $authorizeRequest->getAuthorizationAmount()->setCurrencyCode($this->getCurrencyCode3($client)); try { $authorizeResponse = $client->authorize($authorizeRequest); $amazonAuthorizationId = $authorizeResponse->getAuthorizeResult()->getAuthorizationDetails()->getAmazonAuthorizationId(); //$this->debugLog("ERREUR<pre>" . var_export($authorizeRequest, true) . "</pre>", __FUNCTION__, 'debug'); //$this->debugLog("ERREUR<pre>" . var_export($authorizeResponse, true) . "</pre>", __FUNCTION__, 'debug'); } catch (Exception $e) { $msg = "An exception was thrown when trying to do the authorization:" . $e->getMessage() . "\n" . $e->getTraceAsString(); while ($e = $e->getPrevious()) { $msg .= ("Caused by: " . $e->getMessage() . "\n" . $e->getTraceAsString() . ""); $msg .= "\n"; } if ($redirect) { $cart->setOutOfCheckout(); $this->debugLog($msg, __FUNCTION__ . " Exception", 'error'); $this->amazonError(__FUNCTION__ . ' ' . $msg); $this->redirectToCart(vmText::_('VMPAYMENT_AMAZON_SELECT_ANOTHER_PAYMENT'), true); } return false; } if ($authorizationDetails =$this->getAuthorizeDetailsFromAuthorizeResponse($authorizeResponse)) { $this->updateAuthorizeBillingAddressInOrder($authorizationDetails, $order); } $amazonHelperAuthorizeResponse = new amazonHelperAuthorizeResponse($authorizeResponse, $this->_currentMethod); $amazonState = $amazonHelperAuthorizeResponse->onResponseUpdateOrderHistory($order); $storeInternalData = $amazonHelperAuthorizeResponse->getStoreInternalData(); $this->storeAmazonInternalData($order, $authorizeRequest, $authorizeResponse, NULL, $this->renderPluginName($this->_currentMethod), $storeInternalData); $reasonCode = $authorizeResponse->getAuthorizeResult()->getAuthorizationDetails()->getAuthorizationStatus()->getReasonCode(); if ($redirect) { if ($amazonState == 'Declined' && $reasonCode == 'InvalidPaymentMethod' && $this->_currentMethod->soft_decline) { $this->incrementRetryInvalidPaymentMethodInSession(); return false; } elseif (($amazonState == 'Open' && $reasonCode == 'AmazonRejected') or ($amazonState == 'Declined' && $reasonCode == 'TransactionTimedOut')) { if ($retries < 2) { $shouldRetry = true; $retries++; } else { $cart->setOutOfCheckout(); $this->leaveAmazonCheckout(); $this->redirectToCart(vmText::_('VMPAYMENT_AMAZON_SELECT_ANOTHER_PAYMENT'), true); } } elseif ($amazonState == 'Declined') { $cart->setOutOfCheckout(); $this->leaveAmazonCheckout(); $this->redirectToCart(vmText::_('VMPAYMENT_AMAZON_SELECT_ANOTHER_PAYMENT'), true); } } } while ($shouldRetry and $redirect); return $amazonAuthorizationId; }
/** * Perform the authorization for the shipment at the given index * * @param int $shipmentNumber order item index to authorize * * @return OffAmazonPaymentsService_Model_AuthorizeResponse service response */ public function performAuthorizationForShipment($shipmentNumber) { $item = $this->_orderShipments[$shipmentNumber]; $authorizeRequest = new OffAmazonPaymentsService_Model_AuthorizeRequest(); $authorizeRequest->setAmazonOrderReferenceId($this->_amazonOrderReferenceId); $authorizeRequest->setSellerId($this->_sellerId); $authorizeRequest->setAuthorizationReferenceId($this->_authorizationReferenceIdBase . $shipmentNumber); $authorizeRequest->setAuthorizationAmount(new OffAmazonPaymentsService_Model_Price()); $authorizeRequest->getAuthorizationAmount()->setAmount($item->price); $authorizeRequest->getAuthorizationAmount()->setCurrencyCode($this->_service->getMerchantValues()->getCurrency()); // Set the application timeout so that the polling request will // get a definitive response within this period of time $authorizeRequest->setTransactionTimeout(5); return $this->_service->authorize($authorizeRequest); }
/** * 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 authorize call for the order * * @param float $authorizationAmount amount to authorize from the buyer * * @return OffAmazonPaymentsService_Model_AuthorizeResponse service response */ public function authorizeOrderAmount($authorizationAmount, $authOption = 1) { $authorizeRequest = new OffAmazonPaymentsService_Model_AuthorizeRequest(); $authorizeRequest->setAmazonOrderReferenceId($this->_amazonOrderReferenceId); $authorizeRequest->setSellerId($this->_sellerId); $authorizeRequest->setAuthorizationReferenceId($this->_authorizationReferenceId); $authorizeRequest->setAuthorizationAmount(new OffAmazonPaymentsService_Model_Price()); $authorizeRequest->getAuthorizationAmount()->setAmount($authorizationAmount); $authorizeRequest->getAuthorizationAmount()->setCurrencyCode($this->_service->getMerchantValues()->getCurrency()); if ($authOption == 2) { //To use fast authorization, set the Transaction Timeout (optional parameteter) to 0. $authorizeRequest->setTransactionTimeout(0); } return $this->_service->authorize($authorizeRequest); }