function defineTransactions()
 {
     $this->transactions = array();
     $this->transactions['Donate'] = array('request' => array('amount', 'currency_code', 'country', 'business', 'cancel_return', 'cmd', 'item_name', 'item_number', 'no_note', 'return', 'custom', 'lc'), 'values' => array('business' => $this->account_config['AccountEmail'], 'cancel_return' => ResultPages::getCancelPage($this), 'cmd' => '_donations', 'item_number' => 'DONATE', 'item_name' => WmfFramework::formatMessage('donate_interface-donation-description'), 'no_note' => 0, 'return' => ResultPages::getThankYouPage($this)));
     $this->transactions['DonateXclick'] = array('request' => array('cmd', 'item_number', 'item_name', 'cancel_return', 'no_note', 'return', 'business', 'no_shipping', 'amount', 'currency_code', 'country', 'custom'), 'values' => array('item_number' => 'DONATE', 'item_name' => WmfFramework::formatMessage('donate_interface-donation-description'), 'cancel_return' => ResultPages::getCancelPage($this), 'no_note' => '1', 'return' => ResultPages::getThankYouPage($this), 'business' => $this->account_config['AccountEmail'], 'cmd' => '_xclick', 'no_shipping' => '1'));
     $this->transactions['DonateRecurring'] = array('request' => array('a3', 'currency_code', 'country', 'business', 'cancel_return', 'cmd', 'item_name', 'item_number', 'no_note', 'return', 'custom', 't3', 'p3', 'src', 'srt', 'lc'), 'values' => array('business' => $this->account_config['AccountEmail'], 'cancel_return' => ResultPages::getCancelPage($this), 'cmd' => '_xclick-subscriptions', 'item_number' => 'DONATE', 'item_name' => WmfFramework::formatMessage('donate_interface-donation-description'), 'no_note' => 0, 'return' => ResultPages::getThankYouPage($this), 't3' => 'M', 'p3' => '1', 'src' => '1', 'srt' => $this->getGlobal('RecurringLength')));
 }
 public function stage(GatewayType $adapter, $normalized, &$stagedData)
 {
     if ($adapter->isBatchProcessor()) {
         // Only makes sense for real users.
         return;
     }
     if (!empty($normalized['returnto'])) {
         $returnto = $normalized['returnto'];
     } else {
         $returnto = '';
     }
     if (isset($normalized['payment_method']) && $normalized['payment_method'] === 'cc') {
         // Add order ID to the returnto URL, only if it's not already there.
         //TODO: This needs to be more robust (like actually pulling the
         //qstring keys, resetting the values, and putting it all back)
         //but for now it'll keep us alive.
         if ($adapter->getOrderIDMeta('generate') && !empty($returnto) && !strpos($returnto, 'order_id')) {
             $queryArray = array('order_id' => $normalized['order_id']);
             $stagedData['returnto'] = wfAppendQuery($returnto, $queryArray);
         }
     } else {
         // FIXME: An empty returnto should be handled by the result switcher instead.
         $stagedData['returnto'] = ResultPages::getThankYouPage($adapter);
     }
 }
 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()));
         }
     }
 }
 /**
  * @param string $logReason Logged explanation for redirect
  */
 protected function displayThankYouPage($logReason)
 {
     $thankYouPage = ResultPages::getThankYouPage($this->adapter);
     $this->logger->info("Displaying thank you page {$thankYouPage} for status {$logReason}.");
     $this->getOutput()->redirect($thankYouPage);
 }
 function defineTransactions()
 {
     $this->transactions = array();
     // https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/
     $this->transactions['SetExpressCheckout'] = array('request' => array('USER', 'PWD', 'VERSION', 'METHOD', 'RETURNURL', 'CANCELURL', 'REQCONFIRMSHIPPING', 'NOSHIPPING', 'LOCALECODE', 'EMAIL', 'L_PAYMENTREQUEST_0_AMT0', 'L_PAYMENTREQUEST_0_DESC0', 'PAYMENTREQUEST_0_AMT', 'PAYMENTREQUEST_0_CURRENCYCODE', 'PAYMENTREQUEST_0_CUSTOM', 'PAYMENTREQUEST_0_DESC', 'PAYMENTREQUEST_0_INVNUM', 'PAYMENTREQUEST_0_ITEMAMT', 'PAYMENTREQUEST_0_PAYMENTACTION', 'PAYMENTREQUEST_0_PAYMENTREASON'), 'values' => array('USER' => $this->account_config['User'], 'PWD' => $this->account_config['Password'], 'VERSION' => self::API_VERSION, 'METHOD' => 'SetExpressCheckout', 'CANCELURL' => ResultPages::getCancelPage($this), 'REQCONFIRMSHIPPING' => 0, 'NOSHIPPING' => 1, 'L_PAYMENTREQUEST_0_DESC0' => WmfFramework::formatMessage('donate_interface-donation-description'), 'PAYMENTREQUEST_0_DESC' => WmfFramework::formatMessage('donate_interface-donation-description'), 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'PAYMENTREQUEST_0_PAYMENTREASON' => 'None'), 'response' => array('TOKEN'));
     // https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/
     $this->transactions['SetExpressCheckout_recurring'] = array('request' => array('USER', 'PWD', 'VERSION', 'METHOD', 'RETURNURL', 'CANCELURL', 'REQCONFIRMSHIPPING', 'NOSHIPPING', 'LOCALECODE', 'EMAIL', 'L_BILLINGTYPE0', 'L_BILLINGAGREEMENTDESCRIPTION0', 'L_BILLINGAGREEMENTCUSTOM0', 'L_PAYMENTREQUEST_0_AMT0', 'L_PAYMENTREQUEST_0_NAME0', 'L_PAYMENTREQUEST_0_QTY0', 'MAXAMT', 'PAYMENTREQUEST_0_AMT', 'PAYMENTREQUEST_0_CURRENCYCODE', 'PAYMENTREQUEST_0_ITEMAMT'), 'values' => array('USER' => $this->account_config['User'], 'PWD' => $this->account_config['Password'], 'VERSION' => self::API_VERSION, 'METHOD' => 'SetExpressCheckout', 'CANCELURL' => ResultPages::getCancelPage($this), 'REQCONFIRMSHIPPING' => 0, 'NOSHIPPING' => 1, 'L_BILLINGTYPE0' => 'RecurringPayments', 'L_BILLINGAGREEMENTDESCRIPTION0' => WmfFramework::formatMessage('donate_interface-monthly-donation-description'), 'L_PAYMENTREQUEST_0_DESC0' => WmfFramework::formatMessage('donate_interface-monthly-donation-description'), 'L_PAYMENTREQUEST_0_NAME0' => WmfFramework::formatMessage('donate_interface-monthly-donation-description'), 'L_PAYMENTREQUEST_0_QTY0' => 1, 'PAYMENTREQUEST_0_DESC' => WmfFramework::formatMessage('donate_interface-monthly-donation-description'), 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'PAYMENTREQUEST_0_PAYMENTREASON' => 'None'), 'response' => array('TOKEN'));
     // Incoming parameters after returning from the PayPal workflow
     $this->transactions['ProcessReturn'] = array('request' => array('token', 'PayerID'));
     // https://developer.paypal.com/docs/classic/api/merchant/GetExpressCheckoutDetails_API_Operation_NVP/
     $this->transactions['GetExpressCheckoutDetails'] = array('request' => array('USER', 'PWD', 'VERSION', 'METHOD', 'TOKEN'), 'values' => array('USER' => $this->account_config['User'], 'PWD' => $this->account_config['Password'], 'VERSION' => self::API_VERSION, 'METHOD' => 'GetExpressCheckoutDetails'), 'response' => array('ACK', 'TOKEN', 'CORRELATIONID', 'TIMESTAMP', 'CUSTOM', 'INVNUM', 'BILLINGAGREEMENTACCEPTEDSTATUS', 'REDIRECTREQUIRED', 'CHECKOUTSTATUS', 'EMAIL', 'PAYERID', 'COUNTRYCODE', 'FIRSTNAME', 'MIDDLENAME', 'LASTNAME', 'SUFFIX', 'PAYMENTREQUEST_0_AMT', 'PAYMENTREQUEST_0_CURRENCYCODE', 'PAYMENTREQUEST_0_INVNUM', 'PAYMENTREQUEST_0_TRANSACTIONID'));
     // https://developer.paypal.com/docs/classic/api/merchant/DoExpressCheckoutPayment_API_Operation_NVP/
     $this->transactions['DoExpressCheckoutPayment'] = array('request' => array('USER', 'PWD', 'VERSION', 'METHOD', 'TOKEN', 'PAYERID', 'PAYMENTREQUEST_0_PAYMENTACTION', 'PAYMENTREQUEST_0_AMT', 'PAYMENTREQUEST_0_CURRENCYCODE', 'PAYMENTREQUEST_0_CUSTOM', 'PAYMENTREQUEST_0_DESC', 'PAYMENTREQUEST_0_INVNUM', 'PAYMENTREQUEST_0_ITEMAMT', 'PAYMENTREQUEST_0_PAYMENTACTION', 'PAYMENTREQUEST_0_PAYMENTREASON'), 'values' => array('USER' => $this->account_config['User'], 'PWD' => $this->account_config['Password'], 'VERSION' => self::API_VERSION, 'METHOD' => 'DoExpressCheckoutPayment', 'PAYMENTREQUEST_0_DESC' => WmfFramework::formatMessage('donate_interface-donation-description'), 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'PAYMENTREQUEST_0_PAYMENTREASON' => 'None'));
     // https://developer.paypal.com/docs/classic/api/merchant/CreateRecurringPaymentsProfile_API_Operation_NVP/
     $this->transactions['CreateRecurringPaymentsProfile'] = array('request' => array('USER', 'PWD', 'VERSION', 'METHOD', 'TOKEN', 'DESC', 'PROFILESTARTDATE', 'PROFILEREFERENCE', 'AUTOBILLOUTAMT', 'BILLINGPERIOD', 'BILLINGFREQUENCY', 'TOTALBILLINGCYCLES', 'MAXFAILEDPAYMENTS', 'AMT', 'CURRENCYCODE', 'EMAIL'), 'values' => array('USER' => $this->account_config['User'], 'PWD' => $this->account_config['Password'], 'VERSION' => self::API_VERSION, 'METHOD' => 'CreateRecurringPaymentsProfile', 'DESC' => WmfFramework::formatMessage('donate_interface-monthly-donation-description'), 'AUTOBILLOUTAMT' => 'NoAutoBill', 'BILLINGPERIOD' => 'Month', 'BILLINGFREQUENCY' => 1, 'TOTALBILLINGCYCLES' => 0, 'MAXFAILEDPAYMENTS' => 3), 'response' => array('PROFILEID', 'PROFILESTATUS', 'TRANSACTIONID'));
     // Add the Signature field to all API calls, if necessary.
     // Note that this gives crappy security, vulnerable to replay attacks.
     // The signature is static, not a checksum of the request.
     if (!$this->isCertificateAuthentication()) {
         foreach ($this->transactions as $_name => &$info) {
             if (isset($info['request'])) {
                 $info['request'][] = 'SIGNATURE';
                 $info['values']['SIGNATURE'] = $this->account_config['Signature'];
             }
         }
     }
 }
 /**
  * Show the special page
  */
 protected function handleRequest()
 {
     $req = $this->getRequest();
     // TODO: Don't do that.
     $fake = $req->getBool('fake');
     $fail = $req->getBool('fail');
     if ($fake) {
         if ($fail) {
             $this->displayFailPage();
             return;
         } else {
             $go = ResultPages::getThankYouPage($this->adapter);
         }
         $this->getOutput()->addHTML("<br>Redirecting to page {$go}");
         $this->getOutput()->redirect($go);
         return;
     }
     $forbidden = false;
     $this->qs_oid = $req->getText('order_id', '');
     $this->qs_ref = $req->getText('REF', '');
     if ($this->qs_oid === '' && $this->qs_ref === '') {
         $forbidden = true;
         $f_message = 'No order ID in the Querystring.';
     } else {
         $result = $this->popout_if_iframe();
         if ($result) {
             return;
         }
     }
     $session_oid = $this->adapter->session_getData('Donor', 'order_id');
     if (is_null($session_oid) || $this->qs_oid !== $session_oid && strpos($this->qs_ref, (string) $session_oid) === false) {
         $forbidden = true;
         $f_message = "Requested order id not present in the session. (session_oid = '{$session_oid}')";
     }
     if ($forbidden) {
         $this->logger->error($this->qs_oid . " Resultswitcher: forbidden for reason: {$f_message}");
         wfHttpError(403, 'Forbidden', wfMessage('donate_interface-error-http-403')->text());
         return;
     }
     $this->setHeaders();
     $this->logger->info("Resultswitcher: OK to process Order ID: " . $this->qs_oid);
     // dispatch forms/handling
     if ($this->adapter->checkTokens()) {
         // Display form for the first time
         //this next block is for credit card coming back from GC. Only that. Nothing else, ever.
         if ($this->adapter->getData_Unstaged_Escaped('payment_method') === 'cc') {
             $sessionOrders = $req->getSessionData('order_status');
             if (!is_array($sessionOrders) || !isset($sessionOrders[$this->qs_oid]) || !is_array($sessionOrders[$this->qs_oid])) {
                 $result = $this->adapter->do_transaction('Confirm_CreditCard');
                 $session_info = array('data' => $result->getData(), 'message' => $result->getMessage(), 'errors' => $result->getErrors());
                 $sessionOrders[$this->qs_oid] = $session_info;
                 $sessionOrders[$this->qs_oid]['data']['count'] = 0;
             } else {
                 $sessionOrders = $req->getSessionData('order_status');
                 $sessionOrders[$this->qs_oid]['data']['count'] = $sessionOrders[$this->qs_oid]['data']['count'] + 1;
                 $this->logger->error("Resultswitcher: Multiple attempts to process. " . $sessionOrders[$this->qs_oid]['data']['count']);
                 $result = new PaymentTransactionResponse();
                 $result->setData($sessionOrders[$this->qs_oid]['data']);
                 $result->setMessage($sessionOrders[$this->qs_oid]['message']);
                 $result->setErrors($sessionOrders[$this->qs_oid]['errors']);
             }
             $req->setSessionData('order_status', $sessionOrders);
             $this->displayResultsForDebug($result);
             //do the switching between the... stuff.
             $status = $this->adapter->getFinalStatus();
             if ($status) {
                 switch ($status) {
                     case FinalStatus::COMPLETE:
                     case FinalStatus::PENDING:
                     case FinalStatus::PENDING_POKE:
                         $this->logger->info("Displaying thank you page for final status {$status}");
                         $go = ResultPages::getThankYouPage($this->adapter);
                         break;
                     case FinalStatus::FAILED:
                         $this->logger->info('Displaying fail page for final status failed.');
                         $this->displayFailPage();
                         return;
                 }
                 if ($go) {
                     $this->getOutput()->addHTML("<br>Redirecting to page {$go}");
                     $this->getOutput()->redirect($go);
                     return;
                 } else {
                     $this->logger->error("Resultswitcher: No redirect defined. Order ID: {$this->qs_oid}");
                 }
             } else {
                 $this->logger->error("Resultswitcher: No FinalStatus. Order ID: {$this->qs_oid}");
             }
         } else {
             $this->logger->error("Resultswitcher: Payment method is not cc. Order ID: {$this->qs_oid}");
         }
     } else {
         $this->logger->error("Resultswitcher: Token Check Failed. Order ID: {$this->qs_oid}");
     }
     $this->displayFailPage();
 }
 public function testCancelPage()
 {
     $this->setMwGlobals(array('wgDonationInterfaceCancelPage' => 'Ways to give'));
     $gateway = $this->getFreshGatewayObject();
     $url = ResultPages::getCancelPage($gateway);
     $expectedTitle = Title::newFromText('Ways to give/en');
     $this->assertEquals($expectedTitle->getFullURL(), $url);
 }
 /**
  * Display information for online bank transfer
  *
  * @deprecated
  */
 protected function displayOnlineBankTransferInformation()
 {
     $data = $this->adapter->getTransactionData();
     $return = '';
     $fields = array('CUSTOMERPAYMENTREFERENCE' => array('translation' => 'donate_interface-obt-customer_payment_reference'), 'BILLERID' => array('translation' => 'donate_interface-obt-biller_id'));
     $id = 'bank_transfer_information';
     $return .= Xml::openElement('div', array('id' => $id));
     // $id
     $return .= Xml::tags('h2', array(), $this->msg('donate_interface-obt-information')->escaped());
     $return .= Xml::tags('p', array(), $this->msg('donate_interface-obt-customer_payment_reference_note')->escaped());
     $return .= Xml::openElement('table', array('id' => $id . '_table'));
     foreach ($fields as $field => $meta) {
         if (isset($data[$field])) {
             $return .= Xml::openElement('tr', array());
             $return .= Xml::tags('th', array(), $this->msg($meta['translation'])->escaped());
             $return .= Xml::tags('td', array(), htmlspecialchars($data[$field], ENT_QUOTES));
             $return .= Xml::closeElement('tr');
         }
     }
     $return .= Xml::closeElement('table');
     // close $id . '_table'
     $return .= Xml::openElement('table');
     //open info table
     $return .= Xml::openElement('tr');
     $return .= Xml::openElement('td');
     $return .= Xml::tags('p', array(), $this->msg('donate_interface-online_bank_transfer_message')->escaped());
     $return .= Xml::closeElement('td');
     $return .= Xml::closeElement('tr');
     $return .= Xml::openElement('tr');
     $return .= Xml::openElement('td');
     $scriptPath = $this->getConfig()->get('ScriptPath');
     $return .= Xml::element('img', array('src' => $scriptPath . "/extensions/DonationInterface/gateway_forms/includes/BPAY_Landscape_MONO.gif", 'style' => 'vertical-align:center; width:100px; margin-right: 1em;'));
     $return .= Xml::closeElement('td');
     $return .= Xml::openElement('td');
     $return .= Xml::tags('p', array(), 'Contact your bank or financial institution <br /> to make this payment from your cheque, <br /> debit, or transaction account. <br /> More info: www.bpay.com.au ');
     $return .= Xml::closeElement('td');
     $return .= Xml::closeElement('tr');
     $return .= Xml::openElement('tr');
     $return .= Xml::openElement('td');
     $return .= Xml::tags('p', array(), '<br /> &reg; Registered to BPAY Pty Ltd ABN 69 079 137 518');
     $return .= Xml::closeElement('td');
     $return .= Xml::closeElement('tr');
     $return .= Xml::closeElement('table');
     //close info table
     $queryParams = array('payment_method' => $this->adapter->getPaymentMethod(), 'payment_submethod' => $this->adapter->getPaymentSubmethod());
     $encUrl = Xml::encodeJsVar(ResultPages::getThankYouPage($this->adapter, $queryParams));
     $link = Html::input('MyButton', 'finished', 'button', array('onclick' => "window.location = {$encUrl}"));
     $return .= Xml::tags('p', array(), $link);
     $return .= Xml::closeElement('div');
     // $id
     $this->getOutput()->addHTML($return);
 }