Black-Xstar Posted January 15, 2015 Report Posted January 15, 2015 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. Quote
Tyson Posted January 15, 2015 Report Posted January 15, 2015 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: Instantiate the Http object so you may POST to the gateway POST to the gateway 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 ); } LukesUbuntu and Michael 2 Quote
Black-Xstar Posted January 15, 2015 Author Report Posted January 15, 2015 Hi @Tyson, I want to response gateway's callback, not send a new request to gateway. For example, Gateway send a request ($_POST) to callback URL: https://example.com/callback/gw/1/mygateway/?client_id=1 I want this URL response "success" to gateway. Quote
Tyson Posted January 16, 2015 Report Posted January 16, 2015 I'm not quite sure I understand then. When you receive the callback from the gateway, you want to subsequently send a "success" message back to the gateway? Quote
Black-Xstar Posted January 16, 2015 Author Report Posted January 16, 2015 (edited) 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 January 16, 2015 by Black-Xstar Quote
Tyson Posted January 19, 2015 Report Posted January 19, 2015 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. Quote
Black-Xstar Posted January 19, 2015 Author Report Posted January 19, 2015 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 Quote
Tyson Posted January 19, 2015 Report Posted January 19, 2015 e.g. Loader::loadModels($this, array("Transactions")); $transaction = $this->Transactions->getByTransactionId($transaction_id, $client_id); if ($transaction) { // Transaction already exists } Michael 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.