WC_Boleto_Gateway

WC Boleto Gateway Class.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-boleto-gateway.php  
  1. class WC_Boleto_Gateway extends WC_Payment_Gateway { 
  2.  
  3. /** 
  4. * Initialize the gateway actions. 
  5. */ 
  6. public function __construct() { 
  7. $this->id = 'boleto'; 
  8. $this->icon = apply_filters( 'wcboleto_icon', plugins_url( 'assets/images/boleto.png', plugin_dir_path( __FILE__ ) ) ); 
  9. $this->has_fields = false; 
  10. $this->method_title = __( 'Banking Ticket', 'woocommerce-boleto' ); 
  11. $this->method_description = __( 'Enables payments via Banking Ticket.', 'woocommerce-boleto' ); 
  12.  
  13. // Load the settings. 
  14. $this->init_form_fields(); 
  15. $this->init_settings(); 
  16.  
  17. // Define user settings variables. 
  18. $this->title = $this->get_option( 'title' ); 
  19. $this->description = $this->get_option( 'description' ); 
  20. $this->boleto_time = $this->get_option( 'boleto_time' ); 
  21.  
  22. // Actions. 
  23. add_action( 'woocommerce_thankyou_boleto', array( $this, 'thankyou_page' ) ); 
  24. add_action( 'woocommerce_email_after_order_table', array( $this, 'email_instructions' ), 10, 2 ); 
  25. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 
  26.  
  27. /** 
  28. * Returns a bool that indicates if currency is amongst the supported ones. 
  29. * @return bool 
  30. */ 
  31. protected function using_supported_currency() { 
  32. return ( 'BRL' == get_woocommerce_currency() ); 
  33.  
  34. /** 
  35. * Returns a value indicating the the Gateway is available or not. It's called 
  36. * automatically by WooCommerce before allowing customers to use the gateway 
  37. * for payment. 
  38. * @return bool 
  39. */ 
  40. public function is_available() { 
  41. // Test if is valid for use. 
  42. $available = ( 'yes' == $this->get_option( 'enabled' ) ) && $this->using_supported_currency(); 
  43.  
  44. return $available; 
  45.  
  46. /** 
  47. * Admin Panel Options. 
  48. * @return string Admin form. 
  49. */ 
  50. public function admin_options() { 
  51. include 'views/html-admin-page.php'; 
  52.  
  53. /** 
  54. * Gateway options. 
  55. */ 
  56. public function init_form_fields() { 
  57. $shop_name = get_bloginfo( 'name' ); 
  58.  
  59. $first = array( 
  60. 'enabled' => array( 
  61. 'title' => __( 'Enable/Disable', 'woocommerce-boleto' ),  
  62. 'type' => 'checkbox',  
  63. 'label' => __( 'Enable Banking Ticket', 'woocommerce-boleto' ),  
  64. 'default' => 'yes' 
  65. ),  
  66. 'title' => array( 
  67. 'title' => __( 'Title', 'woocommerce-boleto' ),  
  68. 'type' => 'text',  
  69. 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-boleto' ),  
  70. 'desc_tip' => true,  
  71. 'default' => __( 'Banking Ticket', 'woocommerce-boleto' ) 
  72. ),  
  73. 'description' => array( 
  74. 'title' => __( 'Description', 'woocommerce-boleto' ),  
  75. 'type' => 'textarea',  
  76. 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-boleto' ),  
  77. 'desc_tip' => true,  
  78. 'default' => __( 'Pay with Banking Ticket', 'woocommerce-boleto' ) 
  79. ),  
  80. 'boleto_details' => array( 
  81. 'title' => __( 'Ticket Details', 'woocommerce-boleto' ),  
  82. 'type' => 'title' 
  83. ),  
  84. 'boleto_time' => array( 
  85. 'title' => __( 'Deadline to pay the Ticket', 'woocommerce-boleto' ),  
  86. 'type' => 'text',  
  87. 'description' => __( 'Number of days to pay.', 'woocommerce-boleto' ),  
  88. 'desc_tip' => true,  
  89. 'default' => 5 
  90. ),  
  91. 'boleto_logo' => array( 
  92. 'title' => __( 'Ticket Logo', 'woocommerce-boleto' ),  
  93. 'type' => 'text',  
  94. 'description' => __( 'Logo with 147px x 46px.', 'woocommerce-boleto' ),  
  95. 'desc_tip' => true,  
  96. 'default' => plugins_url( 'assets/images/logo_empresa.png', plugin_dir_path( __FILE__ ) ) 
  97. ),  
  98. 'bank_details' => array( 
  99. 'title' => __( 'Bank Details', 'woocommerce-boleto' ),  
  100. 'type' => 'title' 
  101. ),  
  102. 'bank' => array( 
  103. 'title' => __( 'Bank', 'woocommerce-boleto' ),  
  104. 'type' => 'select',  
  105. 'desc_tip' => true,  
  106. 'description' => __( 'Choose the bank for Ticket.', 'woocommerce-boleto' ),  
  107. 'default' => '0',  
  108. 'options' => array( 
  109. '0' => '--',  
  110. 'bb' => __( 'Banco do Brasil', 'woocommerce-boleto' ),  
  111. 'bradesco' => __( 'Bradesco', 'woocommerce-boleto' ),  
  112. 'cef' => __( 'Caixa Economica Federal - SR (SICOB)', 'woocommerce-boleto' ),  
  113. 'cef_sigcb' => __( 'Caixa Economica Federal - SIGCB', 'woocommerce-boleto' ),  
  114. 'cef_sinco' => __( 'Caixa Economica Federal - SINCO', 'woocommerce-boleto' ),  
  115. 'hsbc' => __( 'HSBC', 'woocommerce-boleto' ),  
  116. 'itau' => __( 'Itau', 'woocommerce-boleto' ),  
  117. 'nossacaixa' => __( 'Nossa Caixa', 'woocommerce-boleto' ),  
  118. 'real' => __( 'Real', 'woocommerce-boleto' ),  
  119. 'santander' => __( 'Santander', 'woocommerce-boleto' ),  
  120. 'unibanco' => __( 'Unibanco', 'woocommerce-boleto' ),  
  121. 'bancoob' => __( 'Bancoob', 'woocommerce-boleto') 
  122. ); 
  123.  
  124. $last = array( 
  125. 'extra_details' => array( 
  126. 'title' => __( 'Optional Data', 'woocommerce-boleto' ),  
  127. 'type' => 'title' 
  128. ),  
  129. 'quantidade' => array( 
  130. 'title' => __( 'Quantity', 'woocommerce-boleto' ),  
  131. 'type' => 'text' 
  132. ),  
  133. 'valor_unitario' => array( 
  134. 'title' => __( 'Unitary value', 'woocommerce-boleto' ),  
  135. 'type' => 'text' 
  136. ),  
  137. 'aceite' => array( 
  138. 'title' => __( 'Acceptance', 'woocommerce-boleto' ),  
  139. 'type' => 'text' 
  140. ),  
  141. 'especie' => array( 
  142. 'title' => __( 'Currency', 'woocommerce-boleto' ),  
  143. 'type' => 'text',  
  144. 'default' => 'R$' 
  145. ),  
  146. 'especie_doc' => array( 
  147. 'title' => __( 'Kind of document', 'woocommerce-boleto' ),  
  148. 'type' => 'text' 
  149. ),  
  150. 'especie' => array( 
  151. 'title' => __( 'Currency', 'woocommerce-boleto' ),  
  152. 'type' => 'text',  
  153. 'default' => 'R$' 
  154. ),  
  155. 'demonstrative' => array( 
  156. 'title' => __( 'Demonstrative', 'woocommerce-boleto' ),  
  157. 'type' => 'title' 
  158. ),  
  159. 'demonstrativo1' => array( 
  160. 'title' => __( 'Line 1', 'woocommerce-boleto' ),  
  161. 'type' => 'text',  
  162. 'description' => __( 'Use [number] to show the Order ID.', 'woocommerce-boleto' ),  
  163. 'desc_tip' => true,  
  164. 'default' => sprintf( __( 'Payment for purchase in %s', 'woocommerce-boleto' ), $shop_name ) 
  165. ),  
  166. 'demonstrativo2' => array( 
  167. 'title' => __( 'Line 2', 'woocommerce-boleto' ),  
  168. 'type' => 'text',  
  169. 'description' => __( 'Use [number] to show the Order ID.', 'woocommerce-boleto' ),  
  170. 'desc_tip' => true,  
  171. 'default' => __( 'Payment referred to the order [number]', 'woocommerce-boleto' ) 
  172. ),  
  173. 'demonstrativo3' => array( 
  174. 'title' => __( 'Line 3', 'woocommerce-boleto' ),  
  175. 'type' => 'text',  
  176. 'description' => __( 'Use [number] to show the Order ID.', 'woocommerce-boleto' ),  
  177. 'desc_tip' => true,  
  178. 'default' => $shop_name . ' - ' . home_url() 
  179. ),  
  180. 'instructions' => array( 
  181. 'title' => __( 'Instructions', 'woocommerce-boleto' ),  
  182. 'type' => 'title' 
  183. ),  
  184. 'instrucoes1' => array( 
  185. 'title' => __( 'Line 1', 'woocommerce-boleto' ),  
  186. 'type' => 'text',  
  187. 'default' => __( '- Mr. Cash, charge a fine of 2% after maturity', 'woocommerce-boleto' ) 
  188. ),  
  189. 'instrucoes2' => array( 
  190. 'title' => __( 'Line 2', 'woocommerce-boleto' ),  
  191. 'type' => 'text',  
  192. 'default' => __( '- Receive up to 10 days past due', 'woocommerce-boleto' ) 
  193. ),  
  194. 'instrucoes3' => array( 
  195. 'title' => __( 'Line 3', 'woocommerce-boleto' ),  
  196. 'type' => 'text',  
  197. 'default' => sprintf( __( '- For questions please contact us: %s', 'woocommerce-boleto' ), get_option( 'woocommerce_email_from_address' ) ) 
  198. ),  
  199. 'instrucoes4' => array( 
  200. 'title' => __( 'Line 4', 'woocommerce-boleto' ),  
  201. 'type' => 'text',  
  202. 'default' => '' 
  203. ),  
  204. 'shop_details' => array( 
  205. 'title' => __( 'Shop Details', 'woocommerce-boleto' ),  
  206. 'type' => 'title' 
  207. ),  
  208. 'cpf_cnpj' => array( 
  209. 'title' => __( 'CPF/CNPJ', 'woocommerce-boleto' ),  
  210. 'type' => 'text',  
  211. 'desc_tip' => true,  
  212. 'description' => __( 'Document number.', 'woocommerce-boleto' ),  
  213. ),  
  214. 'endereco' => array( 
  215. 'title' => __( 'Address', 'woocommerce-boleto' ),  
  216. 'type' => 'text',  
  217. 'desc_tip' => true,  
  218. 'description' => __( 'Shop Address.', 'woocommerce-boleto' ),  
  219. ),  
  220. 'cidade_uf' => array( 
  221. 'title' => __( 'City/State', 'woocommerce-boleto' ),  
  222. 'type' => 'text',  
  223. 'desc_tip' => true,  
  224. 'description' => __( 'Example <code>São Paulo/SP</code>.', 'woocommerce-boleto' ),  
  225. ),  
  226. 'cedente' => array( 
  227. 'title' => __( 'Corporate Name', 'woocommerce-boleto' ),  
  228. 'type' => 'text',  
  229. ),  
  230. ); 
  231.  
  232. $this->form_fields = array_merge( $first, $this->get_bank_fields(), $last ); 
  233.  
  234. /** 
  235. * Gets bank fields. 
  236. * @return array Current bank fields. 
  237. */ 
  238. protected function get_bank_fields() { 
  239. switch ( $this->get_option( 'bank' ) ) { 
  240. case 'bb' : 
  241. $fields = array( 
  242. 'agencia' => array( 
  243. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  244. 'type' => 'text',  
  245. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ) 
  246. ),  
  247. 'conta' => array( 
  248. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  249. 'type' => 'text',  
  250. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ) 
  251. ),  
  252. 'convenio' => array( 
  253. 'title' => __( 'Agreement number', 'woocommerce-boleto' ),  
  254. 'type' => 'text',  
  255. 'description' => __( 'Agreements with 6, 7 or 8 digits.', 'woocommerce-boleto' ) 
  256. ),  
  257. 'contrato' => array( 
  258. 'title' => __( 'Contract number', 'woocommerce-boleto' ),  
  259. 'type' => 'text' 
  260. ),  
  261. 'carteira' => array( 
  262. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  263. 'type' => 'text' 
  264. ),  
  265. 'variacao_carteira' => array( 
  266. 'title' => __( 'Wallet variation (optional)', 'woocommerce-boleto' ),  
  267. 'type' => 'text',  
  268. 'description' => __( 'Wallet variation with dash.', 'woocommerce-boleto' ) 
  269. ),  
  270. 'formatacao_convenio' => array( 
  271. 'title' => __( 'Agreement format', 'woocommerce-boleto' ),  
  272. 'type' => 'select',  
  273. 'default' => '6',  
  274. 'options' => array( 
  275. '6' => __( 'Agreement with 6 digits', 'woocommerce-boleto' ),  
  276. '7' => __( 'Agreement with 7 dgitos', 'woocommerce-boleto' ),  
  277. '8' => __( 'Agreement with 8 dgitos', 'woocommerce-boleto' ),  
  278. ),  
  279. 'formatacao_nosso_numero' => array( 
  280. 'title' => __( 'Our number formatting', 'woocommerce-boleto' ),  
  281. 'type' => 'text',  
  282. 'description' => __( 'Used only for agreement with 6 digits (enter 1 for Our Number is up to 5 digits or 2 for option up to 17 digits).', 'woocommerce-boleto' ) 
  283. ); 
  284. break; 
  285. case 'bancoob' : 
  286. $fields = array( 
  287. 'agencia' => array( 
  288. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  289. 'type' => 'text',  
  290. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ) 
  291. ),  
  292. 'conta' => array( 
  293. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  294. 'type' => 'text',  
  295. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ) 
  296. ),  
  297. 'convenio' => array( 
  298. 'title' => __( 'Agreement number', 'woocommerce-boleto' ),  
  299. 'type' => 'text',  
  300. 'description' => __( 'Agreements with 6, 7 or 8 digits.', 'woocommerce-boleto' ) 
  301. ),  
  302. 'carteira' => array( 
  303. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  304. 'type' => 'text' 
  305. ),  
  306. ); 
  307. break; 
  308. case 'bradesco' : 
  309. $fields = array( 
  310. 'agencia' => array( 
  311. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  312. 'type' => 'text',  
  313. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ),  
  314. ),  
  315. 'agencia_dv' => array( 
  316. 'title' => __( 'Agency digit', 'woocommerce-boleto' ),  
  317. 'type' => 'text' 
  318. ),  
  319. 'conta' => array( 
  320. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  321. 'type' => 'text',  
  322. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ),  
  323. ),  
  324. 'conta_dv' => array( 
  325. 'title' => __( 'Account digit', 'woocommerce-boleto' ),  
  326. 'type' => 'text' 
  327. ),  
  328. 'conta_cedente' => array( 
  329. 'title' => __( 'Transferor account', 'woocommerce-boleto' ),  
  330. 'type' => 'text',  
  331. 'description' => __( 'Transferor account without digit (only numbers).', 'woocommerce-boleto' ),  
  332. ),  
  333. 'conta_cedente_dv' => array( 
  334. 'title' => __( 'Transferor account digit', 'woocommerce-boleto' ),  
  335. 'type' => 'text' 
  336. ),  
  337. 'carteira' => array( 
  338. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  339. 'type' => 'select',  
  340. 'default' => '03',  
  341. 'options' => array( 
  342. '03' => '03',  
  343. '06' => '06',  
  344. '09' => '09',  
  345. '25' => '25' 
  346. ); 
  347. break; 
  348. case 'cef' : 
  349. $fields = array( 
  350. 'agencia' => array( 
  351. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  352. 'type' => 'text',  
  353. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ) 
  354. ),  
  355. 'conta' => array( 
  356. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  357. 'type' => 'text',  
  358. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ) 
  359. ),  
  360. 'conta_dv' => array( 
  361. 'title' => __( 'Account digit', 'woocommerce-boleto' ),  
  362. 'type' => 'text' 
  363. ),  
  364. 'conta_cedente' => array( 
  365. 'title' => __( 'Transferor account', 'woocommerce-boleto' ),  
  366. 'type' => 'text',  
  367. 'description' => __( 'Transferor account without digit, use only numbers', 'woocommerce-boleto' ) 
  368. ),  
  369. 'conta_cedente_dv' => array( 
  370. 'title' => __( 'Transferor account digit', 'woocommerce-boleto' ),  
  371. 'type' => 'text' 
  372. ),  
  373. 'carteira' => array( 
  374. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  375. 'type' => 'select',  
  376. 'description' => __( 'Confirm this information with your manager.', 'woocommerce-boleto' ),  
  377. 'default' => 'SR',  
  378. 'options' => array( 
  379. 'SR' => __( 'Without registry', 'woocommerce-boleto' ),  
  380. 'CR' => __( 'With registry', 'woocommerce-boleto' ) 
  381. ),  
  382. 'inicio_nosso_numero' => array( 
  383. 'title' => __( 'Beginning of the Our Number', 'woocommerce-boleto' ),  
  384. 'type' => 'text',  
  385. 'description' => __( 'Use <code>80, 81 or 82</code> for <strong>Without registry</strong> or <code>90</code> for <strong>With registry</strong>. Confirm this information with your manager.', 'woocommerce-boleto' ),  
  386. 'default' => '80' 
  387. ); 
  388. break; 
  389. case 'cef_sigcb' : 
  390. $fields = array( 
  391. 'agencia' => array( 
  392. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  393. 'type' => 'text',  
  394. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ) 
  395. ),  
  396. 'conta' => array( 
  397. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  398. 'type' => 'text',  
  399. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ) 
  400. ),  
  401. 'conta_dv' => array( 
  402. 'title' => __( 'Account digit', 'woocommerce-boleto' ),  
  403. 'type' => 'text' 
  404. ),  
  405. 'conta_cedente' => array( 
  406. 'title' => __( 'Transferor account', 'woocommerce-boleto' ),  
  407. 'type' => 'text',  
  408. 'description' => __( 'Transferor account with 6 digits, use only numbers.', 'woocommerce-boleto' ) 
  409. ),  
  410. 'carteira' => array( 
  411. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  412. 'type' => 'select',  
  413. 'description' => __( 'Confirm this information with your manager.', 'woocommerce-boleto' ),  
  414. 'default' => 'SR',  
  415. 'options' => array( 
  416. 'SR' => __( 'Without registry', 'woocommerce-boleto' ),  
  417. 'CR' => __( 'With registry', 'woocommerce-boleto' ) 
  418. ); 
  419. break; 
  420. case 'cef_sinco' : 
  421. $fields = array( 
  422. 'agencia' => array( 
  423. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  424. 'type' => 'text',  
  425. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ) 
  426. ),  
  427. 'conta' => array( 
  428. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  429. 'type' => 'text',  
  430. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ),  
  431. ),  
  432. 'conta_dv' => array( 
  433. 'title' => __( 'Account digit', 'woocommerce-boleto' ),  
  434. 'type' => 'text' 
  435. ),  
  436. 'conta_cedente' => array( 
  437. 'title' => __( 'Transferor account', 'woocommerce-boleto' ),  
  438. 'type' => 'text',  
  439. 'description' => __( 'Transferor account without digit, use only numbers', 'woocommerce-boleto' ) 
  440. ),  
  441. 'conta_cedente_dv' => array( 
  442. 'title' => __( 'Transferor account digit', 'woocommerce-boleto' ),  
  443. 'type' => 'text' 
  444. ),  
  445. 'carteira' => array( 
  446. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  447. 'type' => 'select',  
  448. 'description' => __( 'Confirm this information with your manager.', 'woocommerce-boleto' ),  
  449. 'default' => 'SR',  
  450. 'options' => array( 
  451. 'SR' => __( 'Without registry', 'woocommerce-boleto' ),  
  452. 'CR' => __( 'With registry', 'woocommerce-boleto' ) 
  453. ),  
  454. ); 
  455. break; 
  456. case 'hsbc' : 
  457. $fields = array( 
  458. 'codigo_cedente' => array( 
  459. 'title' => __( 'Transferor code', 'woocommerce-boleto' ),  
  460. 'type' => 'text',  
  461. 'description' => __( 'Transferor code with only 7 digits.', 'woocommerce-boleto' ) 
  462. ),  
  463. 'carteira' => array( 
  464. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  465. 'type' => 'select',  
  466. 'description' => __( 'Accepts only CNR.', 'woocommerce-boleto' ),  
  467. 'default' => 'CNR',  
  468. 'options' => array( 
  469. 'CNR' => 'CNR' 
  470. ); 
  471. break; 
  472. case 'itau' : 
  473. $fields = array( 
  474. 'agencia' => array( 
  475. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  476. 'type' => 'text',  
  477. 'description' => __( 'Agency number.', 'woocommerce-boleto' ),  
  478. ),  
  479. 'conta' => array( 
  480. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  481. 'type' => 'text',  
  482. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ) 
  483. ),  
  484. 'conta_dv' => array( 
  485. 'title' => __( 'Account digit', 'woocommerce-boleto' ),  
  486. 'type' => 'text' 
  487. ),  
  488. 'carteira' => array( 
  489. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  490. 'type' => 'select',  
  491. 'default' => '104',  
  492. 'options' => array( 
  493. '104' => '104',  
  494. '109' => '109',  
  495. '157' => '157',  
  496. '174' => '174',  
  497. '175' => '175',  
  498. '178' => '178' 
  499. ); 
  500. break; 
  501. case 'nossacaixa' : 
  502. $fields = array( 
  503. 'agencia' => array( 
  504. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  505. 'type' => 'text',  
  506. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ) 
  507. ),  
  508. 'conta_cedente' => array( 
  509. 'title' => __( 'Transferor account', 'woocommerce-boleto' ),  
  510. 'type' => 'text',  
  511. 'description' => __( 'Transferor account without digit and with only 6 numbers.', 'woocommerce-boleto' ) 
  512. ),  
  513. 'conta_cedente_dv' => array( 
  514. 'title' => __( 'Transferor account digit', 'woocommerce-boleto' ),  
  515. 'type' => 'text' 
  516. ),  
  517. 'carteira' => array( 
  518. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  519. 'type' => 'select',  
  520. 'default' => '1',  
  521. 'options' => array( 
  522. '1' => __( 'Simple Billing (1)', 'woocommerce-boleto' ),  
  523. '5' => __( 'Direct Billing (5)', 'woocommerce-boleto' ) 
  524. ),  
  525. 'modalidade_conta' => array( 
  526. 'title' => __( 'Account modality', 'woocommerce-boleto' ),  
  527. 'type' => 'text',  
  528. 'description' => __( 'Account modality with two positions (example: 04).', 'woocommerce-boleto' ) 
  529. ); 
  530. break; 
  531. case 'real' : 
  532. $fields = array( 
  533. 'agencia' => array( 
  534. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  535. 'type' => 'text',  
  536. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ) 
  537. ),  
  538. 'conta' => array( 
  539. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  540. 'type' => 'text',  
  541. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ) 
  542. ),  
  543. 'carteira' => array( 
  544. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  545. 'type' => 'text' 
  546. ); 
  547. break; 
  548. case 'santander' : 
  549. $fields = array( 
  550. 'codigo_cliente' => array( 
  551. 'title' => __( 'Customer code', 'woocommerce-boleto' ),  
  552. 'type' => 'text',  
  553. 'description' => __( 'Customer code (PSK) with only 7 digits.', 'woocommerce-boleto' ) 
  554. ),  
  555. 'ponto_venda' => array( 
  556. 'title' => __( 'Sale point (Agency)', 'woocommerce-boleto' ),  
  557. 'type' => 'text',  
  558. 'description' => __( 'Agency number.', 'woocommerce-boleto' ) 
  559. ),  
  560. 'carteira' => array( 
  561. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  562. 'type' => 'text',  
  563. 'description' => __( 'Simple collection - Without registration.', 'woocommerce-boleto' ) 
  564. ),  
  565. 'carteira_descricao' => array( 
  566. 'title' => __( 'Wallet description', 'woocommerce-boleto' ),  
  567. 'type' => 'text',  
  568. 'default' => 'COBRANA SIMPLES - CSR' 
  569. ); 
  570. break; 
  571. case 'unibanco' : 
  572. $fields = array( 
  573. 'agencia' => array( 
  574. 'title' => __( 'Agency', 'woocommerce-boleto' ),  
  575. 'type' => 'text',  
  576. 'description' => __( 'Agency number without digit.', 'woocommerce-boleto' ) 
  577. ),  
  578. 'conta' => array( 
  579. 'title' => __( 'Account', 'woocommerce-boleto' ),  
  580. 'type' => 'text',  
  581. 'description' => __( 'Account number without digit.', 'woocommerce-boleto' ) 
  582. ),  
  583. 'conta_dv' => array( 
  584. 'title' => __( 'Account digit', 'woocommerce-boleto' ),  
  585. 'type' => 'text' 
  586. ),  
  587. 'codigo_cliente' => array( 
  588. 'title' => __( 'Customer code', 'woocommerce-boleto' ),  
  589. 'type' => 'text' 
  590. ),  
  591. 'carteira' => array( 
  592. 'title' => __( 'Wallet code', 'woocommerce-boleto' ),  
  593. 'type' => 'text' 
  594. ); 
  595. break; 
  596.  
  597. default : 
  598. $fields = array(); 
  599. break; 
  600.  
  601. return $fields; 
  602.  
  603. /** 
  604. * Process the payment and return the result. 
  605. * @param int $order_id Order ID. 
  606. * @return array Redirect. 
  607. */ 
  608. public function process_payment( $order_id ) { 
  609. $order = new WC_Order( $order_id ); 
  610.  
  611. // Mark as on-hold (we're awaiting the ticket). 
  612. $order->update_status( 'on-hold', __( 'Awaiting boleto payment', 'woocommerce-boleto' ) ); 
  613.  
  614. // Generates ticket data. 
  615. $this->generate_boleto_data( $order ); 
  616.  
  617. // Reduce stock levels. 
  618. $order->reduce_order_stock(); 
  619.  
  620. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) { 
  621. WC()->cart->empty_cart(); 
  622.  
  623. $url = $order->get_checkout_order_received_url(); 
  624. } else { 
  625. global $woocommerce; 
  626.  
  627. $woocommerce->cart->empty_cart(); 
  628.  
  629. $url = add_query_arg( 'key', $order->order_key, add_query_arg( 'order', $order_id, get_permalink( woocommerce_get_page_id( 'thanks' ) ) ) ); 
  630.  
  631. // Return thankyou redirect. 
  632. return array( 
  633. 'result' => 'success',  
  634. 'redirect' => $url 
  635. ); 
  636.  
  637. /** 
  638. * Output for the order received page. 
  639. * @return string Thank You message. 
  640. */ 
  641. public function thankyou_page() { 
  642. $html = '<div class="woocommerce-message">'; 
  643. $html .= sprintf( '<a class="button" href="%s" target="_blank" style="display: block !important; visibility: visible !important;">%s</a>', esc_url( wc_boleto_get_boleto_url( $_GET['key'] ) ), __( 'Pay the Ticket →', 'woocommerce-boleto' ) ); 
  644.  
  645. $message = sprintf( __( '%sAttention!%s You will not get the ticket by Correios.', 'woocommerce-boleto' ), '<strong>', '</strong>' ) . '<br />'; 
  646. $message .= __( 'Please click the following button and pay the Ticket in your Internet Banking.', 'woocommerce-boleto' ) . '<br />'; 
  647. $message .= __( 'If you prefer, print and pay at any bank branch or lottery retailer.', 'woocommerce-boleto' ) . '<br />'; 
  648.  
  649. $html .= apply_filters( 'wcboleto_thankyou_page_message', $message ); 
  650.  
  651. $html .= '<strong style="display: block; margin-top: 15px; font-size: 0.8em">' . sprintf( __( 'Validity of the Ticket: %s.', 'woocommerce-boleto' ), date( 'd/m/Y', time() + ( absint( $this->boleto_time ) * 86400 ) ) ) . '</strong>'; 
  652.  
  653. $html .= '</div>'; 
  654.  
  655. echo $html; 
  656.  
  657. /** 
  658. * Generate ticket data. 
  659. * @param object $order Order object. 
  660. */ 
  661. public function generate_boleto_data( $order ) { 
  662. // Ticket data. 
  663. $data = array(); 
  664. $data['nosso_numero'] = apply_filters( 'wcboleto_our_number', $order->id ); 
  665. $data['numero_documento'] = apply_filters( 'wcboleto_document_number', $order->id ); 
  666. $data['data_vencimento'] = date( 'd/m/Y', time() + ( absint( $this->boleto_time ) * 86400 ) ); 
  667. $data['data_documento'] = date( 'd/m/Y' ); 
  668. $data['data_processamento'] = date( 'd/m/Y' ); 
  669.  
  670. update_post_meta( $order->id, 'wc_boleto_data', $data ); 
  671.  
  672. /** 
  673. * Add content to the WC emails. 
  674. * @param object $order Order object. 
  675. * @param bool $sent_to_admin Send to admin. 
  676. * @return string Billet instructions. 
  677. */ 
  678. function email_instructions( $order, $sent_to_admin ) { 
  679. if ( $sent_to_admin || 'on-hold' !== $order->status || 'boleto' !== $order->payment_method ) { 
  680. return; 
  681.  
  682. $html = '<h2>' . __( 'Payment', 'woocommerce-boleto' ) . '</h2>'; 
  683.  
  684. $html .= '<p class="order_details">'; 
  685.  
  686. $message = sprintf( __( '%sAttention!%s You will not get the ticket by Correios.', 'woocommerce-boleto' ), '<strong>', '</strong>' ) . '<br />'; 
  687. $message .= __( 'Please click the following button and pay the Ticket in your Internet Banking.', 'woocommerce-boleto' ) . '<br />'; 
  688. $message .= __( 'If you prefer, print and pay at any bank branch or lottery retailer.', 'woocommerce-boleto' ) . '<br />'; 
  689.  
  690. $html .= apply_filters( 'wcboleto_email_instructions', $message ); 
  691.  
  692. $html .= '<br />' . sprintf( '<a class="button" href="%s" target="_blank">%s</a>', esc_url( wc_boleto_get_boleto_url( $order->order_key ) ), __( 'Pay the Ticket →', 'woocommerce-boleto' ) ) . '<br />'; 
  693.  
  694. $html .= '<strong style="font-size: 0.8em">' . sprintf( __( 'Validity of the Ticket: %s.', 'woocommerce-boleto' ), date( 'd/m/Y', time() + ( absint( $this->boleto_time ) * 86400 ) ) ) . '</strong>'; 
  695.  
  696. $html .= '</p>'; 
  697.  
  698. echo $html;