emmajiugo Posted January 24, 2019 Report Posted January 24, 2019 Hi I have successfully integrated our gateway and I am running a test before deploying....but I am still experiencing one issue. After payment on our gateway website, the success function is called where I verify the payment and return the array details as described in the doc. But if I go to the transactions list from the staff end, I don't see any proof of payment. The invoice is still open for another payment. It means I am still missing something please help. public function buildProcess(array $contact_info, $amount, array $invoice_amounts = null, array $options = null) { // Load the models required Loader::loadModels($this, ['Clients']); $client = $this->Clients->get($contact_info['client_id']); // Get the url to send params if ($this->meta['live_mode']) { $url = $this->live_url; $pkey = $this->meta['live_public_key']; $skey = $this->meta['live_secret_key']; } else { $url = $this->test_url; $pkey = $this->meta['test_public_key']; $skey = $this->meta['test_secret_key']; } // Load Rave API $api = $this->getApi($skey, $pkey, $url); // set parameter to send to API $invoices = json_encode($invoice_amounts); $params = [ 'amount'=>$amount, 'customer_email'=>$client->email, 'currency'=>$this->currency, 'txref'=>"BLST-".time(), 'PBFPubKey'=>$pkey, 'redirect_url'=>$this->ifSet($options['return_url']), 'meta' => array( [ 'metaname' => 'clientID', 'metavalue' => $contact_info['client_id'] ], [ 'metaname' => 'invoices', 'metavalue' => $invoices ] ), ]; // Get the url to redirect the client to rave standard $result = $api->buildPayment($params); $data = $result->data(); $rave_url = isset($data->link) ? $data->link : ''; return $this->buildForm($rave_url); } /** * Builds the HTML form. * * @return string The HTML form */ private function buildForm($post_to) { $this->view = $this->makeView('process', 'default', str_replace(ROOTWEBDIR, '', dirname(__FILE__) . DS)); // Load the helpers required for this view Loader::loadHelpers($this, ['Form', 'Html']); $this->view->set('post_to', $post_to); return $this->view->fetch(); } /** * Validates the incoming POST/GET response from the gateway to ensure it is * legitimate and can be trusted. * */ public function validate(array $get, array $post) { // Log the successful response $this->log($this->ifSet($_SERVER['REQUEST_URI']), serialize($post), "output", true); return array(); } /** public function success(array $get, array $post) { // Get the url to send params if ($this->meta['live_mode']) { $url = $this->live_url; $pkey = $this->meta['live_public_key']; $skey = $this->meta['live_secret_key']; } else { $url = $this->test_url; $pkey = $this->meta['test_public_key']; $skey = $this->meta['test_secret_key']; } // Load Rave API $api = $this->getApi($skey, $pkey, $url); // verify transaction $verifyParams = [ 'txref' => $this->ifSet($get['txref']), 'SECKEY' => $skey ]; $result = $api->checkPayment($verifyParams); $data = $result->data(); // Get client ID and invoice from metadata $metadata = $this->ifSet($data->meta); foreach ($metadata as $value) { if ($value->metaname == 'clientID') { $client_id = $value->metavalue; } if ($value->metaname == 'invoices') { $invoices = $value->metavalue; } } // decode the invoices $final_invoices = json_decode($invoices, true); //return final response for blesta return [ 'client_id' => $this->ifSet($client_id), 'amount' => $this->ifSet($data->amount), 'currency' => $this->ifSet($data->currency), 'status' => $this->ifSet($data->chargecode) == '00' || $this->ifSet($data->chargecode) == '0' ? 'approved' : 'declined', // we wouldn't be here if it weren't, right? 'transaction_id' => $this->ifSet($data->txref), 'invoices' => $this->ifSet($final_invoices) ]; // return $x; } Quote
Tyson Posted January 24, 2019 Report Posted January 24, 2019 Your gateway code should process the payment notification from the gateway via ::validate. It should process the user's return to your website via ::success. You've only implemented ::success to return the expected response data, so you should ensure ::validate does as well. If no invoices are provided, Blesta cannot mark the invoices paid. Quote
emmajiugo Posted January 25, 2019 Author Report Posted January 25, 2019 So the ::validate and ::success methods are called at the same time when gateway is returning back to Blesta website? Quote
Tyson Posted January 26, 2019 Report Posted January 26, 2019 No, they're called separately, depending on what the gateway supports. If the gateway sends a notification to Blesta directly, it will trigger ::validate. If the gateway returns the customer back to Blesta, it will trigger ::success. Quote
emmajiugo Posted January 26, 2019 Author Report Posted January 26, 2019 So how do I now call the ::validate method. Or should I call it from the ::success method? This is how our gateway works...The user is taken to the gateway's website to complete the transaction which the gateway returns to the user's website through the provided return_url or callback_url, appending unique references to the url for verification. We retrieve this reference using GET and run a check to make sure that the payment was successful or not. The gateway also supports webhook where we send only successful payments, but the user needs to add the url to the webhook on their dashboard. I might not recommend this because the individual might forget to enter the webhook url on their dashboard thereby creating more problems. We would like to handle everything for the user. My current problem is how do I call the ::validate method after successful payment and returned back to the Blesta website, for me to run my check and update the invoice accordingly. Quote
emmajiugo Posted January 28, 2019 Author Report Posted January 28, 2019 Hi Tyson. I appreciate your help. Please, I really need your help on the above in order to close this project by tomorrow. Quote
Tyson Posted January 28, 2019 Report Posted January 28, 2019 Hello, You shouldn't call ::validate or ::success yourself. Those are called on your gateway automatically by Blesta if you have your callback/return URL set correctly. Take a look at the documentation for reference. You may want to also look at the PayPal Payments Standard gateway included with Blesta for a working example. Both ::success and ::validate should return the appropriate array data (e.g. client ID, status, invoices, etc.). You should also validate the payment in ::validate instead of ::success. Quote
emmajiugo Posted January 30, 2019 Author Report Posted January 30, 2019 Thanks Tyson. It's working perfectly well now. Cheers. Paul and Blesta Addons 1 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.