Page 1 of 1

Payment Module Template

Posted: Tue May 18, 2010 7:06 pm
by cstuder
Hello,

I've created a payment module template as starting point for new payment modules in 1.4.something:
Please have a look at the text file included for some additional informations about how to proceed. (Why is that so complicated? Well, I'm ranting over there...)

Bye,
christian

Re: Payment Module Template

Posted: Wed May 19, 2010 4:53 am
by Qphoria
Well the catalog view won't work as that is very much hardcoded to pp_standard.tpl

Actually, that I've already pretty much addressed in all of my payment modules. Instead of listing them out like the core ones:

Code: Select all

<form action="<?php echo $action; ?>" method="post" id="checkout">
  <input type="hidden" name="cmd" value="_xclick" />
  <input type="hidden" name="business" value="<?php echo $business; ?>" />
  <input type="hidden" name="item_name" value="<?php echo $item_name; ?>" />
  <input type="hidden" name="currency_code" value="<?php echo $currency_code; ?>" />
....
</form>
I use a simple array in the payment controller:

Code: Select all

$this->data['fields'] = array();
$this->data['fields']['cmd'] = '_cart';
$this->data['fields']['upload'] = '1';
$this->data['fields']['business'] = $this->config->get('pp_standard_email');
$this->data['fields']['currency_code'] = $currency; 
And then a simple for loop in the tpl:

Code: Select all

<form action="<?php echo $action; ?>" method="post" id="checkout">
  <?php foreach ($fields as $key => $value) { ?>
    <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>" />
  <?php } ?>
</form>
I used this template for ALL my payment modules except the ones that collect credit card data onsite, which i have a slightly different template. Tho with some simple changes the same template could be used for both.

And call it personal preference.... But I CAN'T STAND comments like this:

Code: Select all

/**
     * Module name
     * 
     * @var protected string $modulename
     */
    protected $modulename;
    
    /**
     * Class constructor
     * 
     * Determines current module name
     */
    public function __construct() {
        $this->modulename = basename(__FILE__, '.php');
    }
 
It makes me want to jab a fork in my eye. I know it is popular but it is absolutely horrendous.

What is wrong with a cleaner method:

Code: Select all

//Module name    
protected $modulename;
    
//Class constructor. Determines current module name
public function __construct() {
    $this->modulename = basename(__FILE__, '.php');
} 
even multiline comments looks much cleaner with:

Code: Select all

//Module name
//This is the name of the module
protected $modulename;
    
//Class constructor. Determines current module name
public function __construct() {
    $this->modulename = basename(__FILE__, '.php');
}  
Nobody should be that friendly with the asterisk key as php devs are

Re: Payment Module Template

Posted: Wed May 19, 2010 5:05 am
by Qphoria
The catalog model file and maybe the admin controller are pretty much the only ones that could be common, though there are sometimes other checks you might want to add there. For example, some payment gateways requires a single currency. So you can add a currency check to the model and set the status to disabled. I suppose that could be worked in other ways tho if it was standardized.

You could also probably extend the form loop method I use above to work with the admin view, though it would need to support passing in what "type" of field is used.

Re: Payment Module Template

Posted: Wed May 19, 2010 5:09 am
by Xsecrets
Qphoria wrote: And call it personal preference.... But I CAN'T STAND comments like this:

Code: Select all

/**
     * Module name
     * 
     * @var protected string $modulename
     */
    protected $modulename;
    
    /**
     * Class constructor
     * 
     * Determines current module name
     */
    public function __construct() {
        $this->modulename = basename(__FILE__, '.php');
    }
 
It makes me want to jab a fork in my eye. I know it is popular but it is absolutely horrendous.
It's called docblock and it's so popular because it allows you to run the code through something like phpDocumentor and autgenerate documentation.

Re: Payment Module Template

Posted: Wed May 19, 2010 12:25 pm
by Qphoria
So then its time to join the phpDocumenter team and fix their code for them :)

Re: Payment Module Template

Posted: Wed May 19, 2010 3:16 pm
by cstuder
Concerning the comments: Commenting class variables sucks, I know. Otherwise this is pretty much standard phpDoc. If you're using IDEs like Eclipse, this will provide you with instant documentation on methods, classes etc. Plus Eclipse does pretty much generate these comments automatically for you.

Like I said, this is a template and will not work out of the box. The catalog view has to be modified heavily according to the technical specifictions of the payment service provider.