Jump to content

Return Something When Gateway Callback


Black-Xstar

Recommended Posts

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.

Link to comment
Share on other sites

You can take a look at other non merchant gateways included with Blesta for working examples of this functionality. However, here is a basic example:

  1. Instantiate the Http object so you may POST to the gateway
  2. POST to the gateway
  3. Handle the response

e.g. something like the following:

public function validate(array $get, array $post) {
    // Instantiate the Http object
    if (!isset($this->Http)) {
        Loader::loadComponents($this, array("Net");
        $this->Http = $this->Net->create("Http");
    }

    // Log the response we received initially
    $url = "https://domain.com/";
    $this->log($url, serialize($post), "output", true);

    // Log that we are about to make a request
    $post_data = array(/* set any data to pass along */);
    $this->log($url, serialize($post_data), "input", true);

    // Post to the gateway
    $response = $this->Http->post($url, http_build_query($post_data));

    // Log the response from the gateway
    $this->log($url, serialize($response), "output", true);

    // Handle the response
    if ($response == "success")
        // do something
    else
        // do something else

    return array(
        // ... set return key/value pairs
    );
}
Link to comment
Share on other sites

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

Edited by Black-Xstar
Link to comment
Share on other sites

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

 

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.

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...