Exemplo n.º 1
0
 /**
  * Creates and returns the HTML Form for requesting the payment service.
  *
  * The parameters in $uriparam are appended to the base index URI.
  * If empty, this defaults to "section=Shop&cmd=success".
  *
  * @access  public
  * @global  array       $_ARRAYLANG
  * @param   array       $arrFields      The parameter array
  * @param   string      $submitValue    The optional label for the submit button
  * @param   boolean     $autopost       If true, the form is automatically submitted. Defaults to false.
  * @param   array       $arrSettings    Settings from \Cx\Core\Setting
  * @param   object      $landingPage    The optional URI parameter string
  * @return  string                      The HTML form code
  */
 static function getForm($arrFields, $submitValue = 'Send', $autopost = false, $arrSettings = null, $landingPage = null)
 {
     global $_ARRAYLANG;
     if (gettype($landingPage) != 'object' || get_class($landingPage) != 'Cx\\Core\\ContentManager\\Model\\Entity\\Page') {
         self::$arrError[] = 'No landing page passed.';
     }
     if (($sectionName = $landingPage->getModule()) && !empty($sectionName)) {
         self::$sectionName = $sectionName;
     } else {
         self::$arrError[] = 'Passed landing page is not an application.';
     }
     if (empty($arrSettings)) {
         $settingDb = \Cx\Core\Setting\Controller\Setting::getArray(self::$sectionName, 'config');
         if (!empty($settingDb) && $settingDb['postfinance_active']['value']) {
             $arrSettings = $settingDb;
         } else {
             self::$arrError[] = "Could not load settings.";
         }
     }
     if (empty($arrFields['PSPID'])) {
         $arrFields['PSPID'] = $arrSettings['postfinance_shop_id']['value'];
     }
     if (empty($arrFields['OPERATION'])) {
         $arrFields['OPERATION'] = $arrSettings['postfinance_authorization_type']['value'];
     }
     if (empty($arrFields['LANGUAGE'])) {
         $arrFields['LANGUAGE'] = strtolower(FWLanguage::getLanguageCodeById(FRONTEND_LANG_ID)) . '_' . strtoupper(FWLanguage::getLanguageCodeById(FRONTEND_LANG_ID));
     }
     $baseUri = Cx\Core\Routing\Url::fromPage($landingPage)->toString() . '?result=';
     if (empty($arrFields['ACCEPTURL'])) {
         $arrFields['ACCEPTURL'] = $baseUri . '1';
     }
     if (empty($arrFields['DECLINEURL'])) {
         $arrFields['DECLINEURL'] = $baseUri . '2';
     }
     if (empty($arrFields['EXCEPTIONURL'])) {
         $arrFields['EXCEPTIONURL'] = $baseUri . '2';
     }
     if (empty($arrFields['CANCELURL'])) {
         $arrFields['CANCELURL'] = $baseUri . '0';
     }
     if (empty($arrFields['BACKURL'])) {
         $arrFields['BACKURL'] = $baseUri . '2';
     }
     if (!self::setFields($arrFields)) {
         self::$arrError[] = 'Failed to verify keys.';
         return false;
     }
     $arrFields['SHASIGN'] = self::signature($arrFields, $arrSettings['postfinance_hash_signature_in']['value']);
     $server = $arrSettings['postfinance_use_testserver']['value'] ? 'test' : 'prod';
     $charset = CONTREXX_CHARSET == 'UTF-8' ? '_utf8' : '';
     $hiddenFields = '';
     foreach ($arrFields as $name => $value) {
         $hiddenFields .= Html::getHidden($name, $value);
     }
     $autoSubmit = !$autopost ? '' : '
         <script type="text/javascript">
         /* <![CDATA[ */
             document.yellowpay.submit();
         /* ]]> */
         </script>
     ';
     $form = $_ARRAYLANG['TXT_ORDER_LINK_PREPARED'] . '<br/><br/>' . '<form name="yellowpay" method="post" action="https://e-payment.postfinance.ch/ncol/' . $server . '/orderstandard' . $charset . '.asp">' . $hiddenFields . '<input type="submit" name="go" value="' . $submitValue . '" />' . '</form>' . $autoSubmit;
     return $form;
 }