Skip to main content

new payment method

More
13 years 2 months ago #117345 by nicolas
Replied by nicolas on topic new payment method
From what you're saying the onPaymentNotification function is what you want to use.
The following user(s) said Thank You: kaya

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

More
13 years 2 months ago #119365 by kaya
Replied by kaya on topic new payment method
Hi nicolas thank you
in paypal method at onPaymentNotification function which code or line update order status to confirmed after when payment is ok

it's paypal onPaymentNotification function
Code:
function onPaymentNotification(&$statuses){ $pluginsClass = hikashop_get('class.plugins'); $elements = $pluginsClass->getMethods('payment','paypal'); if(empty($elements)) return false; $element = reset($elements); if(!$element->payment_params->notification){ return false; } $vars = array(); $data = array(); $filter = JFilterInput::getInstance(); foreach($_REQUEST as $key => $value){ $key = $filter->clean($key); if(preg_match("#^[0-9a-z_-]{1,30}$#i",$key)&&!preg_match("#^cmd$#i",$key)){ $value = JRequest::getString($key); $vars[$key]=$value; $data[]=$key.'='.urlencode($value); } } $data = implode('&',$data).'&cmd=_notify-validate'; if($element->payment_params->debug){ echo print_r($vars,true)."\n\n\n"; } $orderClass = hikashop_get('class.order'); $dbOrder = $orderClass->get((int)@$vars['invoice']); if(empty($dbOrder)){ echo "Could not load any order for your notification ".@$vars['invoice']; return false; } $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)); if($element->payment_params->debug){ echo print_r($dbOrder,true)."\n\n\n"; } $mailer = JFactory::getMailer(); $config =& hikashop_config(); $sender = array( $config->get('from_email'), $config->get('from_name') ); $mailer->setSender($sender); $mailer->addRecipient(explode(',',$config->get('payment_notification_email'))); if(!empty($element->payment_params->ips)){ $ip = hikashop_getIP(); $ips = str_replace(array('.','*',','),array('\.','[0-9]+','|'),$element->payment_params->ips); if(!preg_match('#('.implode('|',$ips).')#',$ip)){ $mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','Paypal').' '.JText::sprintf('IP_NOT_VALID',$dbOrder->order_number)); $body = str_replace('<br/>',"\r\n",JText::sprintf('NOTIFICATION_REFUSED_FROM_IP','Paypal',$ip,implode("\r\n",$element->payment_params->ips)))."\r\n\r\n".JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-paypal-error#ip').$order_text; $mailer->setBody($body); $mailer->Send(); JError::raiseError( 403, JText::_( 'Access Forbidden' )); return false; } } if(empty($element->payment_params->url))$element->payment_params->url='https://www.paypal.com/cgi-bin/webscr'; $url = parse_url($element->payment_params->url); if(!isset($url['query'])){ $url['query'] = ''; } if(!isset($url['port'])){ if(!empty($url['scheme'])&&in_array($url['scheme'],array('https','ssl'))){ $url['port'] = 443; }else{ $url['port'] = 80; } } if(!empty($url['scheme'])&&in_array($url['scheme'],array('https','ssl'))){ $url['host_socket'] = 'ssl://'.$url['host']; }else{ $url['host_socket'] = $url['host']; } if($element->payment_params->debug){ echo print_r($url,true)."\n\n\n"; } $fp = fsockopen ( $url['host_socket'], $url['port'], $errno, $errstr, 30); if (!$fp) { $mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','Paypal').' '.JText::sprintf('PAYPAL_CONNECTION_FAILED',$dbOrder->order_number)); $body = str_replace('<br/>',"\r\n",JText::sprintf('NOTIFICATION_REFUSED_NO_CONNECTION','Paypal'))."\r\n\r\n".JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-paypal-error#connection').$order_text; $mailer->setBody($body); $mailer->Send(); JError::raiseError( 403, JText::_( 'Access Forbidden' )); return false; } $uri = $url['path'].($url['query']!='' ? '?' . $url['query'] : ''); $header = "POST $uri HTTP/1.0\r\n". "User-Agent: PHP/".phpversion()."\r\n". "Referer: ".hikashop_currentURL()."\r\n". "Server: ".$_SERVER['SERVER_SOFTWARE']."\r\n". "Host: ".$url['host'].":".$url['port']."\r\n". "Content-Type: application/x-www-form-urlencoded\r\n". "Content-Length: ".strlen($data)."\r\n". "Accept: */"."*\r\n\r\n"; fwrite($fp, $header . $data); $response = ''; while (!feof($fp)) { $response .= fgets ($fp, 1024); } fclose ($fp); if($element->payment_params->debug){ echo print_r($header,true)."\n\n\n"; echo print_r($data,true)."\n\n\n"; echo print_r($response,true)."\n\n\n"; } $response = substr($response, strpos($response, "\r\n\r\n") + strlen("\r\n\r\n")); $verified = preg_match( "#VERIFIED#i", $response); if(!$verified){ if(preg_match("#INVALID#i", $response)){ $mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','Paypal').'invalid transaction'); $body = JText::sprintf("Hello,\r\n A paypal notification was refused because it could not be verified by the paypal server")."\r\n\r\n".JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-paypal-error#invalidtnx').$order_text; $mailer->setBody($body); $mailer->Send(); if($element->payment_params->debug){ echo 'invalid transaction'."\n\n\n"; } }else{ $mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','Paypal').'invalid response'); $body = JText::sprintf("Hello,\r\n A paypal notification was refused because the response from the paypal server was invalid")."\r\n\r\n".JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-paypal-error#invalidresponse').$order_text; $mailer->setBody($body); $mailer->Send(); if($element->payment_params->debug){ echo 'invalid response'."\n\n\n"; } } return false; } $completed = preg_match("#Completed#i", $vars['payment_status']); $pending = preg_match("#Pending#i", $vars['payment_status']); if (!$completed && !$pending) { $body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','Paypal',$vars['payment_status'])).' '.JText::_('STATUS_NOT_CHANGED')."\r\n\r\n".JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-paypal-error#status').$order_text; $mailer->setSubject(JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','Paypal',$vars['payment_status'],$dbOrder->order_number)); $mailer->setBody($body); $mailer->Send(); if($element->payment_params->debug){ echo 'payment '.$vars['payment_status']."\n\n\n"; } return false; } echo 'PayPal transaction id: '.$vars['txn_id']."\n\n\n"; $order->history->history_reason=JText::sprintf('AUTOMATIC_PAYMENT_NOTIFICATION'); $order->history->history_notified=0; $order->history->history_amount=@$vars['mc_gross'].@$vars['mc_currency']; $order->history->history_payment_id = $element->payment_id; $order->history->history_payment_method =$element->payment_type; $order->history->history_data = ob_get_clean(); $order->history->history_type = 'payment'; $currencyClass = hikashop_get('class.currency'); $currencies=null; $currencies = $currencyClass->getCurrencies($dbOrder->order_currency_id,$currencies); $currency=$currencies[$dbOrder->order_currency_id]; $price_check = round($dbOrder->order_full_price, (int)$currency->currency_locale['int_frac_digits'] ); if($price_check != @$vars['mc_gross'] || $currency->currency_code != @$vars['mc_currency']){ $order->order_status = $element->payment_params->invalid_status; $orderClass->save($order); $mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER','Paypal').JText::_('INVALID_AMOUNT')); $body = str_replace('<br/>',"\r\n",JText::sprintf('AMOUNT_RECEIVED_DIFFERENT_FROM_ORDER','Paypal',$order->history->history_amount,$price_check.$currency->currency_code))."\r\n\r\n".JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-paypal-error#amount').$order_text; $mailer->setBody($body); $mailer->Send(); return false; } if($completed){ $order->order_status = $element->payment_params->verified_status; }else{ $order->order_status = $element->payment_params->pending_status; $order_text = JText::sprintf('CHECK_DOCUMENTATION',HIKASHOP_HELPURL.'payment-paypal-error#pending')."\r\n\r\n".$order_text; } if($dbOrder->order_status == $order->order_status) return true; $config =& hikashop_config(); if($config->get('order_confirmed_status','confirmed')==$order->order_status){ $order->history->history_notified=1; } $order->mail_status=$statuses[$order->order_status]; $mailer->setSubject(JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER','Paypal',$vars['payment_status'],$dbOrder->order_number)); $body = str_replace('<br/>',"\r\n",JText::sprintf('PAYMENT_NOTIFICATION_STATUS','Paypal',$vars['payment_status'])).' '.JText::sprintf('ORDER_STATUS_CHANGED',$order->mail_status)."\r\n\r\n".$order_text; $mailer->setBody($body); $mailer->Send(); $orderClass->save($order); return true; }

I want use this method in my payment method for update order status automatically at database if payment is ok.
thank you

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

More
13 years 2 months ago #119395 by nicolas
Replied by nicolas on topic new payment method
It's that line which saves the new order infos:
$orderClass->save($order);

The $order object contains the new status added with the line:
$order->order_status = $element->payment_params->verified_status;
and the order_id added with the line:
$order->order_id = $dbOrder->order_id;
The following user(s) said Thank You: kaya

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

More
13 years 2 months ago - 13 years 2 months ago #119503 by kaya
Replied by kaya on topic new payment method
very well thank you nicolas
my bank send me referenceId with POST method I should save it in my database it's my bank Transaction Code
now which field of order table at database I can save it? it's necessary for save at database.
Last edit: 13 years 2 months ago by kaya.

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

More
13 years 2 months ago - 13 years 2 months ago #119536 by Mohamed Thelji
Replied by Mohamed Thelji on topic new payment method
Hi,

I think that you'll be able to save it by using this kind of code :
Code:
$order->history->history_data = ob_get_clean().'/r/n'.$YourTransactionCode;
Note that you'll have to set your transaction code into the $YourTransactionCode variable.
Last edit: 13 years 2 months ago by Mohamed Thelji.
The following user(s) said Thank You: kaya

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

More
13 years 2 months ago #119686 by kaya
Replied by kaya on topic new payment method
thank you very much
now I should show my user payment result massage after payment
which code I can use at onPaymentNotification function for echo my bank massage for ok payment or not ok payment.

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

More
13 years 2 months ago - 13 years 2 months ago #119689 by Mohamed Thelji
Replied by Mohamed Thelji on topic new payment method
Hi,

I'll need more information about the payment process of this payment method, because if your customer is redirected to your notification URL after the payment your should use this kind of code :

- put this code at the begining of your function :
Code:
$app =& JFactory::getApplication(); $httpsHikashop = HIKASHOP_LIVE; global $Itemid; $url_itemid = ''; if (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; }
- If the payment status is OK :
Code:
$return_url = $httpsHikashop.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$YOUR_ORDER_ID.$url_itemid; $app->enqueueMessage('YOUR SUCCESS MESSAGE'); $app->redirect($return_url);
- If the payment status isn't OK :
Code:
$cancel_url = $httpsHikashop.'index.php?option=com_hikashop&ctrl=order&task=cancel_order&order_id='.$YOUR_ORDER_ID.$url_itemid; $app->enqueueMessage('YOUR ERROR MESSAGE'); $app->redirect($cancel_url);

Note that you'll have to set your order ID into the $YOUR_ORDER_ID variable.
Last edit: 13 years 2 months ago by Mohamed Thelji.

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

More
13 years 2 months ago - 13 years 2 months ago #119693 by kaya
Replied by kaya on topic new payment method
thank you
with this code:
$app->enqueueMessage('YOUR SUCCESS MESSAGE');

can I show to my user bank TransactionCode payment code?
Last edit: 13 years 2 months ago by kaya.

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

More
13 years 2 months ago #119694 by Mohamed Thelji
Replied by Mohamed Thelji on topic new payment method
Yes by using something like :
Code:
$app->enqueueMessage('YOUR SUCCESS MESSAGE WITH THE FOLLOWING TRANSACTION CODE : '. $YourTransactionCode);
The following user(s) said Thank You: kaya

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

More
13 years 2 months ago #119833 by kaya
Replied by kaya on topic new payment method
Hi Mohamed
My all payment process is:
I send to my bank this information:
Code:
$vars = array( "merchantId" => $method->payment_params->merchantId, "amount" => $order->order_full_price, "paymentId" => $order->order_id, "customerId" => $order->order_user_id, "revertURL" => $return_url );
I can send it with use onAfterOrderConfirm function and connect with my bank.
after it my bank send me with POST method $resultCode and $referenceId ( it's my bank Transaction code )
and $paymentID ( it's my order_id ) to my $return_url
after bank send theme I should verify my costomer payment with use nusoap class and after verify if my $resultCode is ok
costumer payment is ok and save order at database and confirmed it.
please help me my problem in verify and save at database.
thank you

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

More
13 years 2 months ago #119838 by nicolas
Replied by nicolas on topic new payment method
For the verification, you need to follow your payment method integration guide. We can't help you on that as it is relative to your payment gateway. Please ask them if you have trouble with that part.
For the order status saving to the database, it's quite easy. If you have the order_id in $paymentID, you can do like that:
Code:
$class = hikashop_get('class.order'); $order = new stdClass(); $order->order_id = $paymentID; $order->order_status = 'confirmed'; $order->history = new stdClass(); $order->history->history_notified = 1; $class->save($order);
The following user(s) said Thank You: cbadmin, kaya

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

More
13 years 2 months ago #119840 by kaya
Replied by kaya on topic new payment method
thank you nicolas
Excuse me.
i have my bank verify sample but my problem is:
my bank send with method POST to $return_url now can I take theme at onPaymentNotification function?

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

More
13 years 2 months ago #119845 by nicolas
Replied by nicolas on topic new payment method
Yes, since they are in the POST.
Like that for example:
Code:
$paymentID = $_POST['paymentID'];
The following user(s) said Thank You: kaya

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

More
13 years 2 months ago - 13 years 2 months ago #119851 by kaya
Replied by kaya on topic new payment method
thank you nicolas
can I show my user ok payment result massage and TransactionCode or not ok payment massage after payment?
Mr Mohamed say if my customer is redirected to notification URL use it
Code:
$app =& JFactory::getApplication(); $httpsHikashop = HIKASHOP_LIVE; global $Itemid; $url_itemid = ''; if (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; }
but my user use $return_url
Last edit: 13 years 2 months ago by kaya.

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

More
13 years 2 months ago #119878 by nicolas
Replied by nicolas on topic new payment method
I can't say. It depends on how the payment gateway calls the payment notification function.
If it redirects the user's browser to the notification, then you can simply echo your text directly.
The following user(s) said Thank You: kaya

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

More
13 years 2 months ago #120163 by kaya
Replied by kaya on topic new payment method
thank you nicolas
how can I echo $paymentID = $_POST; or result code at onPaymentNotification function
Because I want to test Is I get them or not.
thank you

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

More
13 years 2 months ago #120174 by Mohamed Thelji
Replied by Mohamed Thelji on topic new payment method
you should just echo your values like this :
Code:
echo '<br/>My payment ID : '.$paymentID;
and then you'll be able to read this value through the Payment log file option via "Hikashop->System->Configuration->'main'".
The following user(s) said Thank You: kaya

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

More
13 years 2 months ago - 13 years 2 months ago #120316 by kaya
Replied by kaya on topic new payment method
Thank you mohamed
I use it but my log file is empty I think don't receive result code with $_POST in onPaymentNotification function
this is my onPaymentNotification function please check it for me.
Code:
function onPaymentNotification(&$statuses) { $pluginsClass = hikashop_get('class.plugins'); $elements = $pluginsClass->getMethods('payment', 'tejarat'); if(empty($elements)) return false; $element = reset($elements); $vars = array(); $data = array(); $filter =& JFilterInput::getInstance(); /////////////////// My bank Verify ///////////////// $merchantId = $method->payment_params->merchantId; require_once(JPATH_ROOT .'/plugins/hikashoppayment/tejarat/arastejarat/nusoap.php'); $wsdl = "http://pg.sabapardazesh.net:9086/paymentGateway/services/merchant.wsdl"; $ns='http://tejarat/paymentGateway/definitions'; $resultCode = $_POST['resultCode']; $paymentId = $_POST['paymentId']; $referenceId = $_POST['referenceId']; echo '<br/> Bank Transaction code : '.$referenceId; // $client = new nusoap_client($wsdl, true); if (isset($_POST['resultCode'])) { $resultCode = $_POST['resultCode']; $referenceId = isset($_POST['referenceId']) ? $_POST['referenceId'] : 0; $paymentID = isset($_SESSION["PaymentID"]) ? $_SESSION['PaymentID'] : 0; if (($resultCode == 100)) { try { $client = new nusoap_client($wsdl, true); $err = $client->getError(); if ($err) { echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>'; } $params = array( "verifyRequest" => array( 'merchantId' => $merchantId, 'referenceNumber' => $referenceId) ); $client->setUseCurl(0); $client->soap_defencoding = 'UTF-8'; $client->decode_utf8 = true; $client->setEndpoint($wsdl); $result = $client->call("verify", $params); if ($client->fault) { echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2><pre>'; print_r($result); echo '</pre>'; } else { $err = $client->getError(); if ($err) { echo '<h2>Error</h2><pre>' . $err . '</pre>'; } else { //////// Start save order ///////// $class = hikashop_get('class.order'); $order = new stdClass(); $order->order_id = $paymentID; $order->order_status = 'confirmed'; $order->history = new stdClass(); $order->history->history_notified = 1; $order->order_status = $element->payment_params->verified_status; $order->order_id = $dbOrder->order_id; $order->history->history_data = ob_get_clean().'/r/n'.$referenceId; $orderClass->save($order); return true; ///////// End save order ///////// } } echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>'; echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>'; echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>'; } catch (Exception $ex) { echo '<h2>Error</h2><pre>' . $ex->getMessage() . '</pre>'; } } } ///////////// End bank verify ///////////////////// }
my bank send me with return url and $_POST result code and my return url is it:
Code:
$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order->order_id.$url_itemid;
I'm connect bank and payment and back to return url but I think can't receive result code.
thank you for your best support
Last edit: 13 years 2 months ago by kaya.

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

More
13 years 2 months ago - 13 years 2 months ago #120384 by nicolas
Replied by nicolas on topic new payment method
Your return URL should be:
Code:
$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment=tejarat';
Last edit: 13 years 2 months ago by nicolas.
The following user(s) said Thank You: kaya

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

More
13 years 1 month ago #120822 by kaya
Replied by kaya on topic new payment method
Thank you nicolas
I use this:
Code:
$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=notify&notif_payment=tejarat';
but now have this error

Fatal error: Call to a member function save() on a non-object in plugins\hikashoppayment\tejarat\tejarat.php on line 385

please check my onPaymentNotification what is problem
thank you

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

Time to create page: 0.554 seconds
Powered by Kunena Forum