Jump to content
Sign in to follow this  
emmajiugo

Invoice not reflecting in Admin (staff) end

Recommended Posts

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;
    }

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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...
Sign in to follow this  

×
×
  • Create New...