[SOLVED]Custom Payment Plugin Displays Blank Screen On Confirm

Started by IceMan-101, August 29, 2012, 17:11:34 PM

Previous topic - Next topic

IceMan-101

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;
        }

    }

Master of Web disaster!

alatak

Hello,

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

which is correct

IceMan-101

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
Master of Web disaster!

alatak

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;

IceMan-101

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
Master of Web disaster!

IceMan-101

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
Master of Web disaster!

IceMan-101

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?
Master of Web disaster!

alatak

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.

IceMan-101

Hi Alatak,

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

Master of Web disaster!

alatak

Hello
Then try to comment that one:
Quote$modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, true);

IceMan-101

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]
Master of Web disaster!

alatak

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.

IceMan-101

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?
Master of Web disaster!

alatak

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.

IceMan-101

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??
Master of Web disaster!