Jump to content

Black-Xstar

Members
  • Posts

    10
  • Joined

  • Last visited

Posts posted by Black-Xstar

  1. Your solution suffers from the same serialization problem.

     

    A better solution would be something like:

     

    gateway_sessions

    uuid, gateway_id, expire_date

     

    gateway_session_invoices

    gateway_session_uuid, invoice_id, amount

     

    Then you simply pass the uuid to the gateway and read it back on the response.

    Thanks.

    How do I access database? Can I use install() method to init the DB?

  2.  

    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)

     

     

    Thank you! That is exactly I am asking.

    I will try you code snippet. Thanks again!

  3. @serge: you are right, sorry for my typo.

     

     

    Blesta only provides amount and invoices array to buildProcess():

    * @param float $amount The amount to charge this contact
    * @param array $invoice_amounts An array of invoices

    I can't serialize the array and send to gateway because gateway only accept integers.

    So I need a DB/table to save (id, invoices array) pair. When the blesta receive id from gateway, I can mark those invoices as paid.

     

    Using order ID is a good idea. But if people renew their services or just add credit to account, how can I get this order ID?

     

    PS: I know what is transaction identifier but I am not talking about the transaction identifier.

     

    Thanks.

  4. Since blesta doesn't offer unique ID for each payment. I have to use another database to save the unique ID.

    So, how to do it? I need create a table when payment gateway activated and run query inside the gateway functions.

     

    Here is my scene:

    1) buildProcess() will generate unique ID and save (id, invoices array) pair to database as well as send unique ID to payment gateway.

    2) User pay at gateway's website and back to blesta. Gateway will send data to blesta return_url.

    3) success() will receive GET data from payment gateway. The data included same unique ID above and transaction identifier generated by gateway.

    4) To get the invoices array from database by using unique ID mark those invoices as paid.

  5. If I understand that correctly, that function simply checks whether a transaction exists given the transaction ID from the gateway. You could perform a similar check by calling Transactions::getByTransactionId().

     

    However, I don't think that is necessary, as Blesta already does this and simply updates the existing transaction if you had received multiple responses from the gateway for the same transaction.

     

    Yes. Just a simple check function. Can you provide a example by using getByTransactionId()? Thanks.

     

    I know blesta won't record same transaction to database. But it sent 'Payment Received' email (blesta.url/admin/tools/logs/email/) every time when it received a call back request :(

  6. I want the callback URL return a "success" message to gateway directly. It can NOT be a new GET request from blesta.

     

    Because if the callback URL don't return a "success" message, the gateway will keep POST to callback URL every hour.

     

    UPDATE: I figured out. Just add echo "success" to public function validate(array $get, array $post) {} will do the trick.

     

     

     

     

    Another question:

    Is there any way to check callback already recorded? Like checkCbTransID($transid) in WHMCS: http://docs.whmcs.com/Gateway_Module_Developer_Docs#Callbacks

  7. I am developing a non merchant gateway.

     

    I followed the demo here: https://github.com/phillipsdata/blesta_sdk/blob/master/components/gateways/nonmerchant/nonmerchant_demo/nonmerchant_demo.php

     

    This function:

    public function validate(array $get, array $post) {}

    Will handle the gateway callback.

     

    If the blesta received the callback (HTTP Request), how to return a HTTP Response to gateway?

    For example, the gateway posted data ($_POST) to callback url, it should return text 'success' to gateway, so the gateway will not post again.

     

    If the blesta can not return anything to gateway, how to check this transaction already recorded? Because the gateway may post many times.

    For example, in WHMCS, I can use checkCbTransID($transid) to do it: http://docs.whmcs.com/Gateway_Module_Developer_Docs#Callbacks

     

    Thanks.

×
×
  • Create New...