diff --git a/extension/app/code/community/Affirm/Affirm/Model/Payment.php b/extension/app/code/community/Affirm/Affirm/Model/Payment.php
index bfc1ae8..9a7387e 100644
--- a/extension/app/code/community/Affirm/Affirm/Model/Payment.php
+++ b/extension/app/code/community/Affirm/Affirm/Model/Payment.php
@@ -7,6 +7,10 @@ class Affirm_Affirm_Model_Payment extends Mage_Payment_Model_Method_Abstract
// TODO(brian): extract this along with API client
const API_CHARGES_PATH = '/api/v2/charges/';
+ const CHECKOUT_XHR_AUTO = 'auto';
+ const CHECKOUT_XHR = 'xhr';
+ const CHECKOUT_REDIRECT = 'redirect';
+
/**
* Form block type
*/
@@ -424,6 +428,17 @@ private static function _getMetadata()
"version" => Mage::getConfig()->getModuleConfig('Affirm_Affirm')->version
)
);
+
+ if (Mage::app()->getStore()->isAdmin()) {
+ //this is in the admin area..
+ $meta["source"]["merchant_user_initiated"] = 1;
+ $user = Mage::getSingleton('admin/session')->getUser();
+ if ($user) {
+ $meta["source"]["data"]["merchant_logged_in"] = 1;
+ $meta["source"]["data"]["merchant_username"] = $user->getUsername();
+ }
+ }
+
if ($session->isLoggedIn()) {
$customerId = $session->getCustomerId();
diff --git a/extension/app/code/community/Affirm/Affirm/Model/Source/PaymentCheckoutXhr.php b/extension/app/code/community/Affirm/Affirm/Model/Source/PaymentCheckoutXhr.php
new file mode 100644
index 0000000..a4cba29
--- /dev/null
+++ b/extension/app/code/community/Affirm/Affirm/Model/Source/PaymentCheckoutXhr.php
@@ -0,0 +1,21 @@
+ Affirm_Affirm_Model_Payment::CHECKOUT_XHR_AUTO,
+ 'label' => Mage::helper('affirm')->__('Auto Detect')
+ ),
+ array(
+ 'value' => Affirm_Affirm_Model_Payment::CHECKOUT_XHR,
+ 'label' => Mage::helper('affirm')->__('Checkout uses xhr')
+ ),
+ array(
+ 'value' => Affirm_Affirm_Model_Payment::CHECKOUT_REDIRECT,
+ 'label' => Mage::helper('affirm')->__('Checkout uses redirect')
+ )
+ );
+ }
+}
diff --git a/extension/app/code/community/Affirm/Affirm/controllers/PaymentController.php b/extension/app/code/community/Affirm/Affirm/controllers/PaymentController.php
index c4ef71c..0acacbe 100644
--- a/extension/app/code/community/Affirm/Affirm/controllers/PaymentController.php
+++ b/extension/app/code/community/Affirm/Affirm/controllers/PaymentController.php
@@ -32,6 +32,25 @@ public function redirectAction()
$session->unsRedirectUrl();
}
+ private function isXhrRequest($proxy_request)
+ {
+ $detected_xhr = isset($proxy_request["xhr"]) && $proxy_request["xhr"];
+ $config_xhr = Mage::getStoreConfig("payment/affirm/detect_xhr_checkout");
+
+ if ($config_xhr == Affirm_Affirm_Model_Payment::CHECKOUT_REDIRECT)
+ {
+ return false;
+ }
+ elseif ($config_xhr == Affirm_Affirm_Model_Payment::CHECKOUT_XHR)
+ {
+ return true;
+ }
+ else
+ {
+ return $detected_xhr;
+ }
+ }
+
public function renderPreOrderAction()
{
$order = $this->getRequest()->getParam("order");
@@ -39,10 +58,10 @@ public function renderPreOrderAction()
$serialized_request = Mage::getSingleton('checkout/session')->getAffirmOrderRequest();
$proxy_request = unserialize($serialized_request);
- if (isset($proxy_request["xhr"]) && $proxy_request["xhr"])
+ if ($this->isXhrRequest($proxy_request))
{
$this->_getCheckoutSession()->setPreOrderRender($string);
- $result = array("redirect"=>Mage::getUrl('*/*/redirectPreOrder'));
+ $result = array("redirect"=>Mage::getUrl('affirm/payment/redirectPreOrder'));
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
else
@@ -83,8 +102,7 @@ public function confirmAction()
Mage::register("affirm_token_code", $checkout_token);
$this->_forward($proxy_request["action"], $proxy_request["controller"], $proxy_request["module"], $proxy_request["params"]);
-
- if ((isset($proxy_request["xhr"]) && $proxy_request["xhr"]))
+ if ($this->isXhrRequest($proxy_request))
{
#need to actually execute the forward!
$front = Mage::app()->getFrontController();
@@ -95,6 +113,15 @@ public function confirmAction()
}
}
+ //
+ //It's already redirecting... so let it do so
+ //This should never happen, but if it does we should probably let it go through
+ //
+ if ($this->getResponse()->getHttpResponseCode() == 302)
+ {
+ return;
+ }
+
try {
$orderResult = Mage::helper('core')->jsonDecode($this->getResponse()->getBody());
} catch (Exception $e) {
diff --git a/extension/app/code/community/Affirm/Affirm/etc/system.xml b/extension/app/code/community/Affirm/Affirm/etc/system.xml
index b3e9fd3..cdef474 100644
--- a/extension/app/code/community/Affirm/Affirm/etc/system.xml
+++ b/extension/app/code/community/Affirm/Affirm/etc/system.xml
@@ -100,6 +100,15 @@
1
210
+
+
+ select
+ affirm/source_paymentCheckoutXhr
+ 220
+ 1
+ 1
+ 0
+