onPaymentNotification method

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #185227

Hi Dear
I created new custom payment plugin and my bank work with curl I can Successfully redirect to my bank and Successfully payment but when callback from bank to my site only back to this link:
index.php?option=com_hikashop
and not change my order status only show default status in my order list my transaction add in my bank Successfully but in my site no change status to confirm I think onPaymentNotification problem with curl method and I am using curl for verify my payment. this is my onPaymentNotification method:

<?php
      function onPaymentNotification(&$statuses)
    {
        $filter = JFilterInput::getInstance();
        $dbOrder = $this->getOrder($_POST['trans_id']);
        $this->loadPaymentParams($dbOrder);
        if(empty($this->payment_params))
            return false;
        $this->loadOrderData($dbOrder);
        if(empty($dbOrder))
        {
            echo 'Could not load any order for your notification ' . $_POST['trans_id'];
            return false;
        }
        $order_id = $dbOrder->order_id;

        $url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $order_id;
        $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE);
        $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url));
            $trans_id = isset($_POST['trans_id'])?$_POST['trans_id']:'';
            $id_get = isset($_POST['id_get'])?$_POST['id_get']:'';
            $api = $this->payment_params->api;
            $ch = curl_init();
            curl_setopt($ch,CURLOPT_URL,'my bank url');
            curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&id_get=$id_get&trans_id=$trans_id");
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
            $result = curl_exec($ch);
            
            curl_close($ch);
            if ($result == '') {
              
             $order_status = $this->payment_params->pending_status;
             $order_text = JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-MyBank-error#verify')."\r\n\r\n".$order_text;
            
            
        } else {
            
                if ($result == '1') {
                        echo 'MyBank transaction id: '.$_POST['trans_id'] . "\r\n\r\n";
                        $history = new stdClass();
                        $history->notified = 0;
                        $history->amount = round($dbOrder->order_full_price, (int)$this->currency->currency_locale['int_frac_digits']);
                        $history->data = ob_get_clean();
                        $order_status = $this->payment_params->verified_status;
                        if($dbOrder->order_status == $order_status)
                                return true;

                            $config =& hikashop_config();
                            if($config->get('order_confirmed_status', 'confirmed') == $order_status)
                            {
                                $history->notified = 1;
                            }

                            $email = new stdClass();
                            $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','MyBank',$order_status,$dbOrder->order_number);
                            $email->body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','MyBank',$order_status)).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order_status)."\r\n\r\n".$order_text;
                            $this->modifyOrder($order_id, $order_status, $history, $email);
                                    
                    }else {
                    
                            $order_status = $this->payment_params->invalid_status;
                            $email = new stdClass();
                            $email->subject = JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','MyBank').'invalid transaction';
                            $email->body = JText::sprintf("Hello,\r\n A MyBank notification was refused because it could not be verified by the MyBank server (or pay cenceled)")."\r\n\r\n".JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-MyBank-error#invalidtnx');
                            $action = false;
                            $this->modifyOrder($order_id, $order_status, null, $email);
                }
        }
           
        header('location: ' . HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=after_end&order_id='.$order_id . $this->url_itemid );
        exit;
    }
?>

I checked my order report from backend and it's empty. Please help me thank you.

Last edit: 9 years 10 months ago by kaya.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
9 years 10 months ago #185232

Hello,
Your issue is coming from your "callback URL" you should use a URL which will call the "OnPaymentNotification" function of your payment plugin, to do that you'll have to use that kind of URL :

$notify_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment=amazon&tmpl=component&lang=' . $this->locale . $this->url_itemid;
You'll find more example through other Hikashop payment plugin like amazon.

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #185330

Thank you dear Mohamed Thelji
But I have callback URL and it's in onAfterOrderConfirm method it's this is:

$callBackUrl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment='.$this->name.'&tmpl=component&lang='.$this->locale . $this->url_itemid;
I think problem with curl method because I created another bank plugin and use soap it's work very well but now my bank work with curl and my payment not ok
my onAfterOrderConfirm work and it's code this is:
function onAfterOrderConfirm(&$order, &$methods, $method_id)
    {
        parent::onAfterOrderConfirm($order, $methods, $method_id);
        
        $api = $this->payment_params->api;
        $amt = round($order->cart->full_total->prices[0]->price_value_with_tax,(int)$this->currency->currency_locale['int_frac_digits']);
        $callBackUrl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment='.$this->name.'&tmpl=component&lang='.$this->locale . $this->url_itemid;
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,'My bank url');
        curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&amount=$amt&redirect=$callBackUrl");
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
        $result = curl_exec($ch);
        curl_close($ch);
       if ($result>0 && is_numeric($result)){ 
           
         $this->payment_params->url = "My bank data url"; 
          return $this->showPage('end');
       } else{
       
        echo 'No Api';
   }
   
}

it's my Callback url
$callBackUrl = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment='.$this->name.'&tmpl=component&lang='.$this->locale . $this->url_itemid;
but I don't know why only back to this link index.php?option=com_hikashop

Last edit: 9 years 10 months ago by kaya.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
9 years 10 months ago #185337

Hi,

I think that the problem is on this line:
curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&amount=$amt&redirect=$callBackUrl");
If you do that it won't work as the URL need to be encoded.
See this for more information on your issue:
stackoverflow.com/questions/1163421/how-...rl-value-in-curl-php

The following user(s) said Thank You: kaya

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #185449

Hi Dear Nicolas thank you very much
I'm use urlencode methode and now my callback work and back form bank to this link:
index.php?option=com_hikashop&ctrl=checkout&task=notify¬if_payment=mybank&tmpl=component&lang=en&Itemid=251
but my page now is blank and hasn't data and not change my payment status.
Please check my onPaymentNotification method from my first post to this topic I think this part not work

header('location: ' . HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=after_end&order_id='.$order_id . $this->url_itemid );
        exit;
thank you

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 10 months ago #185492

Hi,

Please try:

header('"location:'.HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=after_end&order_id='.$order_id . $this->url_itemid.'"' );
exit;

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #185504

Hi dear Xavier
I found problem in my onPaymentNotification method in this method $this->payment_params is empty and return false
now it's work but email not send after verify my email code this is:

$email = new stdClass();
$email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','mybank',$order_status,$dbOrder->order_number);
$email->body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','mybank',$order_status)).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order_status)."\r\n\r\n".$order_text;
 $this->modifyOrder($order_id, $order_status, $history, $email);
email send only when add order and not send after verify

Last edit: 9 years 10 months ago by kaya.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
9 years 10 months ago #185660

Hi,

Make sure that you have such line before calling the modifyOrder function:
$history = 1;

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #185769

Hi
I'm add $history = 1; but sending email not work yek my code is:

$email = new stdClass();
$email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','mybank',$order_status,$dbOrder->order_number);
 $email->body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','mybank',$order_status)).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order_status)."\r\n\r\n".$order_text;
$history=1;
$this->modifyOrder($order_id, $order_status, $history, $email);
My payment is successful and change order status from created to confirmed but email not send.
Email sending only when order created

Last edit: 9 years 10 months ago by kaya.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
9 years 10 months ago #185781

Hi,

Sorry, I wanted to say that code in my previous message:
$history = true;

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #185814

Hi
Tank you dear Nicolas but I tested before this code and not send yet

$this->modifyOrder($order_id, $order_status,true, $email);
I check my history in database and see for a one order add 3 rows I'm attach a image from my database please check it and my confirmed code part this is:
$order = new stdClass();
                        $order->order_id = $dbOrder->order_id;
                        $order->old_status->order_status=$dbOrder->order_status;
                        $url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id='.$order->order_id;
                        $order_text = "\r\n".JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE',$dbOrder->order_number,HIKASHOP_LIVE);
                        $order_text .= "\r\n".str_replace('<br/>',"\r\n",JText::sprintf('ACCESS_ORDER_WITH_LINK',$url));
                        $order->order_status = 'confirmed';
                        $order->history->history_data = "bank tran_id:: ".$trans_id;
                        $orderClass->save($order);
                        $order_status =  $order->order_status;
                        $config =& hikashop_config();
                          if($config->get('order_confirmed_status','confirmed')==$order->order_status){
                              $order->history->history_notified=1;
                            }
                            $email = new stdClass();
                            $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','my bank',$order_status,$dbOrder->order_number);
                            $email->body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','my bank',$order_status)).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order_status)."\r\n\r\n".$order_text;
                            $this->modifyOrder($order_id, $order_status, true, $email);
                            $order_num = $dbOrder->order_number;
                               $app =& JFactory::getApplication();
                               $httpsHikashop = HIKASHOP_LIVE;
                               $return_url = $httpsHikashop.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$orderid.$this->url_itemid;
                               $app->enqueueMessage("<p style='color:green; font-weight:bold'>order confirmed: <span style='color:blue'>$trans_id</span></p>");
                               $app->enqueueMessage("<p style='color:green; font-weight:bold'>order number: <span style='color:blue'>$order_num</span></p>");
                               $app->redirect($return_url);
                               exit;
and cancelled part this is:
$order_status = $element->payment_params->invalid_status;
                            $email = new stdClass();
                            $email->subject = JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','my bank').'invalid transaction';
                            $email->body = JText::sprintf("Hello,\r\n A my bank notification was refused because it could not be verified by the my bank server (or pay cenceled)")."\r\n\r\n".JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-my bank-error#invalidtnx');
                            $this->modifyOrder($order_id, $order_status, true, $email);
                            $order_num = $dbOrder->order_number;
                            $app =& JFactory::getApplication();
                            $httpsHikashop = HIKASHOP_LIVE;
                            $return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=order&task=cancel_order&order_id='.$orderid.$this->url_itemid;
                            $app->enqueueMessage("<p style='color:red; font-weight:bold'>Order number<span style='color:blue'>$order_num</span> cancelled</p>");
                            $app->redirect($return_url);
                            exit;

Attachments:
Last edit: 9 years 10 months ago by kaya.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 10 months ago #185931

Hi,

The "modifyOrder" function is there to help the modification of the order (change his order status, attach some history data and send an email).
In your code, you save the order object using the order class and you're also using the modifyOrder function.

So, your updating the order too many times, for the same content.
Please just use the "modifyOrder" function and do not use the "$orderClass->save" function unless you really need to.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: kaya

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #186021

Hi
thank you
I can send email by this code:

$history = new stdClass();
$history->notified = 1;
 $history->data = 'order cancelled';
$email = new stdClass();
$email->subject = JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER', 'mybank').'invalid response';
$email->body = JText::sprintf("Hello,\r\n A Postfinance notification was refused because the response from the Post finance server was invalid")."\r\n\r\n".$order_text;
$this->modifyOrder($orderid, $element->payment_params->invalid_status, $history, $email);
now I want send email by custom subject and body but when add my custom data only send with default data.
for example with this code not change email subject and send with only default data:
$email->subject = JText::_('Custom subject');
I want add my bank data in my email body and subject.

Last edit: 9 years 10 months ago by kaya.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
9 years 10 months ago #186023

Hi,

I'm sorry but I don't understand what is your question here.

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #186077

Hi
sorry dear nicolas
I want add my bank transaction id into my email but can't add it.
email only send whit hikashop default value

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
9 years 10 months ago #186095

If you're using the code:

$history = new stdClass();
$history->notified = 1;
 $history->data = 'order cancelled';
$email = new stdClass();
$email->subject = JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER', 'mybank').'invalid response';
$email->body = JText::sprintf("Hello,\r\n A Postfinance notification was refused because the response from the Post finance server was invalid")."\r\n\r\n".$order_text;
$this->modifyOrder($orderid, $element->payment_params->invalid_status, $history, $email);
and if you have your bank transaction id in a variable $transaction_id, you want to change the line:
$email->body = JText::sprintf("Hello,\r\n A Postfinance notification was refused because the response from the Post finance server was invalid")."\r\n\r\n".$order_text;
to:
$email->body = JText::sprintf("Hello,\r\n Payment received with bank transaction id:".$transaction_id)."\r\n\r\n".$order_text;

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #186176

Thank you dear nicolas
I tested your code before and now test again but it's not work.
when use this code: $history->notified = 1; email send and it's send only with default hikashop data

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
9 years 10 months ago #186177

What HikaShop default data ?

Please Log in or Create an account to join the conversation.

  • Posts: 120
  • Thank you received: 2
9 years 10 months ago #186260

only send this data to email:
user details
order details

but I want send with email my custom data too. but not send my bank transaction id when add it to my email body text.
I don't know what is problem

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
9 years 10 months ago #186346

I'm lost.
I thought that you wanted to send a notification in a payment plugin you're developing, then I thought that you wanted to add the transaction id in the notification email that you added in that new payment plugin. And now you're telling me that you don't want to send the transaction id but send custom data.

What custom data do you want to send ?
In which email exactly do you want to add it ?
Please provide precise information on what you want to do so that we can provide precise information on how to do it.

Last edit: 9 years 10 months ago by nicolas.

Please Log in or Create an account to join the conversation.

Time to create page: 0.114 seconds
Powered by Kunena Forum