How to send confirmation email?

  • Posts: 25
  • Thank you received: 1
10 years 10 months ago #139323

I have developed a payment plugin and all is working nice, but it is not finished yet, because I have the following situation:

My payment plugin working without problem and the gateway send notification after user's payment.

The "onPaymentNotification" function get the notification without problem, but i dont know how to send I email to user warning about payment confirmation and delivery his serial and change order status from "created" to "confirmed". With Paypal, notification send email confirmation with serial and change status of the order, but with my plugin only receive notification but do not change status and do not send confirmation email with serial.

I am trying to send to user a confirmation email with his serial, but the code do not work (i've copyed part of code from paypal source):

private static function transactionNotification($notificationCode)
{
        ... (code above) ...
        $parts = explode('|',$transaction->getReference());
	$id    = $parts[0];    // this is order_id
	$nm    = $parts[1];  // this is order_number

       // all is working ok until here

        $url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $id;
	$order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $nm, HIKASHOP_LIVE);
	$order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url));
			
	$order_status = $this->payment_params->verified_status;
	$history->notified = 1;
			
	$email = new stdClass();
	$email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','PagSeguro','confirmed',$nm);
	$email->body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','PagSeguro','Pago')).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order_status)."\r\n\r\n".$order_text;
			
	$this->modifyOrder($id, $order_status, $history, $email);
	return true;

}

What is wrong? Please help!

I just want that "onPaymentNotification" function change order status to "confirmed" and send to user a confirmation email with his serial.

Thk

Last edit: 10 years 10 months ago by andersondionizio.

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

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

Hi,

I don't know if you created the variable $history before setting his value "notified", if not it could be useful.
Otherwise, you can simple pass the argument "history" with "true" to activate the notification.

$this->modifyOrder($id, $order_status, true, $email);
An email will be send to the user if the order status has changed.
Please check that you can right access to the params of the plugin.
$this->payment_params->verified_status
should contain the value of the status. If empty it shouldn't work.

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

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

  • Posts: 25
  • Thank you received: 1
10 years 10 months ago #139369

Hi,

Thanks for information, there were errors on that 2 lines you have showed before.

I have change the code and the error now happen in this line:

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

  • Posts: 25
  • Thank you received: 1
10 years 10 months ago #139370

Hi,

Thanks for information, there were errors on that 2 lines you have showed before.

I have change the code and the error now happen in this line:

$this->modifyOrder($id, $order_status, true, $email);

Full code:
if ($transaction->getStatus()->getValue()==3) { // status confirmed									
		
     $parts = explode('|',$transaction->getReference());
     $id    = $parts[0];
     $nm    = $parts[1];
				
     $url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $id;
     $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $nm, HIKASHOP_LIVE);
     $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url));

     $order_status = 'confirmed';

     $email = new stdClass();
     $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','PagSeguro','confirmed',$nm);
     $email->body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','PagSeguro','Pago')).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order_status)."\r\n\r\n".$order_text;

     // all is working ok without error until here
     $this->modifyOrder($id, $order_status, true, $email);  // <= error here , why ?
     return true;
			
} 

I think
$this->modifyOrder($id, $order_status, true, $email);
fall in error, maybe because not find modifyOrder function.

Last edit: 10 years 10 months ago by andersondionizio.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 10 months ago #139407

That will only work if your plugin class extends from HikaShopPaymentPlugin as it's the case with most payment plugins that we have by default in HikaShop.
Otherwise, please provide the exact error message.

The following user(s) said Thank You: andersondionizio

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

  • Posts: 25
  • Thank you received: 1
10 years 10 months ago #139415

[error] [client 186.234.16.8] PHP Fatal error: Using $this when not in object context in ...

It is working now! I fixed it. The error was my fault. I was using a static function. :lol:

This problem is solved, when the plugin receive the notification, the status is change correctly and user's email and serial is correctly send.

Now I have only one little problem : when the payment gateway return to my site, only using Chrome, the page brokedown with this message: "This page has a redirect loop" ... Using firefox, have no problem.

Last edit: 10 years 10 months ago by andersondionizio.

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

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

Hi,
1. What is the URL where you redirect your customers after they have completed their payment through the payment gateway ?

2. Can you show me the code of your onPaymentNotification function ?

Last edit: 10 years 10 months ago by Mohamed Thelji.

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

  • Posts: 25
  • Thank you received: 1
10 years 10 months ago #139480

Hi,

1) www.mydomain.com.br/download/checkout/after_end/order_id-76

2)

function onPaymentNotification(&$statuses) {
			
		$code = (isset($_POST['notificationCode']) && trim($_POST['notificationCode']) !== "" ? trim($_POST['notificationCode']) : null);
        $type = (isset($_POST['notificationType']) && trim($_POST['notificationType']) !== "" ? trim($_POST['notificationType']) : null);
			
        if ($code && $type) {
            $notificationType = new PagSeguroNotificationType($type);
            $strType = $notificationType->getTypeFromValue();
            switch ($strType) {
                case 'TRANSACTION' : 
					
					$credentials = new PagSeguroAccountCredentials();
					$transaction = PagSeguroNotificationService::checkTransaction($credentials, $code);            
					
					if ($transaction->getStatus()->getValue()==3) {									
					
						$parts = explode('|',$transaction->getReference());
						$id    = $parts[0];
						$nm    = $parts[1];
									
						$url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $id;
						$order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $nm, HIKASHOP_LIVE);
						$order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url));
						
						$order_status = 'confirmed';
						
						$email = new stdClass();
						$email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','PagSeguro','confirmed',$nm);
						$email->body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','PagSeguro','Pago')).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order_status)."\r\n\r\n".$order_text;

						$this->modifyOrder($id, $order_status, true, $email);
						
						return true;

					}
					
                    break;
                default: LogPagSeguro::error("Unknown notification type [" . $notificationType->getValue() . "]");
					break;
            }
        } 
		
	}

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

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

Ok, I think that reading this thread will probably help you.

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

Time to create page: 0.080 seconds
Powered by Kunena Forum