public function execute()
 {
     $output = $this->getResult();
     $recurring = $this->getParameter('recurring');
     $token = $this->getParameter('wmf_token');
     $adapterParams = array('api_request' => true, 'external_data' => array('amount' => $this->getParameter('amount'), 'currency_code' => $this->getParameter('currency_code'), 'recurring' => $recurring, 'wmf_token' => $token));
     $adapter = new AmazonAdapter($adapterParams);
     if ($adapter->getAllErrors()) {
         $output->addValue(null, 'errors', $adapter->getAllErrors());
     } else {
         if ($token && $adapter->checkTokens()) {
             if ($recurring) {
                 $adapter->addRequestData(array('subscr_id' => $this->getParameter('billingAgreementId')));
             } else {
                 $adapter->addRequestData(array('order_reference_id' => $this->getParameter('orderReferenceId')));
             }
             $result = $adapter->doPayment();
             if ($result->isFailed()) {
                 $output->addvalue(null, 'redirect', ResultPages::getFailPage($adapter));
             } else {
                 if ($result->getRefresh()) {
                     $output->addValue(null, 'errors', $result->getErrors());
                 } else {
                     $output->addValue(null, 'redirect', ResultPages::getThankYouPage($adapter));
                 }
             }
         } else {
             // Don't let people continue if they failed a token check!
             $output->addValue(null, 'errors', array('token-mismatch' => $this->msg('donate_interface-cc-token-expired')->text()));
         }
     }
 }
 /**
  * Display a failure page
  *
  * @param bool $allowRapid Whether to allow rendering a RapidFail form
  *  renderForm sets this to false on failure to avoid an infinite loop
  */
 public function displayFailPage($allowRapid = true)
 {
     $output = $this->getOutput();
     if ($this->adapter && $allowRapid) {
         $page = ResultPages::getFailPage($this->adapter);
         if (!filter_var($page, FILTER_VALIDATE_URL)) {
             // If it's not a URL, we're rendering a RapidFail form
             $this->logger->info("Displaying fail form {$page}");
             $this->adapter->addRequestData(array('ffname' => $page));
             $this->displayForm();
             return;
         }
     } else {
         $gatewayName = $this->getGatewayIdentifier();
         $className = DonationInterface::getAdapterClassForGateway($gatewayName);
         $page = ResultPages::getFailPageForType($className, $this->getLogPrefix());
     }
     $log_message = "Redirecting to [{$page}]";
     $this->logger->info($log_message);
     $output->redirect($page);
 }
 public function testGetFallbackFailPage()
 {
     $this->setMwGlobals(array('wgDonationInterfaceRapidFail' => false, 'wgDonationInterfaceFailPage' => 'Main_Page'));
     $options = $this->getDonorTestData('US');
     $gateway = $this->getFreshGatewayObject($options);
     $page = ResultPages::getFailPage($gateway);
     $expectedTitle = Title::newFromText('Main_Page');
     $expectedURL = wfAppendQuery($expectedTitle->getFullURL(), 'uselang=en');
     $this->assertEquals($expectedURL, $page);
 }