PHP Function writing with abstract class

Hi all,
Looking for assistance in the task below. Any help is appreciated.

Task Description:

  1. Create a new function in abstract.php such as getOrder() on line 29 that returns a sessionid value that is generated using the session.php code below.
  2. This parameter is also to be included in the array from line 64 of abstract.php as the resulting value of the variable ($sessionId) in no 3 below.

Example of what’s expected included in the abstract.php:
public function sessionorder()
{

    XXXXXX use session.php parameter here XXXXX

return $this->$sessionId;
}

Session.php

  1. <?php

  2. $merchantId = “43434”;

  3. $sessionId = ’ ';

  4. $http = “http://XXXXXXX/online/online.php”;

  5. $sessionResult = ‘’;

  6. // get the session Id the first time without the event parameter or with

  7. //the parameter newsession or if success

  8. //----------------------------------------------------------------------

  9. if ( ! isset( $_GET[‘event’] ) || isset( $_GET[‘newsession’] ) ||

  10. $_GET[‘status’] == “OK” )

  11. {

  12. //

  13. $sessionResult = file_get_contents( $http . “?merchantid=” .

  14. $merchantId );

  15. //

  16. $result = explode( ‘:’, $sessionResult );

  17. //

  18. if ( $result[0] == ‘OK’ ) $sessionId = $result[1];

  19. }

  20. ?>

  21. Abstract.php

  22. <?php

  23. abstract class Kdn_Mobipaygateway_Model_Abstract extends Mage_Payment_Model_Method_Abstract

  24. {

  25. /**
    • unique internal payment method identifier

  26. */

  27. protected $_code = ‘mobipaygateway_abstract’;

  28. protected $_formBlockType = ‘mobipaygateway/form’;

  29. protected $_infoBlockType = ‘mobipaygateway/info’;

  30. /**
    • Availability options

  31. */

  32. protected $_isGateway = true;

  33. protected $_canAuthorize = true;

  34. protected $_canCapture = true;

  35. protected $_canCapturePartial = false;

  36. protected $_canRefund = false;

  37. protected $_canVoid = false;

  38. protected $_canUseInternal = false;

  39. protected $_canUseCheckout = true;

  40. protected $_canUseForMultishipping = false;

  41. protected $_paymentMethod = ‘abstract’;

  42. protected $_defaultLocale = ‘en’;

  43. protected $_supportedLocales = array(‘cn’, ‘cz’, ‘en’, ‘es’, ‘de’, ‘fr’, ‘gr’, ‘it’, ‘nl’, ‘ro’, ‘ru’, ‘pl’, ‘tr’);

  44. protected $_hidelogin = ‘1’;

  45. protected $_order;

  46. /**
    • Get order model

@return Mage_Sales_Model_Order
28. */
29. public function getOrder()
30. {
• if (!$this->_order) {
• $this->_order = $this->getInfoInstance()->getOrder();
• }
• return $this->_order;
31. }

  1. /**
    • Return url for redirection after order placed
    @return string

  2. */

  3. public function getOrderPlaceRedirectUrl()

  4. {
    • return Mage::getUrl(‘mobipaygateway/processing/payment’);

  5. }

  6. /**
    • Capture payment through Mobipaygateway api

@param Varien_Object $payment
@param decimal $amount
@return Kdn_Mobipaygateway_Model_Abstract
39. */
40. public function capture(Varien_Object $payment, $amount)
41. {
• $payment->setStatus(self::STATUS_APPROVED)
• ->setTransactionId($this->getTransactionId())
• ->setIsTransactionClosed(0);

• return $this;
42. }

  1. /**
    • Camcel payment

@param Varien_Object $payment
@return Kdn_Mobipaygateway_Model_Abstract
45. */
46. public function cancel(Varien_Object $payment)
47. {
• $payment->setStatus(self::STATUS_DECLINED)
• ->setTransactionId($this->getTransactionId())
• ->setIsTransactionClosed(1);

• return $this;
48. }

  1. /**
    • Return url of payment method

@return string
51. */
52. public function getUrl()
53. {
i. return ‘http://41.191.231.116/online/online.php’;
54. }

  1. /**
    • Return url of payment method

@return string
57. */
58. public function getLocale()
59. {
• $locale = explode(‘_’, Mage::app()->getLocale()->getLocaleCode());
• if (is_array($locale) && !empty($locale) && in_array($locale[0], $this->_supportedLocales)) {
• return $locale[0];
• }
• return $this->getDefaultLocale();
60. }

  1. /**
    • prepare params array to send it to gateway page via POST

@return array
63. */
64. public function getFormFields()
65. {
• $order_id = $this->getOrder()->getRealOrderId();
• $billing = $this->getOrder()->getBillingAddress();
• if ($this->getOrder()->getBillingAddress()->getEmail()) {
• $email = $this->getOrder()->getBillingAddress()->getEmail();
• } else {
• $email = $this->getOrder()->getCustomerEmail();
• }

• $params = array(
• ‘merchantid’ => ‘3335214003690023’,

  1. ‘sessionid’ => ‘’,
    • //‘partner’ => ‘magento’,
    • //‘transaction_id’ => $order_id,
    • ‘accepturl’ => Mage::getUrl(‘mobipaypayment/processing/accept’, array(‘transaction_id’ => $order_id)),
    • ‘cancelurl’ => Mage::getUrl(‘mobipaypayment/processing/cancel’, array(‘transaction_id’ => $order_id)),
    i. ‘declineurl’ => Mage::getUrl(‘mobipaypayment/processing/decline’, array(‘transaction_id’ => $order_id)),
    • //‘status_url’ => Mage::getUrl(‘mobipaypayment/processing/status’),
    • //‘language’ => $this->getLocale(),
    • ‘amount’ => round($this->getOrder()->getGrandTotal(), 2),
    • ‘currency’ => $this->getOrder()->getOrderCurrencyCode(),
    • //‘recipient_description’ => $this->getOrder()->getStore()->getWebsite()->getName(),
    • //‘firstname’ => $billing->getFirstname(),
    • //‘lastname’ => $billing->getLastname(),
    • //‘address’ => $billing->getStreet(-1),
    • //‘postal_code’ => $billing->getPostcode(),
    • //‘city’ => $billing->getCity(),
    • //‘country’ => $billing->getCountryModel()->getIso3Code(),
    • //‘pay_from_email’ => $email,
    • ‘phonenumber’ => $billing->getTelephone(),
    • // ‘detail1_description’ => Mage::helper(‘mobipaypayment’)->__(‘Order ID’),
    • ‘detail1_text’ => $order_id,
    • ‘payment_methods’ => $this->_paymentMethod,
    • ‘hide_login’ => $this->_hidelogin,
    • ‘new_window_redirect’ => ‘1’
    • );

• // add optional day of birth
• if ($billing->getDob()) {
• $params[‘date_of_birth’] = Mage::app()->getLocale()->date($billing->getDob(), null, null, false)->toString(‘dmY’);
• }

• return $params;
66. }
67. /**
• Get initialized flag status
@return true
68. */
69. public function isInitializeNeeded()
70. {
• return true;
71. }

  1. /**
    • Instantiate state and set it to state onject
    • //@param
    • //@param

  2. */

  3. public function initialize($paymentAction, $stateObject)

  4. {
    • $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
    • $stateObject->setState($state);
    • $stateObject->setStatus(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT);
    • $stateObject->setIsNotified(false);

  5. }

  6. /**
    • Get config action to process initialization

@return string
79. */
80. public function getConfigPaymentAction()
81. {
• $paymentAction = $this->getConfigData(‘payment_action’);
• return empty($paymentAction) ? true : $paymentAction;
82. }

  1. /**
    • Retrieve information from payment configuration
    • @param string $field
      @return mixed
  2. */
  3. public function getConfigData($field, $storeId = null)
  4. {
    • if (null === $storeId) {
    • $storeId = $this->getStore();
    • }
    • $path = ‘mobipaypayment/’.$this->getCode().‘/’.$field;
    • return Mage::getStoreConfig($path, $storeId);
  5. }
  6. }

As a public forum, PMing is mainly for chat etc. Asking for help should be done via the forums so that the posts may help others in the future.

As I said before, you have basically asked us to do your code for you. That won’t happen. At least give it a go and come back to us with any problems you face.

We don’t do your (home)work for you. If you have a specific query about PHP methodology or syntax, please ask it directly.

Thanks for your post Jake,
How can you help in this or how do I PM you?.
Peter.