Order id? Didn't knew Blesta understood the concept of orders.
Only thing that gets passed to payment gateways is an array of invoices.
Serializing that, and passing that to a gateway is asking for trouble, because many gateways impose a character limit (especially European gateways, because they tend to include the transaction ID on customer's bank statement)
It may work fine during your testing while paying single invoices, but you risk that if a customer has a longer list of overdue invoices that he finally wants to pay, it will fail.
I proposed introducing a common database table for storing payment transaction information for this earlier, but the team didn't feel anything for that.
So yes, anyone wanting to properly implement a non-merchant payment gateway module will need to create their own...
Can use functions like this:
protected $gwname = "My gateway";
function install() { $r = new Record(); $r->setField("id", array('type' => "varchar", 'size' => 255)) ->setField("gateway", array('type' => "varchar", 'size' => 255)) ->setField("expire", array('type' => "datetime")) ->setField("value", array('type' => "text", 'is_null' => true)) ->setKey(array("id","gateway"), "primary") ->create("gateway_sessions", true); } protected function getSession($id) { $r = new Record(); $row = $r->select("value")->from("gateway_sessions") ->where("id", "=", $id) ->where("gateway", "=", $this->gwname)->fetch(PDO::FETCH_ASSOC); if ($row) return unserialize($row["value"]); else return false; } protected function putSession($id, $data) { $r = new Record(); $r->where("id", "=", $id) ->where("gateway", "=", $this->gwname) ->update("gateway_sessions", array("value" => serialize($data))); } protected function createSessionID() { $r = new Record(); $expires = date("Y-m-d H:i:s", time() + 86400 * 14); for ($try = 0; $try < 10; $try++) { try { $key = $this->_generateSessionKey(); $r->insert("gateway_sessions", array('id' => $key, 'gateway' => $this->gwname, 'expire' => $expires)); return $key; } catch (PDOException $e) { } } throw new Exception("Error creating session"); } protected function _generateSessionKey() { return dechex(time()).dechex(crypt_random()).dechex(crypt_random()); }
(Using an ID based on time, rather than an auto-increment, so that the number is unique, and doesn't start at 1 again if you reinstall Blesta, or if you use the same gateway with other software)