Odyssey
2019080900_UpdateIpayV3.php
1 <?php
2 /**
3  * Notes:
4  * 1. Anything complicated needs to be done with SQL.
5  * 2. Always have a check to know if the migration needs to occur (up or down).
6  * 3. Use up() and down(), not change(), because of the SQL
7  */
8 use Phinx\Migration\AbstractMigration;
9 
10 /**
11  * Updates trusted master to include EnrollMICR for IPAY_V3
12  */
13 class UpdateIpayV3 extends AbstractMigration {
14 
15  /** @var string */
16  protected $trusted_table = "cutrustedmaster";
17 
18  /** @var array - use in part for updates, completely for insert */
19  protected $trusted_default = [
20  'trustedid' => 'IPAY_V3',
21  'trustedvendor' => 'IPAY',
22  'trustedtype' => 'BillPay',
23  'hcuinterface' => '\["CLS","CMB"\]',
24  'trustedfields' => [
25  'skip_company'=> [
26  'Type' => 'digits',
27  'Default' => 0,
28  'Message' => "set to 1 to exclude ''CompanyID'' tag in Login XML"
29  ],
30  'moc_session' => [
31  'Type' => 'string',
32  'Default' => 'https://moc.billpaysite.com/messaging/messagehandler.aspx',
33  ],
34  'moc_login' => [
35  'Type' => 'string',
36  'Default' => 'https://moc.billpaysite.com/intro.asp',
37  ],
38  'moc_key' => [
39  'Type' => 'string',
40  'Default' => '',
41  ],
42  'prod_session' => [
43  'Type' => 'string',
44  'Default' => 'https://www.billpaysite.com/messaging/messagehandler.aspx',
45  ],
46  'prod_login' => [
47  'Type' => 'string',
48  'Default' => 'https://www.billpaysite.com/intro.asp',
49  ],
50  'prod_key' => [
51  'Type' => 'digits',
52  'Default' => '',
53  'Message' => 'issued by iPay / Jack Henry'
54  ],
55  'ipay_instid' => [
56  'Type' => 'digits',
57  'Default' => '',
58  'Message' => 'issued by iPay / Jack Henry'
59  ],
60  'hcu_iv' => [
61  'Type' => 'string',
62  'Default' => '',
63  'Message' => "From linux run pwgen 16 -C and pick a value"
64  ],
65  'moc' => [
66  'Type' => 'digits',
67  'Default' => 1,
68  ],
69  'hcuLogging' => [
70  'Type' => 'string',
71  'Default' => 0
72  ],
73  'EnrollMICR' => [
74  'Type' => 'string',
75  'Default' => 0,
76  'Message' => '0=Enroll using member number as AccountNumber or 1= Enroll using micraccount as AccountNumber'
77  ]
78  ]
79  ];
80 
81  /**
82  * See if IPAY_V3 exists, if so if the EnrollMIRC key is not present update it.
83  * If there's more than 1 record, we wind up updating all of them and something else is messed up.
84  * @return void
85  */
86  public function up() {
87 
88  if ($this->hasTable($this->trusted_table)) {
89 
90  $def = $this->trusted_default;
91  $ipay_row = $this->fetchRow("select * from {$this->trusted_table} where trustedid = 'IPAY_V3'");
92 
93  if (count($ipay_row) > 0) {
94 
95  $details = json_decode($ipay_row['trustedfields'], 1);
96  if (array_key_exists('EnrollMICR', $details)) {
97 
98  return;
99  }
100 
101  // Else . . .
102  $sql = "update {$this->trusted_table} set trustedfields = '"
103  . json_encode($def['trustedfields'])
104  . "' where trustedid = 'IPAY_V3'";
105 
106  $this->query($sql);
107 
108  return;
109  }
110 
111  if (count($ipay_row) == 0) {
112 
113  $sql = "insert into {$this->trusted_table} (trustedid, trustedvendor, trustedtype, hcuinterface, trustedfields)"
114  . " values('{$def['trustedid']}', '{$def['trustedvendor']}', '{$def['trustedtype']},'"
115  . " '{$def['hcuinterface']}', '" . json_encode($def['trustedfields']) . "'";
116 
117  $this->query($sql);
118  }
119  }
120 
121 
122  }
123 
124  /**
125  * **Assuming** the previous state was properly added without EnrollMICR, re-add it as such.
126  * @return void
127  */
128  public function down() {
129 
130  $def = $this->trusted_default;
131  unset ($def['trustedfields']['EnrollMICR']);
132 
133  $sql = "update {$this->trusted_table} set trustedfields = '"
134  . json_encode($def['trustedfields'])
135  . "' where trustedid = 'IPAY_V3'";
136 
137  $this->query($sql);
138  }
139 }
140