Payment Plugin

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
sphinix
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun May 27, 2018 1:55 pm

Payment Plugin

Postby sphinix » Sun May 27, 2018 2:16 pm

Hi ,
I am trying to migrate modify a payment plugin to accept additional variables
CardNo
CardOwner
CVV

etc
before passing it to a payment Gateway. It seems i am missing something , the values of the cardNo,cardowner come out blank
Help would be appreciated


Main File

Code: Select all

<?php

// no direct access.
defined('_JEXEC') or die;

JLoader::import('sellacious.loader');

/**
 * Plugin to manage payment via 'Sellacious  ' for sellacious shops checkout process
 *
 * @subpackage  Kharis -  Payments
 */
class plgSellaciousPaymentKharis extends SellaciousPluginPayment
{
   /**
    * Whether to force saving the submitted form data for the payment, useful for offline or similar type of payment methods
    *
    * @var    bool
    *
    * @since  1.4.4
    */
   protected $forceSaveData = true;

   /**
    * Returns handlers to the payment methods that will be managed by this plugin
    *
    * @param   string  $context    The calling context, must be 'com_sellacious.payment' to effect
    * @param   array   &$handlers  ByRef, associative array of handlers
    *
    * @return  bool
    */
   public function onCollectHandlers($context, array &$handlers)
   {
      if ($context == 'com_sellacious.payment' && !JFactory::getUser()->guest)
      {
         $handlers['kharis'] = JText::_('PLG_SELLACIOUSPAYMENT_KHARIS_API');
      }

      return true;
   }

   /**
    * Sellacious do not bother about the details a plugin might need.
    * Plugins are set free to fetch what they want. We'll fetch all the required details for the order here.
    *
    * @return  stdClass  All the required details for the transaction execution with the Payment Gateway
    * @throws  Exception
    */
   protected function getInvoice()
   {
      $app = JFactory::getApplication();

      $payment_id = $app->getUserState('com_sellacious.payment.execution.id');
      $params     = $app->getUserState('com_sellacious.payment.execution.params');
      $payment    = $this->helper->payment->getItem($payment_id);
      $pay    = $this->helper->payment->getItem($payment);

      $invoice = (object) array(
         'reason'   => $payment->context,
         'order_id' => $payment->order_id,
         'amount'   => $payment->amount_payable,
         'currency' => $payment->currency,
         [color=#800040]'CardNo'=> $app->CardNo,
         'CardOwner'=> $app->CardOwner,[/color]
         'params'   => $params,

      );

      return $invoice;
   }



   protected function getCard()
   {
      $app = JFactory::getApplication();

      $payment_id = $app->getUserState('com_sellacious.payment.execution.id');
      $params     = $app->getUserState('com_sellacious.payment.execution.params');
      $payment    = $this->helper->payment->getItem($payment_id);

      $invoice = (object) array(
      
         'CardNo'=> $payment->CardNo,
         'CardOwner'=> $payment->CardOwner,
         'params'   => $params,
      );

      return $invoice;
   }


   /**
    * Create a payment using a previously obtained credit card id.
    * The corresponding credit card is used as the funding instrument.
    *
    * @param   stdClass  $invoice  The data required by the payment gateway to execute the transaction
    *
    * @return  mixed
    * @throws  Exception
    */
   protected function initPayment($invoice)
   {

      // Let any exception here to propagate upward
      $me     = JFactory::getUser();
      $date   = JFactory::getDate()->toSql();
      $helper = SellaciousHelper::getInstance();
      $http     = JHttpFactory::getHttp();
      $config = $this->getParams();

      $api       = new stdClass();
      $data = array(
         'id'         => null,
         'order_id'   => $invoice->order_id,
         'context'    => 'user.id',
         'context_id' => $me->id,
         'reason'     => $invoice->reason,
         'crdr'       => 'dr',
         'amount'     => $invoice->amount,
         'currency'   => $invoice->currency,
         'balance'    => null,
         'txn_date'   => $date,
         'state'      => 1,
         [color=#4000FF]'CardNo'=> $invoice->CardNo,
            'CardOwner'=> $invoice->CardOwner,[/color]
      );

   
      //$balance = $helper->transaction->getBalance($me->id, $invoice->currency, 'user.id');
      $kurl = 'http://kcash.kharissystems.com/kharis.php/';

      

      //$data['url']         = $url;
      $this->app->redirect($kurl.http_build_query($data, '', '&'));         
      //$response = $http->post($kurl, $data);
      //$response = (object) $response;

      return $response;
   }

   /**
    * Generate response data to be stored in the transaction log and save
    *
    * @param   object  $response
    *
    * @return  bool
    * @throws  Exception
    */
   protected function handleResponse($response)
   {
      if ($response->approved)
      {
         $state = 'APPROVED';
      }
      elseif ($response->declined)
      {
         $state = 'DECLINED';
      }
      elseif ($response->error)
      {
         $state = 'ERROR';
      }
      else
      {
         $state = 'UNKNOWN';
      }

      $data = (object) array(
         'response_code'    => 'KHARIS:' . $state,
         'response_state'   => $state,
         'response_message' => $response->message,
         'response_data'    => (array) $response,
         'transaction_id'   => $response->id,
         'state'            => $response->approved ? 1 : -1,
      );

      $this->saveResponse($data->response_code, $data->response_state, $data->response_message, $data->response_data, $data->transaction_id, $data->state, true);

      return $response->approved;
   }
}


the XML File

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<form>
   <fieldset name="payment">
      <fields name="params">
         <field
            name="CardOwner"
            type="text"
            label="Card Holder"
            class="inputbox"
            default="Sample Kawukudi"
         />
         <field
            name="CardNo"
            type="text"
            label="Card Number"
            class="inputbox"
            default="XXXXXXXXXXXXXXXX"
         />
            <field
            name="CVV"
            type="password"
            label="PIN"
            class="inputbox"
            default="1234"
         />
               <field
            name="Expiry_Month"
            type="text"
            label="Expiry Month"
            class="inputbox"
            default="12"
         />
               <field
            name="Expiry_Year"
            type="text"
            label="Expiry Year"
            class="inputbox"
            default="2018"
         />
      </fields>
   </fieldset>
</form>


SharkyKZ
Joomla! Guru
Joomla! Guru
Posts: 947
Joined: Fri Jul 05, 2013 10:35 am
Location: Unknown

Re: Payment Plugin

Postby SharkyKZ » Mon May 28, 2018 8:30 am

Inside getInvoice() try $params->get('CardNo') instead of $app->CardNo.

sphinix
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun May 27, 2018 1:55 pm

Re: Payment Plugin

Postby sphinix » Mon May 28, 2018 5:50 pm

SharkyKZ wrote:Inside getInvoice() try $params->get('CardNo') instead of $app->CardNo.


these are the errors i get
Warning: mysqli_real_escape_string() expects parameter 2 to be string, object given in /Applications/XAMPP/xamppfiles/htdocs/sella/libraries/joomla/database/driver/mysqli.php on line 236

Fatal error: Call to a member function get() on array in /Applications/XAMPP/xamppfiles/htdocs/sella/plugins/sellaciouspayment/kharis/kharis.php on line 64

sphinix
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sun May 27, 2018 1:55 pm

Re: Payment Plugin

Postby sphinix » Mon May 28, 2018 5:55 pm

i am able to get the values using the code below but it displays the default value of the field instead of the user input . what am i getting wrong

Code: Select all

   $form = JForm::getInstance('kharis', __DIR__.'/forms/kharis.xml');   
      $fieldsets = $form->getFieldse

      if ($form)
      {
         //get all the fieldsets in the xml form
         $fieldsets = $form->getFieldsets();
   
         //display for example the label of each fieldset - var_dump($fieldsets) to see more properties
         foreach ($fieldsets as $fieldset)
         {
          // echo JText::_($fieldset->label);
          
           //loop through the fields
           $fields = $form->getFieldset($fieldset->name);
         
         
           foreach ($fields as $field)
           {
              $data[substr(substr($field->name,0,-1),7)]=$field->value;
             //exclude for example image type media from display
             if (strtolower($field->type) != 'media')
             {
               //render the field - see class the finition for more methods
               echo $field->renderField();   
             }     
         
            }
         }
      }


Return to “Joomla! 3.x Coding”

Who is online

Users browsing this forum: No registered users and 2 guests