Help for developing a new payment method

  • Posts: 14
  • Thank you received: 0
10 years 3 months ago #166639

-- Joomla version -- : 2.5.20
-- PHP version -- : 5.3.4

Hi,
I'm going to creating a new payment plugin.

My problem is the variable $order->order_id that it's always empty in my array!

For example, if I can try to pay using Paypal (using pluigin default), the payment it works fine, but the variable $order->order_id is always empty.

Can you help me to solve this problem?

Thank you

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

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

Hi,

You can't have an order id if the order is not already created, like in the trigger onBeforeOrderCreated.

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.

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

  • Posts: 14
  • Thank you received: 0
10 years 3 months ago #166677

Ok. Thanks.

This is my code:

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.2.3
 * @author	hikashop.com
 * @copyright	(C) 2010-2013 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?php
class plgHikashoppaymentmonetaweb2 extends hikashopPaymentPlugin
{
	var $accepted_currencies = array('EUR');
	var $multiple = true;
	var $name = 'superpay';
	var $pluginConfig = array(
		'username' => array('Terminal ID', 'input'),
		'password' => array('Terminal password', 'input'),
		'domain_name' => array('Main domain name<br><small>(i.e.: http://www.myshop.net)</small>', 'input', 'http://www.myshop.net'),	
		'debug' => array('Test environment', 'boolean', '1')

		);

  
	function onBeforeOrderCreate(&$order, &$do) {
		if(parent::onBeforeOrderCreate($order, $do) === true)
			return true;

		$this->ccLoad();

	$amount = number_format($order->cart->full_total->prices[0]->price_value_with_tax,2,'.','');

	$domain=$this->payment_params->domain_name;
	$pluginPath=$domain."/plugins/hikashoppayment/superpay/";
	
	/* ORDER CODE ??? */
	$theOrderCode=$order->order_id;
	
	$host="test";

/* Start the source code MY PERSONAL BANK */

  $parameters = array(
	  'id' => $this->payment_params->username,
	  'password' => $this->payment_params->password,
	  'operationType' => 'initialize',
	  'amount' => $amount,
	  'currencyCode' => '978',
	  'language' => 'ITA',
	  'responseToMerchantUrl' => $pluginPath.'superpay_notify.php',
	  'recoveryUrl' => $pluginPath.'superpay_recovery.php',
	  'merchantOrderId' => 'Order Num. '.$theOrderCode, // ??? ORDER CODE ???
    'cardHolderName' => '',
    'cardHolderEmail'  => '',
	'description' => '',
    'customField' => ''
	  );

		if(!function_exists('curl_init')){
			$this->app->enqueueMessage('The MonetaWeb2 payment plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.','error');
			return false;
		}


  $curlHandle = curl_init();
  curl_setopt($curlHandle, CURLOPT_URL, 'https://'.$host.'.monetaonline.it/monetaweb/payment/2/xml');
  curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curlHandle, CURLOPT_POST, true);
  curl_setopt($curlHandle, CURLOPT_POSTFIELDS, http_build_query($parameters));
  $xmlResponse = curl_exec($curlHandle);
  curl_close($curlHandle);

  $response = new SimpleXMLElement($xmlResponse);
  $paymentId = $response->paymentid;
  $paymentUrl = $response->hostedpageurl;

  $securityToken = $response->securitytoken;

  $setefiPaymentPageUrl = "$paymentUrl?PaymentID=$paymentId";
 // print_r($parameters); exit();
  header("Location: $setefiPaymentPageUrl");

	}

	function onAfterOrderConfirm(&$order,&$methods,$method_id){
		parent::onAfterOrderConfirm($order, $methods, $method_id);
		$this->removeCart = true;

		return $this->showPage('thanks');
	}

	function getPaymentDefaultValues(&$element) {
		$element->payment_name='Credit Card';
		$element->payment_description='You can pay by credit card using this payment method';
		$element->payment_images='MasterCard,VISA,American_Express';

		$element->payment_params->username='';
		$element->payment_params->password='';
		$element->payment_params->ask_ccv = true;
		$element->payment_params->ask_owner = false;
		$element->payment_params->verified_status='confirmed';
	}
}

Can you help me to debug it, for getting correctly the order_id ?
In which one fuction it can be generated?

Thanks!

Last edit: 10 years 3 months ago by willylord.

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

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

Hi,

It's normal that the order_id is not available in $order since the function onBeforeOrderCreate is called before the order is created and thus no order_id has yet been assigned to it.

You should instead put your code in the onAfterOrderConfirm function, like in the PayPal plugin.

The following user(s) said Thank You: willylord

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

  • Posts: 14
  • Thank you received: 0
10 years 3 months ago #166759

Thanks.
In the onAfterOrderConfirm() it works fine.

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

  • Posts: 4
  • Thank you received: 0
7 years 3 months ago #275118

hi... i need to use this payment method...
can you help me?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 3 months ago #275120

Hi,

We don't have the full code of the plugin on our end so we can't help.
However, maybe @willylord could provide it ?

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

Time to create page: 0.087 seconds
Powered by Kunena Forum