[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phortune/view/ -> PhortuneCreditCardForm.php (source)

   1  <?php
   2  
   3  final class PhortuneCreditCardForm {
   4  
   5    private $formID;
   6    private $scripts = array();
   7    private $user;
   8    private $errors = array();
   9  
  10    private $cardNumberError;
  11    private $cardCVCError;
  12    private $cardExpirationError;
  13  
  14    public function setUser(PhabricatorUser $user) {
  15      $this->user = $user;
  16      return $this;
  17    }
  18  
  19    public function setErrors(array $errors) {
  20      $this->errors = $errors;
  21      return $this;
  22    }
  23  
  24    public function addScript($script_uri) {
  25      $this->scripts[] = $script_uri;
  26      return $this;
  27    }
  28  
  29    public function getFormID() {
  30      if (!$this->formID) {
  31        $this->formID = celerity_generate_unique_node_id();
  32      }
  33      return $this->formID;
  34    }
  35  
  36    public function buildForm() {
  37      $form_id = $this->getFormID();
  38  
  39      require_celerity_resource('phortune-credit-card-form-css');
  40      require_celerity_resource('phortune-credit-card-form');
  41  
  42      require_celerity_resource('aphront-tooltip-css');
  43      Javelin::initBehavior('phabricator-tooltips');
  44  
  45      $form = new AphrontFormView();
  46  
  47      foreach ($this->scripts as $script) {
  48        $form->appendChild(
  49          phutil_tag(
  50            'script',
  51            array(
  52              'type' => 'text/javascript',
  53              'src'  => $script,
  54            )));
  55      }
  56  
  57      $errors = $this->errors;
  58      $e_number = isset($errors[PhortuneErrCode::ERR_CC_INVALID_NUMBER])
  59        ? pht('Invalid')
  60        : true;
  61  
  62      $e_cvc = isset($errors[PhortuneErrCode::ERR_CC_INVALID_CVC])
  63        ? pht('Invalid')
  64        : true;
  65  
  66      $e_expiry = isset($errors[PhortuneErrCode::ERR_CC_INVALID_EXPIRY])
  67        ? pht('Invalid')
  68        : null;
  69  
  70      $form
  71        ->setID($form_id)
  72        ->appendChild(
  73          id(new AphrontFormMarkupControl())
  74          ->setLabel('')
  75          ->setValue(
  76            javelin_tag(
  77              'div',
  78              array(
  79                'class' => 'credit-card-logos',
  80                'sigil' => 'has-tooltip',
  81                'meta' => array(
  82                  'tip'  => 'We support Visa, Mastercard, American Express, '.
  83                            'Discover, JCB, and Diners Club.',
  84                  'size' => 440,
  85                ),
  86              ))))
  87        ->appendChild(
  88          id(new AphrontFormTextControl())
  89          ->setLabel('Card Number')
  90          ->setDisableAutocomplete(true)
  91          ->setSigil('number-input')
  92          ->setError($e_number))
  93        ->appendChild(
  94          id(new AphrontFormTextControl())
  95          ->setLabel('CVC')
  96          ->setDisableAutocomplete(true)
  97          ->setSigil('cvc-input')
  98          ->setError($e_cvc))
  99        ->appendChild(
 100          id(new PhortuneMonthYearExpiryControl())
 101          ->setLabel('Expiration')
 102          ->setUser($this->user)
 103          ->setError($e_expiry));
 104  
 105      return $form;
 106    }
 107  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1