PageRenderTime 59ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/old_installation/code/administrator/components/com_virtuemart/classes/payment/ps_pagseguro.php

https://github.com/rafarubert/megafiltros
PHP | 85 lines | 80 code | 5 blank | 0 comment | 8 complexity | 7f996e216a08c629bfc9896a821b1b15 MD5 | raw file
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. class ps_pagseguro {
  4. var $classname = 'ps_pagseguro';
  5. var $payment_code = 'PGS';
  6. function show_configuration() {
  7. $configs = $this->configs();
  8. foreach($configs as $item)
  9. $this->trataInput($item);
  10. }
  11. function configs() {
  12. return $configs = array(
  13. array('name' => 'token', 'label' => 'Informação sobre seu TOKEN, que você consegue no site do pagseguro.'),
  14. array('name' => 'email', 'label' => 'O seu e-mail de login no PagSeguro'),
  15. array('name' => 'tipo_frete', 'label' => 'Tipo de frete', 'type' => 'select' , 'options' => array(
  16. 'EN' => 'PAC - Encomenda',
  17. 'SD' => 'Sedex',
  18. ))
  19. );
  20. }
  21. function trataInput($input) {
  22. require_once(CLASSPATH ."payment/".$this->classname.".cfg.php");
  23. if (!isset($input['type'])) $input['type'] = 'text';
  24. $input['id'] = "{$this->classname}_{$input['name']}";
  25. $code = $this->payment_code.'_'.strtoupper($input['name']);
  26. $code = defined($code) ? constant($code) : '';
  27. switch ($input['type']) {
  28. case 'select':
  29. $options = array();
  30. foreach($input['options'] as $k=>$v) {
  31. $options[] = sprintf('<option value="%s"%s>%s</option>', $k, ($k==$code ? ' selected="selected"': ''), $v);
  32. }
  33. printf ('<p><label for="%s">%s <select name="%s" id="%s">%s</select></label>',
  34. $input['id'],
  35. $input['label'],
  36. strtoupper($this->payment_code.'_'.$input['name']),
  37. $input['id'],
  38. implode("\n", $options)
  39. );
  40. break;
  41. default:
  42. printf ('<p><label for="%s">%s <input type="%s" name="%s" id="%s" value="%s" /></label></p>',
  43. $input['id'],
  44. $input['label'],
  45. $input['type'],
  46. strtoupper($this->payment_code.'_'.$input['name']),
  47. $input['id'],
  48. $code
  49. );
  50. }
  51. }
  52. function has_configuration() {
  53. return true;
  54. }
  55. function configfile_writeable() {
  56. return is_writeable( CLASSPATH."payment/".$this->classname.".cfg.php" );
  57. }
  58. function configfile_readable() {
  59. return is_readable( CLASSPATH."payment/".$this->classname.".cfg.php" );
  60. }
  61. function write_configuration( &$d ) {
  62. $configs = $this->configs();
  63. $config = "<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); \n\n";
  64. foreach($configs as $item) {
  65. $name = strtoupper($this->payment_code.'_'.$item['name']);
  66. $value = $d[$name];
  67. $config .= "define ('{$name}', '{$value}');\n";
  68. }
  69. if ($fp = fopen(CLASSPATH ."payment/".$this->classname.".cfg.php", "w")) {
  70. fputs($fp, $config, strlen($config));
  71. fclose ($fp);
  72. return true;
  73. } else {
  74. return false;
  75. }
  76. }
  77. function process_payment($order_number, $order_total, &$d) {
  78. return true;
  79. }
  80. }