@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhortuneCreditCardForm extends Phobject {
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 private $securityAssurance;
14
15 public function setSecurityAssurance($security_assurance) {
16 $this->securityAssurance = $security_assurance;
17 return $this;
18 }
19
20 public function getSecurityAssurance() {
21 return $this->securityAssurance;
22 }
23
24 public function setUser(PhabricatorUser $user) {
25 $this->user = $user;
26 return $this;
27 }
28
29 public function setErrors(array $errors) {
30 $this->errors = $errors;
31 return $this;
32 }
33
34 public function addScript($script_uri) {
35 $this->scripts[] = $script_uri;
36 return $this;
37 }
38
39 public function getFormID() {
40 if (!$this->formID) {
41 $this->formID = celerity_generate_unique_node_id();
42 }
43 return $this->formID;
44 }
45
46 public function buildForm() {
47 $form_id = $this->getFormID();
48
49 require_celerity_resource('phortune-credit-card-form-css');
50 require_celerity_resource('phortune-credit-card-form');
51
52 require_celerity_resource('aphront-tooltip-css');
53 Javelin::initBehavior('phabricator-tooltips');
54
55 $form = new AphrontFormView();
56
57 foreach ($this->scripts as $script) {
58 $form->appendChild(
59 phutil_tag(
60 'script',
61 array(
62 'type' => 'text/javascript',
63 'src' => $script,
64 )));
65 }
66
67 $errors = $this->errors;
68 $e_number = isset($errors[PhortuneErrCode::ERR_CC_INVALID_NUMBER])
69 ? pht('Invalid')
70 : null;
71
72 $e_cvc = isset($errors[PhortuneErrCode::ERR_CC_INVALID_CVC])
73 ? pht('Invalid')
74 : null;
75
76 $e_expiry = isset($errors[PhortuneErrCode::ERR_CC_INVALID_EXPIRY])
77 ? pht('Invalid')
78 : null;
79
80 $form
81 ->setID($form_id)
82 ->appendChild(
83 id(new AphrontFormTextControl())
84 ->setLabel(pht('Card Number'))
85 ->setDisableAutocomplete(true)
86 ->setSigil('number-input')
87 ->setError($e_number))
88 ->appendChild(
89 id(new AphrontFormTextControl())
90 ->setLabel(pht('CVC'))
91 ->setDisableAutocomplete(true)
92 ->addClass('aphront-form-cvc-input')
93 ->setSigil('cvc-input')
94 ->setError($e_cvc))
95 ->appendChild(
96 id(new PhortuneMonthYearExpiryControl())
97 ->setLabel(pht('Expiration'))
98 ->setUser($this->user)
99 ->setError($e_expiry));
100
101 $assurance = $this->getSecurityAssurance();
102 if ($assurance) {
103 $assurance = phutil_tag(
104 'div',
105 array(
106 'class' => 'phortune-security-assurance',
107 ),
108 array(
109 id(new PHUIIconView())
110 ->setIcon('fa-lock grey'),
111 ' ',
112 $assurance,
113 ));
114
115 $form->appendChild(
116 id(new AphrontFormMarkupControl())
117 ->setValue($assurance));
118 }
119
120 return $form;
121 }
122}