VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: IceMan-101 on August 29, 2012, 17:11:34 PM

Title: [SOLVED]Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on August 29, 2012, 17:11:34 PM
Hi All,

I have a problem with a custom payment plugin I wrote for VM.

The plugin makes a call to a WSDL server to redeem points from the users account.

The actions go through, but the result page does not display and i get a blank screen in all my browsers.

I am running Joomla: 2.5.6, VM 2.0.10 and VM AIO 2.0.10

Can anyone tell me what am i doing wrong?

Please see my plgVmConfirmedOrder() code below:



    function plgVmConfirmedOrder($cart, $order) {

if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) {
return NULL; // Another method was selected, do nothing
}
if (!$this->selectedThisElement($method->payment_element)) {
return false;
}
// $params = new JParameter($payment->payment_params);
$lang     = JFactory::getLanguage();
$filename = 'com_virtuemart';
$lang->load($filename, JPATH_ADMINISTRATOR);
$vendorId = 0;

$html = "";

if (!class_exists('VirtueMartModelOrders')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php');
}
$this->getPaymentCurrency($method, true);

// END printing out HTML Form code (Payment Extra Info)
        $q  = 'SELECT `currency_code_3` FROM `#__virtuemart_currencies` WHERE `virtuemart_currency_id`="' . $method->payment_currency . '" ';
$db = JFactory::getDBO();
$db->setQuery($q);
$currency_code_3        = $db->loadResult();
$paymentCurrency        = CurrencyDisplay::getInstance($method->payment_currency);
$totalInPaymentCurrency = round($paymentCurrency->convertCurrencyTo($method->payment_currency, $order['details']['BT']->order_total, false), 2);
$cd                     = CurrencyDisplay::getInstance($cart->pricesCurrency);
       
        // get API feedback
        //$user = JFactory::getUser();
   
        //$userId = $user->get('id');
       
        // get user info from virtuemart table
//$db = &JFactory::getDBO();
//$q = 'SELECT `mybonus_card_number` FROM `#__virtuemart_userinfos` WHERE `virtuemart_user_id`="'.$userId.'" ';
//$db->setQuery($q);
       
        $address = ((isset($order['details']['ST'])) ? $order['details']['ST'] : $order['details']['BT']);
       
$card_number = $address->mbc_number;
               
        if ($card_number != '')
        {
            // includes nusoap class
            require_once('lib/nusoap.php');

            // Create object
            $client = new nusoap_client('http://www.mybonus.co.za/AgribonusService/WSAgriBonus.svc?wsdl', true);

            //set your dot net web service url
            $client->soap_defencoding = 'UTF-8';

            $err = $client->getError();
            if ($err)
            {
                $order_status = $err;
                $con_order = '0';
            }

            // get account number from card
            $MPAcc = trim($card_number);
            $MPAcc = $MPAcc."=99110100000000000";
           
            $total_payment = round($totalInPaymentCurrency);

            // Call mathod
            // Display the result
            $result = $client->call('RedemptionSale', array('merchantID' => '000000000001', 'cardNumber' => $MPAcc,'sequenceNumber' => $order['details']['BT']->virtuemart_order_id,'transactionAmount' => $total_payment,'terminalID' => '9898989', 'auditUser' => 'SHOP'));

            // fault if any
            if ($client->fault)
            {
                $certificate_num = "Error Processing Request";
                $authorization_code = "Error Processing Request";
                $order_status = $result['detail']['ExceptionDetail']['Message'];
                $con_order = '0';
            }
            else
            {
                // Check for errors
                $err = $client->getError();
                if ($err)
                {
                    // Display the error
                    $order_status = $err;
                    $con_order = '0';
                }
                else
                {
                    $order_status = "Sale Captured";
                    $certificate_num = $result['RedemptionSaleResult']['CertificateNum'];
                    $authorization_code = $result['RedemptionSaleResult']['AuthCode'];
                }
            }
        }
        else
        {
            $certificate_num = "No Valid MyBonus Card";
            $authorization_code = "No Valid MyBonus Card";
            $order_status = "No Valid MyBonus Card";
            $con_order = '0';
        }

$dbValues['payment_name']                = $this->renderPluginName($method) . '<br />' . $method->payment_info;
$dbValues['order_number']                = $order['details']['BT']->order_number;
$dbValues['virtuemart_paymentmethod_id'] = $order['details']['BT']->virtuemart_paymentmethod_id;
$dbValues['cost_per_transaction']        = $method->cost_per_transaction;
$dbValues['cost_percent_total']          = $method->cost_percent_total;
$dbValues['payment_currency']            = $currency_code_3;
$dbValues['payment_order_total']         = $totalInPaymentCurrency;
$dbValues['tax_id']                      = $method->tax_id;
        $dbValues['certificate_num'] = $certificate_num;
        $dbValues['authorization_code'] = $authorization_code;
        $dbValues['order_status'] = $order_status;
$this->storePSPluginInternalData($dbValues);
       
$html = '<table class="vmorder-done">' . "\n";
        $html .= $this->getHtmlRow('MYBONUS_PAYMENT_INFO', $dbValues['payment_name'], 'class="vmorder-done-payinfo"');
if (!empty($payment_info))
        {
            $lang = JFactory::getLanguage();
            if ($lang->hasKey($method->payment_info))
            {
                $payment_info = JText::_($method->payment_info);
            }
            else
            {
                $payment_info = $method->payment_info;
            }
            $html .= $this->getHtmlRow('MYBONUS_PAYMENTINFO', $payment_info, 'class="vmorder-done-payinfo"');
        }
       
        if (!class_exists('VirtueMartModelCurrency'))
        {
            require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php');
        }
       
$currency = CurrencyDisplay::getInstance('', $order['details']['BT']->virtuemart_vendor_id);
$html .= $this->getHtmlRow('MYBONUS_ORDER_NUMBER', $order['details']['BT']->order_number);
$html .= $this->getHtmlRow('MYBONUS_AMOUNT', $currency->priceDisplay($order['details']['BT']->order_total));
$html .= $this->getHtmlRow('MYBONUS_CERTIFICATE_NUMBER', $certificate_num);
$html .= $this->getHtmlRow('MYBONUS_AUTHORIZATION_CODE', $authorization_code);
        $html .= $this->getHtmlRow('MYBONUS_ORDER_STATUS', $order_status);
        $html .= $this->getHtmlRow('MYBONUS_PLEASE_NOTE', "Please keep the Certificate Number and Authorization Code for future reference.");
$html .= '</table>' . "\n";

        if ($con_order != '0')
        {
       
            $modelOrder                 = VmModel::getModel('orders');
$order['order_status']      = 'P';
$order['customer_notified'] = 1;
$order['comments']          = '';
            //$order['comments']          = 'Order Status: '.$order_status.' Certificate Number: '.$certificate_num.' Authorization Code: '.$authorization_code.' Please keep the Certificate Number and Authorization Code for future reference.';
            $modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, true);

            //We delete the old stuff
            $cart->emptyCart();
            JRequest::setVar('html', $html);
            return true;
        }
        else
        {

            $cart->_confirmDone = FALSE;
            $cart->_dataValidated = FALSE;
            $cart->setCartIntoSession ();
            JRequest::setVar ('html', $html);
           
$session = JFactory::getSession ();
$return_context = $session->getId ();

            return false;
        }

    }

Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on August 29, 2012, 17:55:40 PM
Hello,

Humm.. i don't see where is the problem, because you do
  JRequest::setVar('html', $html);

which is correct
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on August 30, 2012, 08:20:12 AM
Thanks Alatak,

I had a look at the Error Console that Firefox has and once I have Confirmed a transaction and this is what I get:


Timestamp: 2012/08/30 08:18:33 AM
Error: The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.
Source File: http://demo.myitmanager.co.za/thebonusshop/index.php/my-store/cart/confirm
Line: 0


Could it a problem on my template that I am using?

Regards,
Llewellyn
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on August 30, 2012, 08:59:41 AM
Hello,

I don't think it comes from the template.
But you can check adding a line
$html="testing"
before you do
JRequest::setVar('html', $html);

I will probably check the character encoding of the ini file (should be UTF-8), and of the variable $result;
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on August 30, 2012, 15:03:20 PM
Hi,

Okay I did test your suggestions and they worked.

I then tried again and still got the blank page. So I thought I will enable PHP errors and then this is what i get:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40961 bytes) in /usr/www/users/myitma/demo.myitmanager.co.za/thebonusshop/libraries/joomla/application/module/helper.php on line 220

What am i doing wrong where?

Regards
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on August 30, 2012, 15:20:51 PM
Hi,

I thought it could be a problem that is generated from my WSDL/NuSOAP call, so I did test it on its own and it is working correctly.

Regards
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on August 30, 2012, 17:29:22 PM
Hi Alatak,

I found the problem, please see below:


$modelOrder = VmModel::getModel('orders');
$order['order_status'] = 'P';
$order['customer_notified'] = 1;
$order['comments'] = 'Order Status: '.$order_status.' Certificate Number: '.$certificate_num.' Authorization Code: '.$authorization_code.' Please keep the Certificate Number and Authorization Code for future reference.';
$modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, true);


Once I comment this section out, everything is working fine, except that the person who placed the order does not get an email.

Please, let me know what I have done wrong?
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on August 30, 2012, 18:10:28 PM
Hello,

hummm...
I don't see anything wrong in your code
Try commenting this line:

$order['comments'] = 'Order Status: '.$order_status.' Certificate Number: '.$certificate_num.' Authorization Code: '.$authorization_code.' Please keep the Certificate Number and Authorization Code for future reference.';

Just in case one of those variables contain not the correct encoding.
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on August 31, 2012, 09:21:57 AM
Hi Alatak,

I did comment out that line and still it is not working.

Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on August 31, 2012, 09:23:35 AM
Hello
Then try to comment that one:
Quote$modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, true);
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on August 31, 2012, 13:38:13 PM
Okay it worked, when i comment out the line it goes trough and display the result screen.

The only problem I have now is that the user/buyer does not get an email.

I you want to have a look at my payment method file, please find it attached.

[attachment cleanup by admin]
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on August 31, 2012, 14:14:28 PM
Hello

You have to try to find why this call does not work updateStatusForOneOrder().

Because it should work. And it is that call that will send the email.
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on September 05, 2012, 09:24:41 AM
Hi,

I did check the updateStatusForOneOrder() and it is working, because it is functioning correctly in my standard payment plugin.

Could it be that my NuSoap call is clashing with something? Is there another way to send out notification emails to the buyer and vendor?
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on September 05, 2012, 09:47:35 AM
Hello,

if you are using nusoap library, check that you have it configurated to receive the answer in UTF-8. That migth be the problem.
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on September 05, 2012, 09:51:50 AM
Hi,

This has been done, please see the code below:


// includes nusoap class
require_once('lib/nusoap.php');
// Create object
$wdsl_client = new nusoap_client('http://www.mybonus.co.za/AgribonusService/WSAgriBonus.svc?wsdl', true);

//set encoding
$wdsl_client->soap_defencoding = 'UTF-8';


Still getting the same problem??
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on September 05, 2012, 10:23:26 AM
Hi,

I even tried to convert the result set I get from my web service call, mb_convert_encoding($wsdl_result, 'UTF-8'); and stil not working.
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on September 05, 2012, 12:15:34 PM
Hi There,

Here is an update.

When i change the value of $order['customer_notified'] = 1 from 1 to 0, it works. So there must be an issue with the mail script.

Any help would be greatly appreciated.
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on September 05, 2012, 12:57:40 PM
Hello,

Have you configure the safe path correctly?
Go in the VM configuration > Templates and check this parameter
Safe Path
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on September 05, 2012, 13:05:35 PM
Hi,

I have checked and used the suggested path that VM gave me.
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on September 05, 2012, 14:00:12 PM
Hello,

and when you use another payment method, then you receive the email? Everyrthing is fine?
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on September 05, 2012, 14:20:07 PM
Hi,

Yes, that is correct. When i use the standard payment method everything works correctly and the emails get sent out. It is only when I make use of the custom payment method that is based on the standard payment method, that I get this problem that the emails are sending out but I get a blank screen.

I turned on error reporting in my php script and got the follow error: Fatal Error, memory limit exceeded.

So what i did is, asked my hosting company to increase the memory limit on the domain.

I did test again and the problem was resolved.

Everything is working now.

Thanks for your help.
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: alatak on September 05, 2012, 15:40:59 PM
Hello,

Ok, so it is the nusoap library that required more memory.
Good to know. :)
It was increased from to how much?
Title: Re: Custom Payment Plugin Displays Blank Screen On Confirm
Post by: IceMan-101 on September 05, 2012, 15:43:44 PM
Hi,

Yes, it is NuSOAP that used a lot of memory during the call to the web service.

The memory limit on the server was 8Mb and was increased to its highest value on the server of 64Mb.