public function getCurlBaseOpts()
 {
     $opts = parent::getCurlBaseOpts();
     if ($this->isCertificateAuthentication()) {
         $opts[CURLOPT_SSLCERTTYPE] = 'PEM';
         $opts[CURLOPT_SSLCERT] = $this->account_config['CertificatePath'];
     }
     return $opts;
 }
 public function testFallbackByCountry()
 {
     // With 'FallbackCurrencyByCountry', we need to return a single supported currency
     TestingGenericAdapter::$acceptedCurrencies = array('USD');
     TestingGenericAdapter::$fakeGlobals = array('FallbackCurrency' => false, 'FallbackCurrencyByCountry' => true);
     $this->setUpAdapter();
     $this->adapter->addRequestData(array('country' => 'US'));
     $this->page->validateForm();
     $this->assertEquals(100, $this->adapter->getData_Unstaged_Escaped('amount'));
     $this->assertEquals('USD', $this->adapter->getData_Unstaged_Escaped('currency_code'));
 }
 /**
  * Take UI action suggested by the payment result
  */
 protected function renderResponse(PaymentResult $result)
 {
     if ($result->isFailed()) {
         $this->logger->info('Displaying fail page for failed PaymentResult');
         $this->displayFailPage();
     } elseif ($url = $result->getRedirect()) {
         $this->adapter->logPending();
         $this->getOutput()->redirect($url);
     } elseif ($url = $result->getIframe()) {
         // Show a form containing an iframe.
         // Well, that's sketchy.  See TODO in renderIframe: we should
         // accomplish this entirely by passing an iframeSrcUrl parameter
         // to the template.
         $this->displayForm();
         $this->renderIframe($url);
     } elseif ($form = $result->getForm()) {
         // Show another form.
         $this->adapter->addRequestData(array('ffname' => $form));
         $this->displayForm();
     } elseif ($errors = $result->getErrors()) {
         // FIXME: Creepy.  Currently, the form inspects adapter errors.  Use
         // the stuff encapsulated in PaymentResult instead.
         foreach ($this->adapter->getTransactionResponse()->getErrors() as $code => $transactionError) {
             $message = $transactionError['message'];
             $error = array();
             if (!empty($transactionError['context'])) {
                 $error[$transactionError['context']] = $message;
             } else {
                 if (strpos($code, 'internal') === 0) {
                     $error['retryMsg'][$code] = $message;
                 } else {
                     $error['general'][$code] = $message;
                 }
             }
             $this->adapter->addManualError($error);
         }
         $this->displayForm();
     } else {
         // Success.
         $thankYouPage = ResultPages::getThankYouPage($this->adapter);
         $this->logger->info("Displaying thank you page {$thankYouPage} for successful PaymentResult.");
         $this->getOutput()->redirect($thankYouPage);
     }
 }
 /**
  * Get the expected XML request from GlobalCollect
  *
  * @return string	The expected XML request
  */
 public function getExpectedXmlRequestForGlobalCollect($optionsForTestData, $options = array())
 {
     $orderId = $this->gatewayAdapter->getData_Unstaged_Escaped('order_id');
     $expected = '<?xml version="1.0"?>' . "\n";
     $expected .= '<XML>';
     $expected .= '<REQUEST>';
     $expected .= '<ACTION>INSERT_ORDERWITHPAYMENT</ACTION>';
     $expected .= '<META><MERCHANTID>' . $this->gatewayAdapter->getGlobal('MerchantID') . '</MERCHANTID><VERSION>1.0</VERSION></META>';
     $expected .= '<PARAMS>';
     $expected .= '<ORDER>';
     $expected .= '<ORDERID>' . $orderId . '</ORDERID>';
     $expected .= '<AMOUNT>' . $options['testData']['amount'] * 100 . '</AMOUNT>';
     $expected .= '<CURRENCYCODE>' . $options['testData']['currency_code'] . '</CURRENCYCODE>';
     $expected .= '<LANGUAGECODE>' . $options['testData']['language'] . '</LANGUAGECODE>';
     $expected .= '<COUNTRYCODE>' . $options['testData']['country'] . '</COUNTRYCODE>';
     $expected .= '<MERCHANTREFERENCE>' . $orderId . '</MERCHANTREFERENCE>';
     $expected .= '</ORDER>';
     $expected .= '<PAYMENT>';
     $expected .= '<PAYMENTPRODUCTID>' . $optionsForTestData['payment_product_id'] . '</PAYMENTPRODUCTID>';
     $expected .= '<AMOUNT>' . $options['testData']['amount'] * 100 . '</AMOUNT>';
     $expected .= '<CURRENCYCODE>' . $options['testData']['currency_code'] . '</CURRENCYCODE>';
     $expected .= '<LANGUAGECODE>' . $options['testData']['language'] . '</LANGUAGECODE>';
     $expected .= '<COUNTRYCODE>' . $options['testData']['country'] . '</COUNTRYCODE>';
     $expected .= '<HOSTEDINDICATOR>1</HOSTEDINDICATOR>';
     $expected .= '<RETURNURL>http://' . TESTS_HOSTNAME . '/index.php/Special:GlobalCollectGatewayResult?order_id=' . $orderId . '</RETURNURL>';
     $expected .= '<FIRSTNAME>' . $options['testData']['fname'] . '</FIRSTNAME>';
     $expected .= '<SURNAME>' . $options['testData']['lname'] . '</SURNAME>';
     $expected .= '<STREET>' . $options['testData']['street'] . '</STREET>';
     $expected .= '<CITY>' . $options['testData']['city'] . '</CITY>';
     $expected .= '<STATE>' . $options['testData']['state'] . '</STATE>';
     $expected .= '<EMAIL>' . TESTS_EMAIL . '</EMAIL>';
     // Set the issuer id if it is passed.
     if (isset($optionsForTestData['issuer_id'])) {
         $expected .= '<ISSUERID>' . $optionsForTestData['issuer_id'] . '</ISSUERID>';
     }
     $expected .= '</PAYMENT>';
     $expected .= '</PARAMS>';
     $expected .= '</REQUEST>';
     $expected .= '</XML>';
     return $expected;
 }
 /**
  * MakeGlobalVariablesScript handler, sends settings to Javascript
  * @param array $vars
  */
 public function setClientVariables(&$vars)
 {
     parent::setClientVariables($vars);
     $vars['wgAmazonGatewayClientID'] = $this->account_config['ClientID'];
     $vars['wgAmazonGatewaySellerID'] = $this->account_config['SellerID'];
     $vars['wgAmazonGatewaySandbox'] = $this->getGlobal('Test') ? true : false;
     $vars['wgAmazonGatewayReturnURL'] = $this->account_config['ReturnURL'];
     $vars['wgAmazonGatewayWidgetScript'] = $this->account_config['WidgetScriptURL'];
     $vars['wgAmazonGatewayLoginScript'] = $this->getGlobal('LoginScript');
     $vars['wgAmazonGatewayFailPage'] = $this->getGlobal('FailPage');
     $vars['wgAmazonGatewayOtherWaysURL'] = $this->localizeGlobal('OtherWaysURL');
 }
 /**
  * Pulls normalized and escaped data from the $gateway object.
  * For more information, see GatewayAdapter::getData_Unstaged_Escaped in
  * $IP/extensions/DonationData/gateway_common/gateway.adapter.php
  * @param string $key The value to fetch from the adapter.
  * @return mixed The escaped value in the adapter, or null if none exists.
  * Note: The value could still be a blank string in some cases.
  */
 protected function getEscapedValue($key)
 {
     return $this->gateway->getData_Unstaged_Escaped($key);
 }
 public function defineDataTransformers()
 {
     $this->data_transformers = parent::getCoreDataTransformers();
 }
 /**
  * Because GC has some processes that involve more than one do_transaction 
  * chained together, we're catching those special ones in an overload and 
  * letting the rest behave normally. 
  */
 public function do_transaction($transaction)
 {
     switch ($transaction) {
         case 'Confirm_CreditCard':
             $this->getStopwatch('Confirm_CreditCard', true);
             $result = $this->transactionConfirm_CreditCard();
             $this->saveCommunicationStats('Confirm_CreditCard', $transaction);
             return $result;
             break;
         default:
             return parent::do_transaction($transaction);
     }
 }
 public function delete($correlationId, $queue)
 {
     if (!GatewayAdapter::getGlobal('EnableQueue')) {
         return;
     }
     $this->newBackend($queue)->clear($correlationId);
 }
 function do_transaction($transaction)
 {
     $this->session_addDonorData();
     $this->setCurrentTransaction($transaction);
     switch ($transaction) {
         case 'Donate':
         case 'DonateXclick':
         case 'DonateRecurring':
             $result = parent::do_transaction($transaction);
             $this->finalizeInternalStatus(FinalStatus::COMPLETE);
             return $result;
     }
 }
 /**
  * Overriding @see GatewayAdapter::getTransactionSpecificValue to strip
  * newlines.
  * @param string $gateway_field_name
  * @param boolean $token
  * @return mixed
  */
 protected function getTransactionSpecificValue($gateway_field_name, $token = false)
 {
     $value = parent::getTransactionSpecificValue($gateway_field_name, $token);
     return str_replace('\\n', '', $value);
 }
 /**
  * Get the expected XML request from GlobalCollect
  *
  * @param $optionsForTestData
  * @param array $options
  * @return string    The expected XML request
  */
 public function getExpectedXmlRequestForGlobalCollect($optionsForTestData, $options = array())
 {
     global $wgDonationInterfaceThankYouPage;
     $request = RequestContext::getMain()->getRequest();
     $orderId = $this->gatewayAdapter->getData_Unstaged_Escaped('order_id');
     $exposed = TestingAccessWrapper::newFromObject($this->gatewayAdapter);
     $merchantref = $exposed->getData_Staged('contribution_tracking_id');
     //@TODO: WHY IN THE NAME OF ZARQUON are we building XML in a STRING format here?!?!?!!!1one1!?. Great galloping galumphing giraffes.
     $expected = '<?xml version="1.0" encoding="UTF-8"?' . ">\n";
     $expected .= '<XML>';
     $expected .= '<REQUEST>';
     $expected .= '<ACTION>INSERT_ORDERWITHPAYMENT</ACTION>';
     $expected .= '<META><MERCHANTID>' . $exposed->account_config['MerchantID'] . '</MERCHANTID>';
     if (isset($request)) {
         $expected .= '<IPADDRESS>' . $request->getIP() . '</IPADDRESS>';
     }
     $expected .= '<VERSION>1.0</VERSION>';
     $expected .= '</META>';
     $expected .= '<PARAMS>';
     $expected .= '<ORDER>';
     $expected .= '<ORDERID>' . $orderId . '</ORDERID>';
     $expected .= '<AMOUNT>' . $options['amount'] * 100 . '</AMOUNT>';
     $expected .= '<CURRENCYCODE>' . $options['currency_code'] . '</CURRENCYCODE>';
     $expected .= '<LANGUAGECODE>' . $options['language'] . '</LANGUAGECODE>';
     $expected .= '<COUNTRYCODE>' . $options['country'] . '</COUNTRYCODE>';
     $expected .= '<MERCHANTREFERENCE>' . $merchantref . '</MERCHANTREFERENCE>';
     if (isset($request)) {
         $expected .= '<IPADDRESSCUSTOMER>' . $request->getIP() . '</IPADDRESSCUSTOMER>';
     }
     $expected .= '<EMAIL>' . TESTS_EMAIL . '</EMAIL>';
     $expected .= '</ORDER>';
     $expected .= '<PAYMENT>';
     $expected .= '<PAYMENTPRODUCTID>' . $optionsForTestData['payment_product_id'] . '</PAYMENTPRODUCTID>';
     $expected .= '<AMOUNT>' . $options['amount'] * 100 . '</AMOUNT>';
     $expected .= '<CURRENCYCODE>' . $options['currency_code'] . '</CURRENCYCODE>';
     $expected .= '<LANGUAGECODE>' . $options['language'] . '</LANGUAGECODE>';
     $expected .= '<COUNTRYCODE>' . $options['country'] . '</COUNTRYCODE>';
     $expected .= '<HOSTEDINDICATOR>1</HOSTEDINDICATOR>';
     $expected .= "<RETURNURL>{$wgDonationInterfaceThankYouPage}/{$options['language']}?country={$options['country']}</RETURNURL>";
     $expected .= '<AUTHENTICATIONINDICATOR>0</AUTHENTICATIONINDICATOR>';
     $expected .= '<FIRSTNAME>' . $options['fname'] . '</FIRSTNAME>';
     $expected .= '<SURNAME>' . $options['lname'] . '</SURNAME>';
     $expected .= '<STREET>' . $options['street'] . '</STREET>';
     $expected .= '<CITY>' . $options['city'] . '</CITY>';
     $expected .= '<STATE>' . $options['state'] . '</STATE>';
     $expected .= '<ZIP>' . $options['zip'] . '</ZIP>';
     $expected .= '<EMAIL>' . TESTS_EMAIL . '</EMAIL>';
     // Set the issuer id if it is passed.
     if (isset($optionsForTestData['descriptor'])) {
         $expected .= '<DESCRIPTOR>' . $optionsForTestData['descriptor'] . '</DESCRIPTOR>';
     }
     // Set the issuer id if it is passed.
     if (isset($optionsForTestData['issuer_id'])) {
         $expected .= '<ISSUERID>' . $optionsForTestData['issuer_id'] . '</ISSUERID>';
     }
     // If we're doing Direct Debit...
     //@TODO: go ahead and split this out into a "Get the direct debit I_OWP XML block function" the second this gets even slightly annoying.
     if ($optionsForTestData['payment_method'] === 'dd') {
         $expected .= '<ACCOUNTNAME>' . $optionsForTestData['account_name'] . '</ACCOUNTNAME>';
         $expected .= '<ACCOUNTNUMBER>' . $optionsForTestData['account_number'] . '</ACCOUNTNUMBER>';
         $expected .= '<BANKCODE>' . $optionsForTestData['bank_code'] . '</BANKCODE>';
         $expected .= '<BRANCHCODE>' . $optionsForTestData['branch_code'] . '</BRANCHCODE>';
         $expected .= '<BANKCHECKDIGIT>' . $optionsForTestData['bank_check_digit'] . '</BANKCHECKDIGIT>';
         $expected .= '<DATECOLLECT>' . gmdate('Ymd') . '</DATECOLLECT>';
         //is this cheating? Probably.
         $expected .= '<DIRECTDEBITTEXT>' . $optionsForTestData['direct_debit_text'] . '</DIRECTDEBITTEXT>';
     }
     $expected .= '</PAYMENT>';
     $expected .= '</PARAMS>';
     $expected .= '</REQUEST>';
     $expected .= '</XML>';
     return $expected;
 }
 public function stageData()
 {
     // Must run first because staging relies on constraints.
     $this->tuneConstraints();
     parent::stageData();
     // FIXME: Move to a more specific point in the workflow, in the related do_transaction handler.
     $this->set3dsFlag();
     // FIXME: Move to a post-staging hook, and push most of it into the declarative block.
     $this->tuneForMethod();
     $this->tuneForRecurring();
     $this->tuneForCountry();
 }
 /**
  * Overriding parent method to add fiscal number
  * @return array of required field names
  */
 public function getRequiredFields()
 {
     $fields = parent::getRequiredFields();
     $noFiscalRequired = array('MX', 'PE');
     $country = $this->getData_Unstaged_Escaped('country');
     if (!in_array($country, $noFiscalRequired)) {
         $fields[] = 'fiscal_number';
     }
     $fields[] = 'payment_submethod';
     return $fields;
 }