PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/membership/lib/authorize.net/lib/shared/AuthorizeNetTypes.php

https://gitlab.com/najomie/fit-hippie
PHP | 404 lines | 288 code | 39 blank | 77 comment | 6 complexity | c44582d68754e27a94daf69043b6dedf MD5 | raw file
  1. <?php
  2. /**
  3. * Classes for the various AuthorizeNet data types.
  4. *
  5. * @package AuthorizeNet
  6. * @subpackage AuthorizeNetCIM
  7. */
  8. /**
  9. * A class that contains all fields for a CIM Customer Profile.
  10. *
  11. * @package AuthorizeNet
  12. * @subpackage AuthorizeNetCIM
  13. */
  14. class M2_AuthorizeNetCustomer
  15. {
  16. public $merchantCustomerId;
  17. public $description;
  18. public $email;
  19. public $paymentProfiles = array();
  20. public $shipToList = array();
  21. public $customerProfileId;
  22. }
  23. /**
  24. * A class that contains all fields for a CIM Address.
  25. *
  26. * @package AuthorizeNet
  27. * @subpackage AuthorizeNetCIM
  28. */
  29. class M2_AuthorizeNetAddress
  30. {
  31. public $firstName;
  32. public $lastName;
  33. public $company;
  34. public $address;
  35. public $city;
  36. public $state;
  37. public $zip;
  38. public $country;
  39. public $phoneNumber;
  40. public $faxNumber;
  41. public $customerAddressId;
  42. }
  43. /**
  44. * A class that contains all fields for a CIM Payment Profile.
  45. *
  46. * @package AuthorizeNet
  47. * @subpackage AuthorizeNetCIM
  48. */
  49. class M2_AuthorizeNetPaymentProfile
  50. {
  51. public $customerType;
  52. public $billTo;
  53. public $payment;
  54. public $customerPaymentProfileId;
  55. public function __construct()
  56. {
  57. $this->billTo = new M2_AuthorizeNetAddress;
  58. $this->payment = new M2_AuthorizeNetPayment;
  59. }
  60. }
  61. /**
  62. * A class that contains all fields for a CIM Payment Type.
  63. *
  64. * @package AuthorizeNet
  65. * @subpackage AuthorizeNetCIM
  66. */
  67. class M2_AuthorizeNetPayment
  68. {
  69. public $creditCard;
  70. public $bankAccount;
  71. public function __construct()
  72. {
  73. $this->creditCard = new M2_AuthorizeNetCreditCard;
  74. $this->bankAccount = new M2_AuthorizeNetBankAccount;
  75. }
  76. }
  77. /**
  78. * A class that contains all fields for a CIM Transaction.
  79. *
  80. * @package AuthorizeNet
  81. * @subpackage AuthorizeNetCIM
  82. */
  83. class M2_AuthorizeNetTransaction
  84. {
  85. public $amount;
  86. public $tax;
  87. public $shipping;
  88. public $duty;
  89. public $lineItems = array();
  90. public $customerProfileId;
  91. public $customerPaymentProfileId;
  92. public $customerShippingAddressId;
  93. public $creditCardNumberMasked;
  94. public $bankRoutingNumberMasked;
  95. public $bankAccountNumberMasked;
  96. public $order;
  97. public $taxExempt;
  98. public $recurringBilling;
  99. public $cardCode;
  100. public $splitTenderId;
  101. public $approvalCode;
  102. public $transId;
  103. public function __construct()
  104. {
  105. $this->tax = (object)array();
  106. $this->tax->amount = "";
  107. $this->tax->name = "";
  108. $this->tax->description = "";
  109. $this->shipping = (object)array();
  110. $this->shipping->amount = "";
  111. $this->shipping->name = "";
  112. $this->shipping->description = "";
  113. $this->duty = (object)array();
  114. $this->duty->amount = "";
  115. $this->duty->name = "";
  116. $this->duty->description = "";
  117. // line items
  118. $this->order = (object)array();
  119. $this->order->invoiceNumber = "";
  120. $this->order->description = "";
  121. $this->order->purchaseOrderNumber = "";
  122. }
  123. }
  124. /**
  125. * A class that contains all fields for a CIM Transaction Line Item.
  126. *
  127. * @package AuthorizeNet
  128. * @subpackage AuthorizeNetCIM
  129. */
  130. class M2_AuthorizeNetLineItem
  131. {
  132. public $itemId;
  133. public $name;
  134. public $description;
  135. public $quantity;
  136. public $unitPrice;
  137. public $taxable;
  138. }
  139. /**
  140. * A class that contains all fields for a CIM Credit Card.
  141. *
  142. * @package AuthorizeNet
  143. * @subpackage AuthorizeNetCIM
  144. */
  145. class M2_AuthorizeNetCreditCard
  146. {
  147. public $cardNumber;
  148. public $expirationDate;
  149. public $cardCode;
  150. }
  151. /**
  152. * A class that contains all fields for a CIM Bank Account.
  153. *
  154. * @package AuthorizeNet
  155. * @subpackage AuthorizeNetCIM
  156. */
  157. class M2_AuthorizeNetBankAccount
  158. {
  159. public $accountType;
  160. public $routingNumber;
  161. public $accountNumber;
  162. public $nameOnAccount;
  163. public $echeckType;
  164. public $bankName;
  165. }
  166. /**
  167. * A class that contains all fields for an AuthorizeNet ARB Subscription.
  168. *
  169. * @package AuthorizeNet
  170. * @subpackage AuthorizeNetARB
  171. */
  172. class M2_AuthorizeNet_Subscription
  173. {
  174. public $name;
  175. public $intervalLength;
  176. public $intervalUnit;
  177. public $startDate;
  178. public $totalOccurrences;
  179. public $trialOccurrences;
  180. public $amount;
  181. public $trialAmount;
  182. public $creditCardCardNumber;
  183. public $creditCardExpirationDate;
  184. public $creditCardCardCode;
  185. public $bankAccountAccountType;
  186. public $bankAccountRoutingNumber;
  187. public $bankAccountAccountNumber;
  188. public $bankAccountNameOnAccount;
  189. public $bankAccountEcheckType;
  190. public $bankAccountBankName;
  191. public $orderInvoiceNumber;
  192. public $orderDescription;
  193. public $customerId;
  194. public $customerEmail;
  195. public $customerPhoneNumber;
  196. public $customerFaxNumber;
  197. public $billToFirstName;
  198. public $billToLastName;
  199. public $billToCompany;
  200. public $billToAddress;
  201. public $billToCity;
  202. public $billToState;
  203. public $billToZip;
  204. public $billToCountry;
  205. public $shipToFirstName;
  206. public $shipToLastName;
  207. public $shipToCompany;
  208. public $shipToAddress;
  209. public $shipToCity;
  210. public $shipToState;
  211. public $shipToZip;
  212. public $shipToCountry;
  213. public function getXml()
  214. {
  215. $xml = "<subscription>
  216. <name>{$this->name}</name>
  217. <paymentSchedule>
  218. <interval>
  219. <length>{$this->intervalLength}</length>
  220. <unit>{$this->intervalUnit}</unit>
  221. </interval>
  222. <startDate>{$this->startDate}</startDate>
  223. <totalOccurrences>{$this->totalOccurrences}</totalOccurrences>
  224. <trialOccurrences>{$this->trialOccurrences}</trialOccurrences>
  225. </paymentSchedule>
  226. <amount>{$this->amount}</amount>
  227. <trialAmount>{$this->trialAmount}</trialAmount>
  228. <payment>
  229. <creditCard>
  230. <cardNumber>{$this->creditCardCardNumber}</cardNumber>
  231. <expirationDate>{$this->creditCardExpirationDate}</expirationDate>
  232. <cardCode>{$this->creditCardCardCode}</cardCode>
  233. </creditCard>
  234. <bankAccount>
  235. <accountType>{$this->bankAccountAccountType}</accountType>
  236. <routingNumber>{$this->bankAccountRoutingNumber}</routingNumber>
  237. <accountNumber>{$this->bankAccountAccountNumber}</accountNumber>
  238. <nameOnAccount>{$this->bankAccountNameOnAccount}</nameOnAccount>
  239. <echeckType>{$this->bankAccountEcheckType}</echeckType>
  240. <bankName>{$this->bankAccountBankName}</bankName>
  241. </bankAccount>
  242. </payment>
  243. <order>
  244. <invoiceNumber>{$this->orderInvoiceNumber}</invoiceNumber>
  245. <description>{$this->orderDescription}</description>
  246. </order>
  247. <customer>
  248. <id>{$this->customerId}</id>
  249. <email>{$this->customerEmail}</email>
  250. <phoneNumber>{$this->customerPhoneNumber}</phoneNumber>
  251. <faxNumber>{$this->customerFaxNumber}</faxNumber>
  252. </customer>
  253. <billTo>
  254. <firstName>{$this->billToFirstName}</firstName>
  255. <lastName>{$this->billToLastName}</lastName>
  256. <company>{$this->billToCompany}</company>
  257. <address>{$this->billToAddress}</address>
  258. <city>{$this->billToCity}</city>
  259. <state>{$this->billToState}</state>
  260. <zip>{$this->billToZip}</zip>
  261. <country>{$this->billToCountry}</country>
  262. </billTo>
  263. <shipTo>
  264. <firstName>{$this->shipToFirstName}</firstName>
  265. <lastName>{$this->shipToLastName}</lastName>
  266. <company>{$this->shipToCompany}</company>
  267. <address>{$this->shipToAddress}</address>
  268. <city>{$this->shipToCity}</city>
  269. <state>{$this->shipToState}</state>
  270. <zip>{$this->shipToZip}</zip>
  271. <country>{$this->shipToCountry}</country>
  272. </shipTo>
  273. </subscription>";
  274. $xml_clean = "";
  275. // Remove any blank child elements
  276. foreach (preg_split("/(\r?\n)/", $xml) as $key => $line) {
  277. if (!preg_match('/><\//', $line)) {
  278. $xml_clean .= $line . "\n";
  279. }
  280. }
  281. // Remove any blank parent elements
  282. $element_removed = 1;
  283. // Recursively repeat if a change is made
  284. while ($element_removed) {
  285. $element_removed = 0;
  286. if (preg_match('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', $xml_clean)) {
  287. $xml_clean = preg_replace('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', '', $xml_clean);
  288. $element_removed = 1;
  289. }
  290. }
  291. // Remove any blank lines
  292. // $xml_clean = preg_replace('/\r\n[\s]+\r\n/','',$xml_clean);
  293. return $xml_clean;
  294. }
  295. }
  296. /**
  297. * A class that contains all fields for an AuthorizeNet ARB SubscriptionList.
  298. *
  299. * @package AuthorizeNet
  300. * @subpackage AuthorizeNetARB
  301. */
  302. class M2_AuthorizeNetGetSubscriptionList
  303. {
  304. public $searchType;
  305. public $sorting;
  306. public $paging;
  307. public function getXml()
  308. {
  309. $emptyString = "";
  310. $sortingXml = (is_null($this->sorting)) ? $emptyString : $this->sorting->getXml();
  311. $pagingXml = (is_null($this->paging)) ? $emptyString : $this->paging->getXml();
  312. $xml = "
  313. <searchType>{$this->searchType}</searchType>"
  314. .$sortingXml
  315. .$pagingXml
  316. ;
  317. $xml_clean = "";
  318. // Remove any blank child elements
  319. foreach (preg_split("/(\r?\n)/", $xml) as $key => $line) {
  320. if (!preg_match('/><\//', $line)) {
  321. $xml_clean .= $line . "\n";
  322. }
  323. }
  324. // Remove any blank parent elements
  325. $element_removed = 1;
  326. // Recursively repeat if a change is made
  327. while ($element_removed) {
  328. $element_removed = 0;
  329. if (preg_match('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', $xml_clean)) {
  330. $xml_clean = preg_replace('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', '', $xml_clean);
  331. $element_removed = 1;
  332. }
  333. }
  334. // Remove any blank lines
  335. // $xml_clean = preg_replace('/\r\n[\s]+\r\n/','',$xml_clean);
  336. return $xml_clean;
  337. }
  338. }
  339. class M2_AuthorizeNetSubscriptionListPaging
  340. {
  341. public $limit;
  342. public $offset;
  343. public function getXml()
  344. {
  345. $xml = "<paging>
  346. <limit>{$this->limit}</limit>
  347. <offset>{$this->offset}</offset>
  348. </paging>";
  349. return $xml;
  350. }
  351. }
  352. class M2_AuthorizeNetSubscriptionListSorting
  353. {
  354. public $orderBy;
  355. public $orderDescending;
  356. public function getXml()
  357. {
  358. $xml = "
  359. <sorting>
  360. <orderBy>{$this->orderBy}</orderBy>
  361. <orderDescending>{$this->orderDescending}</orderDescending>
  362. </sorting>";
  363. return $xml;
  364. }
  365. }