WC_Moip_Gateway

WC Moip Gateway Class.

Defined (1)

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

/includes/class-wc-moip-gateway.php  
  1. class WC_Moip_Gateway extends WC_Payment_Gateway { 
  2.  
  3. /** 
  4. * Constructor for the gateway. 
  5. * @return void 
  6. */ 
  7. public function __construct() { 
  8.  
  9. $this->id = 'moip'; 
  10. $this->icon = apply_filters( 'woocommerce_moip_icon', plugins_url( 'assets/images/moip.png', plugin_dir_path( __FILE__ ) ) ); 
  11. $this->has_fields = false; 
  12. $this->method_title = __( 'Moip', 'woocommerce-moip' ); 
  13.  
  14. // Load the settings. 
  15. $this->init_form_fields(); 
  16. $this->init_settings(); 
  17.  
  18. // Display options. 
  19. $this->title = $this->get_option( 'title' ); 
  20. $this->description = $this->get_option( 'description' ); 
  21.  
  22. // Gateway options. 
  23. $this->login = $this->get_option( 'login' ); 
  24. $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' ); 
  25.  
  26. // API options. 
  27. $this->api = $this->get_option( 'api', 'html' ); 
  28. $this->token = $this->get_option( 'token' ); 
  29. $this->key = $this->get_option( 'key' ); 
  30.  
  31. // Payment methods. 
  32. $this->billet_banking = $this->get_option( 'billet_banking' ); 
  33. $this->credit_card = $this->get_option( 'credit_card' ); 
  34. $this->debit_card = $this->get_option( 'debit_card' ); 
  35. $this->moip_wallet = $this->get_option( 'moip_wallet' ); 
  36. $this->banking_debit = $this->get_option( 'banking_debit' ); 
  37. $this->financing_banking = $this->get_option( 'financing_banking' ); 
  38.  
  39. // Installments options. 
  40. $this->installments = $this->get_option( 'installments', 'no' ); 
  41. $this->installments_mininum = $this->get_option( 'installments_mininum', 2 ); 
  42. $this->installments_maxium = $this->get_option( 'installments_maxium', 12 ); 
  43. $this->installments_receipt = $this->get_option( 'installments_receipt', 'AVista' ); 
  44. $this->installments_interest = $this->get_option( 'installments_interest', 0 ); 
  45. $this->installments_rehearse = $this->get_option( 'installments_rehearse', 'no' ); 
  46.  
  47. // Billet options. 
  48. $this->billet = $this->get_option( 'billet', 'no' ); 
  49. $this->billet_type_term = $this->get_option( 'billet_type_term', 'no' ); 
  50. $this->billet_number_days = $this->get_option( 'billet_number_days', '7' ); 
  51. $this->billet_instruction_line1 = $this->get_option( 'billet_instruction_line1' ); 
  52. $this->billet_instruction_line2 = $this->get_option( 'billet_instruction_line2' ); 
  53. $this->billet_instruction_line3 = $this->get_option( 'billet_instruction_line3' ); 
  54. $this->billet_logo = $this->get_option( 'billet_logo' ); 
  55.  
  56. // Debug options. 
  57. $this->sandbox = $this->get_option( 'sandbox' ); 
  58. $this->debug = $this->get_option( 'debug' ); 
  59.  
  60. // Actions. 
  61. add_action( 'woocommerce_api_wc_moip_gateway', array( $this, 'check_ipn_response' ) ); 
  62. add_action( 'valid_moip_ipn_request', array( $this, 'successful_request' ) ); 
  63. add_action( 'woocommerce_receipt_moip', array( $this, 'receipt_page' ) ); 
  64. add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ), 9999 ); 
  65. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 
  66.  
  67. // Custom Thank You message. 
  68. if ( 'tc' == $this->api ) { 
  69. add_action( 'woocommerce_thankyou_moip', array( $this, 'transparent_checkout_thankyou_page' ) ); 
  70.  
  71. // Active logs. 
  72. if ( 'yes' == $this->debug ) { 
  73. if ( class_exists( 'WC_Logger' ) ) { 
  74. $this->log = new WC_Logger(); 
  75. } else { 
  76. $this->log = $this->woocommerce_instance()->logger(); 
  77.  
  78. // Display admin notices. 
  79. $this->admin_notices(); 
  80.  
  81. /** 
  82. * Backwards compatibility with version prior to 2.1. 
  83. * @return object Returns the main instance of WooCommerce class. 
  84. */ 
  85. protected function woocommerce_instance() { 
  86. if ( function_exists( 'WC' ) ) { 
  87. return WC(); 
  88. } else { 
  89. global $woocommerce; 
  90. return $woocommerce; 
  91.  
  92. /** 
  93. * Displays notifications when the admin has something wrong with the configuration. 
  94. * @return void 
  95. */ 
  96. protected function admin_notices() { 
  97. if ( is_admin() ) { 
  98. // Valid for use. 
  99. if ( 'html' != $this->api ) { 
  100. // Checks if token is not empty. 
  101. if ( empty( $this->token ) ) { 
  102. add_action( 'admin_notices', array( $this, 'token_missing_message' ) ); 
  103.  
  104. // Checks if key is not empty. 
  105. if ( empty( $this->key ) ) { 
  106. add_action( 'admin_notices', array( $this, 'key_missing_message' ) ); 
  107.  
  108. } else { 
  109. // Checks if login is not empty. 
  110. if ( empty( $this->login ) ) { 
  111. add_action( 'admin_notices', array( $this, 'login_missing_message' ) ); 
  112.  
  113. // Checks that the currency is supported 
  114. if ( ! $this->using_supported_currency() ) { 
  115. add_action( 'admin_notices', array( $this, 'currency_not_supported_message' ) ); 
  116.  
  117. /** 
  118. * Returns a bool that indicates if currency is amongst the supported ones. 
  119. * @return bool 
  120. */ 
  121. public function using_supported_currency() { 
  122. return ( 'BRL' == get_woocommerce_currency() ); 
  123.  
  124. /** 
  125. * Returns a value indicating the the Gateway is available or not. It's called 
  126. * automatically by WooCommerce before allowing customers to use the gateway 
  127. * for payment. 
  128. * @return bool 
  129. */ 
  130. public function is_available() { 
  131. // Test if is valid for use. 
  132. if ( 'html' != $this->api ) { 
  133. $api = ( ! empty( $this->token ) && ! empty( $this->key ) ); 
  134. } else { 
  135. $api = ( ! empty( $this->login ) ); 
  136.  
  137. $available = ( 'yes' == $this->settings['enabled'] ) && $api && $this->using_supported_currency(); 
  138.  
  139. return $available; 
  140.  
  141. /** 
  142. * Call plugin scripts in front-end. 
  143. * @return void 
  144. */ 
  145. public function scripts() { 
  146. if ( 'tc' == $this->api && is_checkout() ) { 
  147. wp_enqueue_style( 'wc-moip-checkout', plugins_url( 'assets/css/checkout.css', plugin_dir_path( __FILE__ ) ), array(), '', 'all' ); 
  148. wp_enqueue_script( 'jquery' ); 
  149. wp_enqueue_script( 'jquery-blockui' ); 
  150. wp_enqueue_script( 'wc-moip-checkout', plugins_url( 'assets/js/checkout.min.js', plugin_dir_path( __FILE__ ) ), array( 'jquery', 'jquery-blockui' ), '', true ); 
  151. wp_localize_script( 
  152. 'wc-moip-checkout',  
  153. 'woocommerce_moip_params',  
  154. array( 
  155. 'method_empty' => __( 'Please select a payment method.', 'woocommerce-moip' ),  
  156. 'processing' => __( 'Wait a few moments, your transaction is being processed...', 'woocommerce-moip' ),  
  157. 'redirecting' => sprintf( __( 'Thank you for your order, we will complete your order in %s seconds...', 'woocommerce-moip' ), '<span id="redirect-timer">10</span>' ),  
  158. 'ajax_url' => admin_url( 'admin-ajax.php' ),  
  159. 'security' => wp_create_nonce( 'woocommerce_moip_transparent_checkout' ),  
  160. 'ajax_fail' => __( 'There was an error in the request, please cancel the order and contact us to place your order.', 'woocommerce-moip' ),  
  161. 'at_sight' => __( 'at sight', 'woocommerce-moip' ),  
  162. 'of' => __( 'of', 'woocommerce-moip' ) 
  163. ); 
  164.  
  165. /** 
  166. * Admin Panel Options. 
  167. */ 
  168. public function admin_options() { 
  169. wp_enqueue_script( 'wc-moip', plugins_url( 'assets/js/admin.min.js', plugin_dir_path( __FILE__ ) ), array( 'jquery' ), '', true ); 
  170.  
  171. echo '<h3>' . __( 'Moip standard', 'woocommerce-moip' ) . '</h3>'; 
  172. echo '<p>' . __( 'Moip standard works by sending the user to Moip to enter their payment information.', 'woocommerce-moip' ) . '</p>'; 
  173.  
  174. // Generate the HTML For the settings form. 
  175. echo '<table class="form-table">'; 
  176. $this->generate_settings_html(); 
  177. echo '</table>'; 
  178.  
  179. /** 
  180. * Initialise Gateway Settings Form Fields. 
  181. * @return void 
  182. */ 
  183. public function init_form_fields() { 
  184. $this->form_fields = array( 
  185. 'enabled' => array( 
  186. 'title' => __( 'Enable/Disable', 'woocommerce-moip' ),  
  187. 'type' => 'checkbox',  
  188. 'label' => __( 'Enable Moip standard', 'woocommerce-moip' ),  
  189. 'default' => 'yes' 
  190. ),  
  191. 'title' => array( 
  192. 'title' => __( 'Title', 'woocommerce-moip' ),  
  193. 'type' => 'text',  
  194. 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-moip' ),  
  195. 'desc_tip' => true,  
  196. 'default' => __( 'Moip', 'woocommerce-moip' ) 
  197. ),  
  198. 'description' => array( 
  199. 'title' => __( 'Description', 'woocommerce-moip' ),  
  200. 'type' => 'textarea',  
  201. 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-moip' ),  
  202. 'default' => __( 'Pay via Moip', 'woocommerce-moip' ) 
  203. ),  
  204. 'login' => array( 
  205. 'title' => __( 'Moip Login', 'woocommerce-moip' ),  
  206. 'type' => 'text',  
  207. 'description' => __( 'Please enter your Moip email address or username; this is needed in order to take payment.', 'woocommerce-moip' ),  
  208. 'desc_tip' => true,  
  209. 'default' => '' 
  210. ),  
  211. 'invoice_prefix' => array( 
  212. 'title' => __( 'Invoice Prefix', 'woocommerce-moip' ),  
  213. 'type' => 'text',  
  214. 'description' => __( 'Please enter a prefix for your invoice numbers. If you use your Moip account for multiple stores ensure this prefix is unqiue as Moip will not allow orders with the same invoice number.', 'woocommerce-moip' ),  
  215. 'desc_tip' => true,  
  216. 'default' => 'WC-' 
  217. ),  
  218. 'api_section' => array( 
  219. 'title' => __( 'Payment API', 'woocommerce-moip' ),  
  220. 'type' => 'title',  
  221. 'description' => '',  
  222. ),  
  223. 'api' => array( 
  224. 'title' => __( 'Moip Payment API', 'woocommerce-moip' ),  
  225. 'type' => 'select',  
  226. 'description' => sprintf( __( 'The XML and Checkout Transparent requires Access Token and Access Key. %sHere\'s how to get this information%s.', 'woocommerce-moip' ), '<a href="https://labs.moip.com.br/blog/pergunta-do-usuario-como-obter-o-token-e-a-chave-de-acesso-da-api-do-moip/" target="_blank">', '</a>' ),  
  227. 'default' => 'form',  
  228. 'options' => array( 
  229. 'html' => __( 'HTML - Basic and less safe', 'woocommerce-moip' ),  
  230. 'xml' => __( 'XML - Safe and with more options', 'woocommerce-moip' ),  
  231. 'tc' => __( 'Transparent Checkout', 'woocommerce-moip' ) 
  232. ),  
  233. 'token' => array( 
  234. 'title' => __( 'Access Token', 'woocommerce-moip' ),  
  235. 'type' => 'text',  
  236. 'description' => __( 'Please enter your Access Token; this is needed in order to take payment.', 'woocommerce-moip' ),  
  237. 'desc_tip' => true,  
  238. 'default' => '' 
  239. ),  
  240. 'key' => array( 
  241. 'title' => __( 'Access Key', 'woocommerce-moip' ),  
  242. 'type' => 'text',  
  243. 'description' => __( 'Please enter your Access Key; this is needed in order to take payment.', 'woocommerce-moip' ),  
  244. 'desc_tip' => true,  
  245. 'default' => '' 
  246. ),  
  247. 'payment_section' => array( 
  248. 'title' => __( 'Payment Settings', 'woocommerce-moip' ),  
  249. 'type' => 'title',  
  250. 'description' => __( 'These options need to be available to you in your Moip account.', 'woocommerce-moip' ),  
  251. ),  
  252. 'billet_banking' => array( 
  253. 'title' => __( 'Billet Banking', 'woocommerce-moip' ),  
  254. 'type' => 'checkbox',  
  255. 'label' => __( 'Enable Billet Banking', 'woocommerce-moip' ),  
  256. 'default' => 'yes' 
  257. ),  
  258. 'credit_card' => array( 
  259. 'title' => __( 'Credit Card', 'woocommerce-moip' ),  
  260. 'type' => 'checkbox',  
  261. 'label' => __( 'Enable Credit Card', 'woocommerce-moip' ),  
  262. 'default' => 'yes' 
  263. ),  
  264. 'debit_card' => array( 
  265. 'title' => __( 'Debit Card', 'woocommerce-moip' ),  
  266. 'type' => 'checkbox',  
  267. 'label' => __( 'Enable Debit Card', 'woocommerce-moip' ),  
  268. 'description' => __( 'Not available for Transparent Checkout.', 'woocommerce-moip' ),  
  269. 'desc_tip' => true,  
  270. 'default' => 'yes' 
  271. ),  
  272. 'moip_wallet' => array( 
  273. 'title' => __( 'Moip Wallet', 'woocommerce-moip' ),  
  274. 'type' => 'checkbox',  
  275. 'label' => __( 'Enable Moip Wallet', 'woocommerce-moip' ),  
  276. 'description' => __( 'Not available for Transparent Checkout.', 'woocommerce-moip' ),  
  277. 'desc_tip' => true,  
  278. 'default' => 'yes' 
  279. ),  
  280. 'banking_debit' => array( 
  281. 'title' => __( 'Banking Debit', 'woocommerce-moip' ),  
  282. 'type' => 'checkbox',  
  283. 'label' => __( 'Enable Banking Debit', 'woocommerce-moip' ),  
  284. 'default' => 'yes' 
  285. ),  
  286. 'financing_banking' => array( 
  287. 'title' => __( 'Financing Banking', 'woocommerce-moip' ),  
  288. 'type' => 'checkbox',  
  289. 'label' => __( 'Enable Financing Banking', 'woocommerce-moip' ),  
  290. 'description' => __( 'Not available for Transparent Checkout.', 'woocommerce-moip' ),  
  291. 'desc_tip' => true,  
  292. 'default' => 'yes' 
  293. ),  
  294. 'installments_section' => array( 
  295. 'title' => __( 'Credit Card Installments Settings', 'woocommerce-moip' ),  
  296. 'type' => 'title',  
  297. 'description' => '',  
  298. ),  
  299. 'installments' => array( 
  300. 'title' => __( 'Installments settings', 'woocommerce-moip' ),  
  301. 'type' => 'checkbox',  
  302. 'label' => __( 'Enable Installments settings', 'woocommerce-moip' ),  
  303. 'default' => 'no' 
  304. ),  
  305. 'installments_mininum' => array( 
  306. 'title' => __( 'Minimum Installment', 'woocommerce-moip' ),  
  307. 'type' => 'select',  
  308. 'description' => __( 'Indicate the minimum installments.', 'woocommerce-moip' ),  
  309. 'desc_tip' => true,  
  310. 'default' => '2',  
  311. 'options' => array( 
  312. 2 => '2',  
  313. 3 => '3',  
  314. 4 => '4',  
  315. 5 => '5',  
  316. 6 => '6',  
  317. 7 => '7',  
  318. 8 => '8',  
  319. 9 => '9',  
  320. 10 => '10',  
  321. 11 => '11',  
  322. 12 => '12' 
  323. ),  
  324. 'installments_maxium' => array( 
  325. 'title' => __( 'Maximum Installment', 'woocommerce-moip' ),  
  326. 'type' => 'select',  
  327. 'description' => __( 'Indicate the Maximum installments.', 'woocommerce-moip' ),  
  328. 'desc_tip' => true,  
  329. 'default' => '12',  
  330. 'options' => array( 
  331. 2 => '2',  
  332. 3 => '3',  
  333. 4 => '4',  
  334. 5 => '5',  
  335. 6 => '6',  
  336. 7 => '7',  
  337. 8 => '8',  
  338. 9 => '9',  
  339. 10 => '10',  
  340. 11 => '11',  
  341. 12 => '12' 
  342. ),  
  343. 'installments_receipt' => array( 
  344. 'title' => __( 'Receipt', 'woocommerce-moip' ),  
  345. 'type' => 'select',  
  346. 'description' => __( 'If the installment payment will in at sight (subject to additional costs) in your account Moip (in one installment) or if it will be split (credited in the same number of parcels chosen by the payer).', 'woocommerce-moip' ),  
  347. 'desc_tip' => true,  
  348. 'default' => 'yes',  
  349. 'options' => array( 
  350. 'AVista' => __( 'At Sight', 'woocommerce-moip' ),  
  351. 'Parcelado' => __( 'Installments', 'woocommerce-moip' ),  
  352. ),  
  353. 'installments_interest' => array( 
  354. 'title' => __( 'Interest', 'woocommerce-moip' ),  
  355. 'type' => 'text',  
  356. 'description' => __( 'Interest to be applied to the installment.', 'woocommerce-moip' ),  
  357. 'desc_tip' => true,  
  358. 'placeholder' => '0.00',  
  359. 'default' => '' 
  360. ),  
  361. 'installments_rehearse' => array( 
  362. 'title' => __( 'Rehearse', 'woocommerce-moip' ),  
  363. 'type' => 'checkbox',  
  364. 'label' => __( 'Enable Rehearse', 'woocommerce-moip' ),  
  365. 'default' => 'no',  
  366. 'description' => __( 'Defines if the installment will be paid by the payer.', 'woocommerce-moip' ),  
  367. ),  
  368. 'billet_section' => array( 
  369. 'title' => __( 'Billet Settings', 'woocommerce-moip' ),  
  370. 'type' => 'title',  
  371. 'description' => '',  
  372. ),  
  373. 'billet' => array( 
  374. 'title' => __( 'Billet settings', 'woocommerce-moip' ),  
  375. 'type' => 'checkbox',  
  376. 'label' => __( 'Enable Billet settings', 'woocommerce-moip' ),  
  377. 'default' => 'no' 
  378. ),  
  379. 'billet_type_term' => array( 
  380. 'title' => __( 'Type of Term', 'woocommerce-moip' ),  
  381. 'type' => 'select',  
  382. 'description' => '',  
  383. 'default' => 'no',  
  384. 'options' => array( 
  385. 'no' => __( 'Default', 'woocommerce-moip' ),  
  386. 'Corridos' => __( 'Calendar Days', 'woocommerce-moip' ),  
  387. 'Uteis' => __( 'Working Days', 'woocommerce-moip' ) 
  388. ),  
  389. 'billet_number_days' => array( 
  390. 'title' => __( 'Number of Days', 'woocommerce-moip' ),  
  391. 'type' => 'text',  
  392. 'description' => __( 'Days of expiry of the billet after printed.', 'woocommerce-moip' ),  
  393. 'desc_tip' => true,  
  394. 'placeholder' => '7',  
  395. 'default' => '7' 
  396. ),  
  397. 'billet_instruction_line1' => array( 
  398. 'title' => __( 'Instruction Line 1', 'woocommerce-moip' ),  
  399. 'type' => 'text',  
  400. 'description' => __( 'First line instruction for the billet.', 'woocommerce-moip' ),  
  401. 'desc_tip' => true,  
  402. 'default' => '' 
  403. ),  
  404. 'billet_instruction_line2' => array( 
  405. 'title' => __( 'Instruction Line 2', 'woocommerce-moip' ),  
  406. 'type' => 'text',  
  407. 'description' => __( 'Second line instruction for the billet.', 'woocommerce-moip' ),  
  408. 'desc_tip' => true,  
  409. 'default' => '' 
  410. ),  
  411. 'billet_instruction_line3' => array( 
  412. 'title' => __( 'Instruction Line 3', 'woocommerce-moip' ),  
  413. 'type' => 'text',  
  414. 'description' => __( 'Third line instruction for the billet.', 'woocommerce-moip' ),  
  415. 'desc_tip' => true,  
  416. 'default' => '' 
  417. ),  
  418. 'billet_logo' => array( 
  419. 'title' => __( 'Custom Logo URL', 'woocommerce-moip' ),  
  420. 'type' => 'text',  
  421. 'description' => __( 'URL of the logo image to be shown on the billet.', 'woocommerce-moip' ),  
  422. 'desc_tip' => true,  
  423. 'default' => '' 
  424. ),  
  425. 'testing' => array( 
  426. 'title' => __( 'Gateway Testing', 'woocommerce-moip' ),  
  427. 'type' => 'title',  
  428. 'description' => '',  
  429. ),  
  430. 'sandbox' => array( 
  431. 'title' => __( 'Moip sandbox', 'woocommerce-moip' ),  
  432. 'type' => 'checkbox',  
  433. 'label' => __( 'Enable Moip sandbox', 'woocommerce-moip' ),  
  434. 'default' => 'no',  
  435. 'description' => sprintf( __( 'Moip sandbox can be used to test payments. Sign up for a developer account <a href="%s">here</a>.', 'woocommerce-moip' ), 'http://labs.moip.com.br/' ),  
  436. ),  
  437. 'debug' => array( 
  438. 'title' => __( 'Debug Log', 'woocommerce-moip' ),  
  439. 'type' => 'checkbox',  
  440. 'label' => __( 'Enable logging', 'woocommerce-moip' ),  
  441. 'default' => 'no',  
  442. 'description' => sprintf( __( 'Log Moip events, such as API requests, inside %s', 'woocommerce-moip' ), '<code>woocommerce/logs/moip-' . sanitize_file_name( wp_hash( 'moip' ) ) . '.txt</code>' ),  
  443. ); 
  444.  
  445. /** 
  446. * Add error message in checkout. 
  447. * @param string $message Error message. 
  448. * @return string Displays the error message. 
  449. */ 
  450. protected function add_error( $message ) { 
  451. if ( version_compare( WOOCOMMERCE_VERSION, '2.1', '>=' ) ) { 
  452. wc_add_notice( $message, 'error' ); 
  453. } else { 
  454. $this->woocommerce_instance()->add_error( $message ); 
  455.  
  456. /** 
  457. * Generate the args to form. 
  458. * @param object $order Order data. 
  459. * @return array Form arguments. 
  460. */ 
  461. public function get_form_args( $order ) { 
  462.  
  463. $args = array( 
  464. 'id_carteira' => $this->login,  
  465. 'valor' => str_replace( array( ', ', '.' ), '', $order->order_total ),  
  466. 'nome' => sanitize_text_field( get_bloginfo( 'name' ) ),  
  467.  
  468. // Sender info. 
  469. 'pagador_nome' => $order->billing_first_name . ' ' . $order->billing_last_name,  
  470. 'pagador_email' => $order->billing_email,  
  471. 'pagador_telefone' => str_replace( array( '(', '-', ' ', ')' ), '', $order->billing_phone ),  
  472. //'pagador_cpf' 
  473. //'pagador_celular' 
  474. //'pagador_sexo' 
  475. //'pagador_data_nascimento' 
  476.  
  477. // Address info. 
  478. 'pagador_logradouro' => $order->billing_address_1,  
  479. //'pagador_numero' 
  480. 'pagador_complemento' => $order->billing_address_2,  
  481. // 'pagador_bairro' 
  482. 'pagador_cep' => $order->billing_postcode,  
  483. 'pagador_cidade' => $order->billing_city,  
  484. 'pagador_estado' => $order->billing_state,  
  485. // 'pagador_pais' => $order->billing_country,  
  486.  
  487. // Payment Info. 
  488. 'id_transacao' => $this->invoice_prefix . $order->id,  
  489.  
  490. // Shipping info. 
  491. //'frete' 
  492. //'peso_compra' 
  493.  
  494. // Return 
  495. 'url_retorno' => $this->get_return_url( $order ),  
  496. ); 
  497.  
  498. // Cart Contents. 
  499. $item_names = array(); 
  500.  
  501. if ( sizeof( $order->get_items() ) > 0 ) { 
  502. foreach ( $order->get_items() as $item ) { 
  503. if ( $item['qty'] ) { 
  504. $item_names[] = $item['name'] . ' x ' . $item['qty']; 
  505.  
  506. $args['descricao'] = sprintf( __( 'Order %s', 'woocommerce-moip' ), $order->get_order_number() ) . ' - ' . implode( ', ', $item_names ); 
  507.  
  508. // Shipping Cost item. 
  509. if ( version_compare( WOOCOMMERCE_VERSION, '2.1', '>=' ) ) { 
  510. $shipping_total = $order->get_total_shipping(); 
  511. } else { 
  512. $shipping_total = $order->get_shipping(); 
  513.  
  514. if ( $shipping_total > 0 ) { 
  515. $args['descricao'] .= ', ' . __( 'Shipping via', 'woocommerce-moip' ) . ' ' . ucwords( $order->shipping_method_title ); 
  516.  
  517. $args = apply_filters( 'woocommerce_moip_args', $args, $order ); 
  518.  
  519. return $args; 
  520.  
  521. /** 
  522. * Generate XML payment args. 
  523. * @param object $order Order data. 
  524. * @return string Payment xml. 
  525. */ 
  526. protected function get_payment_xml( $order ) { 
  527. // Include the WC_Moip_Gateway class. 
  528. require_once plugin_dir_path( __FILE__ ) . 'class-wc-moip-simplexml.php'; 
  529.  
  530. $data = $this->get_form_args( $order ); 
  531.  
  532. $number = isset( $data['pagador_numero'] ) && ! empty( $data['pagador_numero'] ) ? $data['pagador_numero'] : 0; 
  533. $neighborhood = isset( $data['pagador_bairro'] ) && ! empty( $data['pagador_bairro'] ) ? $data['pagador_bairro'] : __( 'Not contained', 'woocommerce-moip' ); 
  534.  
  535. $xml = new WC_Moip_SimpleXML( '<?xml version="1.0" encoding="utf-8" ?><EnviarInstrucao></EnviarInstrucao>' ); 
  536. $instruction = $xml->addChild( 'InstrucaoUnica' ); 
  537. if ( 'tc' == $this->api ) { 
  538. $instruction->addAttribute( 'TipoValidacao', 'Transparente' ); 
  539. $instruction->addChild( 'Razao' )->addCData( $data['descricao'] ); 
  540. $values = $instruction->addChild( 'Valores' ); 
  541. $values->addChild( 'Valor', $order->order_total ); 
  542. $values->addAttribute( 'moeda', 'BRL' ); 
  543. $instruction->addChild( 'IdProprio', $data['id_transacao'] ); 
  544.  
  545. // Payer. 
  546. $payer = $instruction->addChild( 'Pagador' ); 
  547. $payer->addChild( 'Nome' )->addCData( $data['pagador_nome'] ); 
  548. $payer->addChild( 'Email', $data['pagador_email'] ); 
  549. $payer->addChild( 'IdPagador', $data['pagador_email'] ); 
  550.  
  551. // Address. 
  552. $address = $payer->addChild( 'EnderecoCobranca' ); 
  553. $address->addChild( 'Logradouro' )->addCData( $data['pagador_logradouro'] ); 
  554. $address->addChild( 'Numero', $number ); 
  555. $address->addChild( 'Bairro' )->addCData( $neighborhood ); 
  556. $address->addChild( 'Complemento' )->addCData( $data['pagador_complemento'] ); 
  557. $address->addChild( 'Cidade' )->addCData( $data['pagador_cidade'] ); 
  558. $address->addChild( 'Estado', $data['pagador_estado'] ); 
  559. $address->addChild( 'Pais', 'BRA' ); 
  560. $address->addChild( 'CEP', $data['pagador_cep'] ); 
  561. $address->addChild( 'TelefoneFixo', $data['pagador_telefone'] ); 
  562.  
  563. // Payment info. 
  564. $payment = $instruction->addChild( 'FormasPagamento' ); 
  565.  
  566. if ( 'yes' == $this->billet_banking ) { 
  567. $payment->addChild( 'FormaPagamento', 'BoletoBancario' ); 
  568.  
  569. // Billet settings. 
  570. if ( 'yes' == $this->billet ) { 
  571. $billet = $instruction->addChild( 'Boleto' ); 
  572. if ( 'no' != $billet->billet_type_term && ! empty( $this->billet_number_days ) ) { 
  573. $days = $billet->addChild( 'DiasExpiracao', (int) $this->billet_number_days ); 
  574. $days->addAttribute( 'Tipo', $this->billet_type_term ); 
  575.  
  576. if ( ! empty( $this->billet_instruction_line1 ) ) { 
  577. $billet->addChild( 'Instrucao1' )->addCData( $this->billet_instruction_line1 ); 
  578.  
  579. if ( ! empty( $this->billet_instruction_line2 ) ) { 
  580. $billet->addChild( 'Instrucao2' )->addCData( $this->billet_instruction_line2 ); 
  581.  
  582. if ( ! empty( $this->billet_instruction_line3 ) ) { 
  583. $billet->addChild( 'Instrucao3' )->addCData( $this->billet_instruction_line3 ); 
  584.  
  585. if ( ! empty( $this->billet_logo ) ) { 
  586. $billet->addChild( 'URLLogo', $this->billet_logo ); 
  587.  
  588. if ( 'yes' == $this->credit_card ) { 
  589. $payment->addChild( 'FormaPagamento', 'CartaoCredito' ); 
  590.  
  591. // Installments info. 
  592. if ( 'yes' == $this->installments ) { 
  593. $installments = $instruction->addChild( 'Parcelamentos' ); 
  594. $installment = $installments->addChild( 'Parcelamento' ); 
  595. $installment->addChild( 'MinimoParcelas', $this->installments_mininum ); 
  596. $installment->addChild( 'MaximoParcelas', $this->installments_maxium ); 
  597. $installment->addChild( 'Recebimento', $this->installments_receipt ); 
  598.  
  599. if ( ! empty( $this->installments_interest ) && $this->installments_interest > 0 ) { 
  600. $installment->addChild( 'Juros', str_replace( ', ', '.', $this->installments_interest ) ); 
  601.  
  602. if ( 'AVista' == $this->installments_receipt ) { 
  603. $rehearse = ( 'yes' == $this->installments_rehearse ) ? 'true' : 'false'; 
  604. $installment->addChild( 'Repassar', $rehearse ); 
  605.  
  606. if ( 'yes' == $this->debit_card ) { 
  607. $payment->addChild( 'FormaPagamento', 'CartaoDebito' ); 
  608.  
  609. if ( 'yes' == $this->moip_wallet ) { 
  610. $payment->addChild( 'FormaPagamento', 'CarteiraMoip' ); 
  611.  
  612. if ( 'yes' == $this->banking_debit ) { 
  613. $payment->addChild( 'FormaPagamento', 'DebitoBancario' ); 
  614.  
  615. if ( 'yes' == $this->financing_banking ) { 
  616. $payment->addChild( 'FormaPagamento', 'FinanciamentoBancario' ); 
  617.  
  618. // Notification URL. 
  619. $instruction->addChild( 'URLNotificacao', home_url( '/?wc-api=WC_Moip_Gateway' ) ); 
  620.  
  621. // Return URL. 
  622. $instruction->addChild( 'URLRetorno' )->addCData( $this->get_return_url( $order ) ); 
  623.  
  624. $xml = apply_filters( 'woocommerce_moip_xml', $xml, $order ); 
  625.  
  626. return $xml->asXML(); 
  627.  
  628. /** 
  629. * Gets the Moip Payment Token 
  630. * @param object $order Order data. 
  631. * @return string Payment token. 
  632. */ 
  633. protected function create_payment_token( $order ) { 
  634. $xml = $this->get_payment_xml( $order ); 
  635.  
  636. if ( 'yes' == $this->debug ) { 
  637. $this->log->add( 'moip', 'Requesting token for order ' . $order->get_order_number() . ' with the following data: ' . $xml ); 
  638.  
  639. if ( 'yes' == $this->sandbox ) { 
  640. $url = 'https://desenvolvedor.moip.com.br/sandbox/ws/alpha/EnviarInstrucao/Unica'; 
  641. } else { 
  642. $url = 'https://www.moip.com.br/ws/alpha/EnviarInstrucao/Unica'; 
  643.  
  644. $params = array( 
  645. 'method' => 'POST',  
  646. 'body' => $xml,  
  647. 'sslverify' => false,  
  648. 'timeout' => 60,  
  649. 'headers' => array( 
  650. 'Expect' => '',  
  651. 'Content-Type' => 'application/xml;charset=UTF-8',  
  652. 'Authorization' => 'Basic ' . base64_encode( $this->token . ':' . $this->key ) 
  653. ); 
  654.  
  655. $response = wp_remote_post( $url, $params ); 
  656.  
  657. if ( is_wp_error( $response ) ) { 
  658. if ( 'yes' == $this->debug ) { 
  659. $this->log->add( 'moip', 'WP_Error: ' . $response->get_error_message() ); 
  660. } elseif ( $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) { 
  661. $body = new SimpleXmlElement( $response['body'], LIBXML_NOCDATA ); 
  662.  
  663. if ( 'Sucesso' == $body->Resposta->Status ) { 
  664. if ( 'yes' == $this->debug ) { 
  665. $this->log->add( 'moip', 'Moip Payment Token created with success! The Token is: ' . $body->Resposta->Token ); 
  666.  
  667. return esc_attr( (string) $body->Resposta->Token ); 
  668. } else { 
  669. if ( 'yes' == $this->debug ) { 
  670. $this->log->add( 'moip', 'Failed to generate the Moip Payment Token: ' . print_r( $body->Resposta->Erro, true ) ); 
  671.  
  672. foreach ( $body->Resposta->Erro as $error ) { 
  673. $this->add_error( '<strong>Moip</strong>: ' . esc_attr( (string) $error ) ); 
  674.  
  675. } else { 
  676. if ( 'yes' == $this->debug ) { 
  677. $this->log->add( 'moip', 'Failed to generate the Moip Payment Token, the status was: ' . $response['response']['code'] . ' - ' . $response['response']['message'] . '. With the content: ' . $response['body'] ); 
  678.  
  679. return false; 
  680.  
  681. /** 
  682. * Generate the form. 
  683. * @param int $order_id Order ID. 
  684. * @return string Payment form. 
  685. */ 
  686. protected function generate_form( $order_id ) { 
  687. $order = new WC_Order( $order_id ); 
  688.  
  689. $args = $this->get_form_args( $order ); 
  690.  
  691. if ( 'yes' == $this->debug ) { 
  692. $this->log->add( 'moip', 'Payment arguments for order ' . $order->get_order_number() . ': ' . print_r( $args, true ) ); 
  693.  
  694. $args_array = array(); 
  695.  
  696. foreach ( $args as $key => $value ) { 
  697. $args_array[] = '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '" />'; 
  698.  
  699. if ( version_compare( WOOCOMMERCE_VERSION, '2.1', '>=' ) ) { 
  700. wc_enqueue_js( ' 
  701. jQuery.blockUI({ 
  702. message: "' . esc_js( __( 'Thank you for your order. We are now redirecting you to Moip to make payment.', 'woocommerce-moip' ) ) . '",  
  703. baseZ: 99999,  
  704. overlayCSS: { 
  705. background: "#fff",  
  706. opacity: 0.6 
  707. },  
  708. css: { 
  709. padding: "20px",  
  710. zindex: "9999999",  
  711. textAlign: "center",  
  712. color: "#555",  
  713. border: "3px solid #aaa",  
  714. backgroundColor:"#fff",  
  715. cursor: "wait",  
  716. lineHeight: "24px",  
  717. }); 
  718. jQuery("#submit-payment-form").click(); 
  719. ' ); 
  720. } else { 
  721. $this->woocommerce_instance()->add_inline_js( ' 
  722. jQuery("body").block({ 
  723. message: "' . esc_js( __( 'Thank you for your order. We are now redirecting you to Moip to make payment.', 'woocommerce-moip' ) ) . '",  
  724. overlayCSS: { 
  725. background: "#fff",  
  726. opacity: 0.6 
  727. },  
  728. css: { 
  729. padding: "20px",  
  730. zIndex: "9999999",  
  731. textAlign: "center",  
  732. color: "#555",  
  733. border: "3px solid #aaa",  
  734. backgroundColor: "#fff",  
  735. cursor: "wait",  
  736. lineHeight: "24px",  
  737. }); 
  738. jQuery("#submit-payment-form").click(); 
  739. ' ); 
  740.  
  741. // Payment URL or Sandbox URL. 
  742. if ( 'yes' == $this->sandbox ) { 
  743. $payment_url = 'https://desenvolvedor.moip.com.br/sandbox/PagamentoMoIP.do'; 
  744. } else { 
  745. $payment_url = 'https://www.moip.com.br/PagamentoMoIP.do'; 
  746.  
  747. $html = '<p>' . __( 'Thank you for your order, please click the button below to pay with Moip.', 'woocommerce-moip' ) . '</p>'; 
  748.  
  749. $html .= '<form action="' . esc_url( $payment_url ) . '" method="post" id="payment-form" accept-charset="ISO-8859-1" target="_top"> 
  750. ' . implode( '', $args_array ) . ' 
  751. <a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">' . __( 'Cancel order & restore cart', 'woocommerce-moip' ) . '</a> <input type="submit" class="button alt" id="submit-payment-form" value="' . __( 'Pay via Moip', 'woocommerce-moip' ) . '" /> 
  752. </form>'; 
  753.  
  754. return $html; 
  755.  
  756. /** 
  757. * Generate the form. 
  758. * @param int $order_id Order ID. 
  759. * @return string Payment form. 
  760. */ 
  761. protected function generate_transparent_checkout( $order_id ) { 
  762. $order = new WC_Order( $order_id ); 
  763.  
  764. $token = $this->create_payment_token( $order ); 
  765.  
  766. if ( 'yes' == $this->debug ) { 
  767. $this->log->add( 'moip', 'Generating transparent checkout for order ' . $order->get_order_number() ); 
  768.  
  769. if ( $token ) { 
  770. $holder_default = apply_filters( 'woocommerce_moip_holder_data', array( 
  771. 'name' => $order->billing_first_name . ' ' . $order->billing_last_name,  
  772. 'birthdate_day' => '',  
  773. 'birthdate_month' => '',  
  774. 'birthdate_year' => '',  
  775. 'phone' => $order->billing_phone,  
  776. 'cpf' => '' 
  777. ), $order ); 
  778.  
  779. if ( 'yes' == $this->sandbox ) { 
  780. $url = 'https://desenvolvedor.moip.com.br/sandbox/Instrucao.do?token=' . $token; 
  781. } else { 
  782. $url = 'https://www.moip.com.br/Instrucao.do?token=' . $token; 
  783.  
  784. ob_start(); 
  785. include plugin_dir_path( dirname( __FILE__ ) ) . 'templates/transparent-checkout.php'; 
  786. $html = ob_get_clean(); 
  787.  
  788. return $html; 
  789. } else { 
  790. // Display message if a problem occurs. 
  791. $html = '<p>' . __( 'An error has occurred while processing your payment, please try again. Or contact us for assistance.', 'woocommerce-moip' ) . '</p>'; 
  792. $html .= '<a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">' . __( 'Click to try again', 'woocommerce-moip' ) . '</a>'; 
  793.  
  794. return $html; 
  795.  
  796. /** 
  797. * Process the payment and return the result. 
  798. * @param int $order_id Order ID. 
  799. * @return array Redirect. 
  800. */ 
  801. public function process_payment( $order_id ) { 
  802.  
  803. $order = new WC_Order( $order_id ); 
  804.  
  805. if ( 'xml' == $this->api ) { 
  806.  
  807. $token = $this->create_payment_token( $order ); 
  808.  
  809. if ( $token ) { 
  810. if ( 'yes' == $this->sandbox ) { 
  811. $url = 'https://desenvolvedor.moip.com.br/sandbox/Instrucao.do?token=' . $token; 
  812. } else { 
  813. $url = 'https://www.moip.com.br/Instrucao.do?token=' . $token; 
  814.  
  815. return array( 
  816. 'result' => 'success',  
  817. 'redirect' => $url 
  818. ); 
  819. } else { 
  820. if ( version_compare( WOOCOMMERCE_VERSION, '2.1', '>=' ) ) { 
  821. return array( 
  822. 'result' => 'success',  
  823. 'redirect' => $order->get_checkout_payment_url( true ) 
  824. ); 
  825. } else { 
  826. return array( 
  827. 'result' => 'success',  
  828. 'redirect' => add_query_arg( 'order', $order->id, add_query_arg( 'key', $order->order_key, get_permalink( woocommerce_get_page_id( 'pay' ) ) ) ) 
  829. ); 
  830.  
  831. /** 
  832. * Output for the order received page. 
  833. * @param object $order Order data. 
  834. * @return void 
  835. */ 
  836. public function receipt_page( $order ) { 
  837. if ( 'tc' == $this->api ) { 
  838. echo $this->generate_transparent_checkout( $order ); 
  839. } else { 
  840. echo $this->generate_form( $order ); 
  841.  
  842. /** 
  843. * Check API Response. 
  844. * @return void 
  845. */ 
  846. public function check_ipn_response() { 
  847. @ob_clean(); 
  848.  
  849. if ( isset( $_POST['id_transacao'] ) ) { 
  850. header( 'HTTP/1.0 200 OK' ); 
  851. do_action( 'valid_moip_ipn_request', stripslashes_deep( $_POST ) ); 
  852. } else { 
  853. wp_die( __( 'Moip Request Failure', 'woocommerce-moip' ) ); 
  854.  
  855. /** 
  856. * Successful Payment! 
  857. * @param array $posted Moip post data. 
  858. * @return void 
  859. */ 
  860. public function successful_request( $posted ) { 
  861.  
  862. if ( ! empty( $posted['id_transacao'] ) ) { 
  863. $order_key = $posted['id_transacao']; 
  864. $order_id = (int) str_replace( $this->invoice_prefix, '', $order_key ); 
  865.  
  866. $order = new WC_Order( $order_id ); 
  867.  
  868. // Checks whether the invoice number matches the order. 
  869. // If true processes the payment. 
  870. if ( $order->id === $order_id ) { 
  871.  
  872. if ( 'yes' == $this->debug ) { 
  873. $this->log->add( 'moip', 'Payment status from order ' . $order->get_order_number() . ': ' . $posted['status_pagamento'] ); 
  874.  
  875. switch ( $posted['status_pagamento'] ) { 
  876. case '1': 
  877. // Order details. 
  878. if ( ! empty( $posted['cod_moip'] ) ) { 
  879. update_post_meta( 
  880. $order_id,  
  881. __( 'Moip Transaction ID', 'woocommerce-moip' ),  
  882. $posted['cod_moip'] 
  883. ); 
  884. if ( ! empty( $posted['email_consumidor'] ) ) { 
  885. update_post_meta( 
  886. $order_id,  
  887. __( 'Payer email', 'woocommerce-moip' ),  
  888. $posted['email_consumidor'] 
  889. ); 
  890. if ( ! empty( $posted['tipo_pagamento'] ) ) { 
  891. update_post_meta( 
  892. $order_id,  
  893. __( 'Payment type', 'woocommerce-moip' ),  
  894. $posted['tipo_pagamento'] 
  895. ); 
  896. if ( ! empty( $posted['parcelas'] ) ) { 
  897. update_post_meta( 
  898. $order_id,  
  899. __( 'Number of parcels', 'woocommerce-moip' ),  
  900. $posted['parcelas'] 
  901. ); 
  902.  
  903. // Payment completed. 
  904. $order->add_order_note( __( 'Moip: Payment has already been made but not yet credited to Carteira Moip.', 'woocommerce-moip' ) ); 
  905. $order->payment_complete(); 
  906.  
  907. break; 
  908. case '2': 
  909. $order->update_status( 'on-hold', __( 'Moip: Payment under review.', 'woocommerce-moip' ) ); 
  910.  
  911. break; 
  912. case '3': 
  913. $order->update_status( 'on-hold', __( 'Moip: Billet was printed and has not been paid yet.', 'woocommerce-moip' ) ); 
  914.  
  915. break; 
  916. case '4': 
  917. $order->add_order_note( __( 'Moip: Payment completed and credited in your Carteira Moip.', 'woocommerce-moip' ) ); 
  918.  
  919. break; 
  920. case '5': 
  921. $order->update_status( 'cancelled', __( 'Moip: Payment canceled.', 'woocommerce-moip' ) ); 
  922.  
  923. break; 
  924. case '6': 
  925. $order->update_status( 'on-hold', __( 'Moip: Payment under review.', 'woocommerce-moip' ) ); 
  926.  
  927. break; 
  928. case '7': 
  929. $order->update_status( 'refunded', __( 'Moip: Payment was reversed by the payer, payee, payment institution or Moip.', 'woocommerce-moip' ) ); 
  930.  
  931. break; 
  932.  
  933. default: 
  934. // No action xD. 
  935. break; 
  936.  
  937. do_action( 'woocommerce_moip_after_successful_request', $order, $posted ); 
  938.  
  939. /** 
  940. * Transparent checkout custom Thank You message. 
  941. * @return void 
  942. */ 
  943. public function transparent_checkout_thankyou_page() { 
  944. $order_id = woocommerce_get_order_id_by_order_key( esc_attr( $_GET['key'] ) ); 
  945. $method = get_post_meta( $order_id, 'woocommerce_moip_method', true ); 
  946.  
  947. switch ( $method ) { 
  948. case 'CartaoCredito': 
  949.  
  950. $html = '<div class="woocommerce-message">'; 
  951. $message = WC_Moip_Messages::credit_cart_message( get_post_meta( $order_id, 'woocommerce_moip_status', true ), get_post_meta( $order_id, 'woocommerce_moip_code', true ) ); 
  952. $html .= apply_filters( 'woocommerce_moip_thankyou_creditcard_message', $message, $order_id ); 
  953. $html .= '</div>'; 
  954.  
  955. break; 
  956. case 'DebitoBancario': 
  957.  
  958. $html = '<div class="woocommerce-message">'; 
  959. $html .= sprintf( '<a class="button" href="%s" target="_blank">%s</a>', get_post_meta( $order_id, 'woocommerce_moip_url', true ), __( 'Pay the order →', 'woocommerce-moip' ) ); 
  960. $message = WC_Moip_Messages::debit_message(); 
  961. $html .= apply_filters( 'woocommerce_moip_thankyou_debit_message', $message, $order_id ); 
  962. $html .= '</div>'; 
  963.  
  964. break; 
  965. case 'BoletoBancario': 
  966.  
  967. $html = '<div class="woocommerce-message">'; 
  968. $html .= sprintf( '<a class="button" href="%s" target="_blank">%s</a>', get_post_meta( $order_id, 'woocommerce_moip_url', true ), __( 'Print the billet →', 'woocommerce-moip' ) ); 
  969. $message = WC_Moip_Messages::billet_message(); 
  970. $html .= apply_filters( 'woocommerce_moip_thankyou_billet_message', $message, $order_id ); 
  971. $html .= '</div>'; 
  972.  
  973. break; 
  974.  
  975. default: 
  976. $html = ''; 
  977. break; 
  978.  
  979. echo $html; 
  980.  
  981. /** 
  982. * Gets the admin url. 
  983. * @return string 
  984. */ 
  985. protected function admin_url() { 
  986. if ( version_compare( WOOCOMMERCE_VERSION, '2.1', '>=' ) ) { 
  987. return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_moip_gateway' ); 
  988.  
  989. return admin_url( 'admin.php?page=woocommerce_settings&tab=payment_gateways§ion=WC_Moip_Gateway' ); 
  990.  
  991. /** 
  992. * Adds error message when not configured the email or username. 
  993. * @return string Error Mensage. 
  994. */ 
  995. public function login_missing_message() { 
  996. echo '<div class="error"><p><strong>' . __( 'Moip Disabled', 'woocommerce-moip' ) . '</strong>: ' . sprintf( __( 'You should inform your email address. %s', 'woocommerce-moip' ), '<a href="' . $this->admin_url() . '">' . __( 'Click here to configure!', 'woocommerce-moip' ) . '</a>' ) . '</p></div>'; 
  997.  
  998. /** 
  999. * Adds error message when not configured the token. 
  1000. * @return string Error Mensage. 
  1001. */ 
  1002. public function token_missing_message() { 
  1003. echo '<div class="error"><p><strong>' . __( 'Moip Disabled', 'woocommerce-moip' ) . '</strong>: ' . sprintf( __( 'You should inform your Access Token. %s', 'woocommerce-moip' ), '<a href="' . $this->admin_url() . '">' . __( 'Click here to configure!', 'woocommerce-moip' ) . '</a>' ) . '</p></div>'; 
  1004.  
  1005. /** 
  1006. * Adds error message when not configured the key. 
  1007. * @return string Error Mensage. 
  1008. */ 
  1009. public function key_missing_message() { 
  1010. echo '<div class="error"><p><strong>' . __( 'Moip Disabled', 'woocommerce-moip' ) . '</strong>: ' . sprintf( __( 'You should inform your Access Key. %s', 'woocommerce-moip' ), '<a href="' . $this->admin_url() . '">' . __( 'Click here to configure!', 'woocommerce-moip' ) . '</a>' ) . '</p></div>'; 
  1011.  
  1012. /** 
  1013. * Adds error message when an unsupported currency is used. 
  1014. * @return string Error Mensage. 
  1015. */ 
  1016. public function currency_not_supported_message() { 
  1017. echo '<div class="error"><p><strong>' . __( 'Moip Disabled', 'woocommerce-moip' ) . '</strong>: ' . sprintf( __( 'Currency <code>%s</code> is not supported. Works only with <code>BRL</code> (Brazilian Real).', 'woocommerce-moip' ), get_woocommerce_currency() ) . '</p></div>';