Help in OCS / OJS payment plugin development

Dear Alec, dear all,
I’m trying to develop a new payment plugin for the Setefi - Monetaweb Italian Payment system for OCS, and I will try to port it in OJS.
I started with Paypal plugin and tried to customize that plugin, so I learned a lot of things on how OCS works internally, but I don’t know how to:

  • get current language settings of OCS interface
  • if OCS/OJS offers a facility to add to the PHP session some data

Can you help me?
Thanks in advance.

Looking for a confirmation about the second question:
Session::setSessionVar($key) Session::getSessionVar($key)

Am I right?
Or better:
$sessionManager =& SessionManager::getManager(); $session =& $sessionManager->getUserSession(); $myvar = $session->getSessionVar('$key');

Hi @netdiver,

Your last example has it right. Session::getSessionVar and Session::setSessionVar are equivalent to using $_SESSION, but are more “PKP-ish”.

To get the current locale, you can use AppLocale::getLocale().

Regards,
Alec Smecher
Public Knowledge Project Team

Thank you very much Alec.

Lorenzo a.k.a. netdiver

Dear Alec, dear all,
I have developed the main part of the payment plugin for OCS, copying the concept exposed in the paypal plugin, but I’m not able to make OCS create the needed table in database.
Is this the function needed to create the table?

function register($category, $path) { if (parent::register($category, $path)) { $this->addLocaleData(); $this->import('MonetaWebDAO'); $monetaWebDao = new MonetaWebDAO(); DAORegistry::registerDAO('MonetaWebDAO', $monetaWebDao); return true; } return false; }

I have also a schema file:
`

<!--
 *
 * TABLE monetaweb_transactions
 *
 -->
<table name="monetaweb_transactions">
	<field name="paymentid" type="C2" size="18">
		<KEY/>
	</field>
	<field name="securitycode" type="C2" size="32" />
	<field name="result" type="C2" size="20" />
	<field name="authorizationcode" type="C2" size="6" />
	<field name="merchantorderid" type="C2" size="18" />
	<field name="threedsecure" type="C2" size="1" />
	<field name="rrn" type="C2" size="12" />
	<field name="maskedpan" type="C2" size="19" />
	<field name="cardtype" type="C2" size="10" />
	<field name="cardcountry" type="C2" size="255" />
	<field name="cardexpirydate" type="C2" size="4" />
	<field name="customfield" type="C2" size="255" />
	<field name="status" type="C2" size="4" />
	<field name="payment_date" type="C2" size="127" />
	
	<descr>Monetaweb transactions</descr>
</table>

`

What’s wrong?

I installed the plugin providing a tar.gz file (BTW there are two bugs in the plugin installation routine that I fixed).
The plugin settings are correctly persisted in the database.

I think I’ve found the cause: reading code of
pages/manager/PluginManagementHandler.inc.php
at line 203 there is a comment:
// If plugin has an install.xml file, update database with it

So I think I need an install.xml file like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE install SYSTEM "../../../lib/pkp/dtd/install.dtd">
<!--
  * install.xml
  *
  * Copyright (c) 2016 Lorenzo Maurizi
  * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  *
  * Installation descriptor file.
  -->
  
<install version="1.0">
	<schema file="schema.xml"/>
</install>

Am I right?
How can I force table creation of plugin without uploading again the tar.gz file? I tried launching the upgrade.php script with upgrade option, but it only added email templates to database.

Hi @netdiver,

Have a look at the PayPal plugin for an example. It has a function like this:

 function getInstallSchemaFile() {
        return ($this->getPluginPath() . DIRECTORY_SEPARATOR . 'schema.xml');
}

When this function is present, it’ll cause the plugin install tools to create a schema according to schema.xml in the plugin’s directory. You can use the upgrade script to sync the descriptor without having to re-install the plugin.

Regards,
Alec Smecher
Public Knowledge Project Team

Thank you very much Alec for your reply, I have that function defined in my plugin from the first version, but the table is not created.
I kept the skeleton of the paypal plugin, so I have also a function getInstallEmailTemplatesFile() and a function getInstallEmailTemplateDataFile().

Uhm… it seems all is ok, I also checked mysql user permission to create tables, and it’s ok.

Any idea?

Hi @netdiver,

Hmm, I’m not sure from here. An alternate way of creating the schema is to use the schema tool:

 php tools/dbXMLtoSQL.php -schema execute path/to/schema.xml

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Thank you very much for the pointer to this cli tool, Alec!
I tried the “print” command with my schema and I obtained an empty response; then I tested the command with the paypal schema, and I obtained the SQL code, so I compared the two schema files, and, apart of the column names and number, the only difference was that in paypal schema the declaration was:
<schema version="0.2">
while in my file was
<schema version="0.1">

Changing to 0.2 the schema version in my file did the trick!
I don’t want to abuse your time, but can you explain why?

Thank you again for all!

Hi @netdiver,

That’s part of the ADODB schema management toolkit, which is implemented in lib/pkp/lib/adodb/adodb-xmlschema.inc.php. Versions 0.1 and 0.2 appear to have internal meanings, though I’m not specifically sure what they are. As you’ve noted, we use version 0.2.

Regards,
Alec Smecher
Public Knowledge Project Team