/app/code/community/Icepay/IceAdvanced/Model/Paymentmethods.php

https://bitbucket.org/nharland/wikl.nl · PHP · 110 lines · 70 code · 23 blank · 17 comment · 3 complexity · 9a4ea214394e1813609ee4166f2e0b98 MD5 · raw file

  1. <?php
  2. /**
  3. * ICEPAY Advanced - Webservice Paymentmethods
  4. * @version 2.0.0
  5. * @author Wouter van Tilburg
  6. * @author Olaf Abbenhuis
  7. * @copyright ICEPAY <www.icepay.com>
  8. *
  9. * Disclaimer:
  10. * The merchant is entitled to change de ICEPAY plug-in code,
  11. * any changes will be at merchant's own risk.
  12. * Requesting ICEPAY support for a modified plug-in will be
  13. * charged in accordance with the standard ICEPAY tariffs.
  14. *
  15. */
  16. class Icepay_IceAdvanced_Model_Paymentmethods {
  17. protected $storeID = null;
  18. private $messages = array();
  19. public function retrieveAdminGrid($storeID)
  20. {
  21. $this->storeID = $storeID;
  22. return $this->retrievePaymentmethods();
  23. }
  24. public function retrievePaymentmethods()
  25. {
  26. $merchantID = Mage::getStoreConfig('icecore/settings/merchant_id', $this->storeID);
  27. $secretCode = Mage::getStoreConfig('icecore/settings/merchant_secret', $this->storeID);
  28. $submitObject = new stdClass();
  29. $webservice = Mage::getModel('Icepay_IceAdvanced_Model_Webservice_Advanced');
  30. $webservice->init($merchantID, $secretCode);
  31. try {
  32. $paymentMethods = $webservice->getMyPaymentMethods();
  33. $this->addMessage('SOAP connection established', 'ok');
  34. if (isset($paymentMethods->GetMyPaymentMethodsResult->PaymentMethods->PaymentMethod)) {
  35. $pMethods = $this->clean($paymentMethods->GetMyPaymentMethodsResult->PaymentMethods->PaymentMethod);
  36. $this->addMessage(sprintf(Mage::helper('iceadvanced')->__('%s active paymentmethods found'), count($pMethods)), 'ok');
  37. // Add issuers
  38. $issuerObj = array();
  39. foreach ($pMethods as $value) {
  40. $arr = array(
  41. 'merchant' => $merchantID,
  42. 'code' => $value->PaymentMethodCode,
  43. 'issuers' => $value->Issuers->Issuer
  44. );
  45. array_push($issuerObj, array(
  46. 'pmcode' => $value->PaymentMethodCode,
  47. 'data' => urlencode(serialize($arr))
  48. ));
  49. }
  50. $submitObject->paymentmethods = Mage::helper("iceadvanced")->addIcons($pMethods);
  51. $submitObject->issuers = $issuerObj;
  52. } else {
  53. $this->addMessage(Mage::helper('iceadvanced')->__('No active paymentmethods found'));
  54. }
  55. } catch (Exception $e) {
  56. $this->addMessage('SOAP connection established', 'ok');
  57. $this->addMessage($e->getMessage());
  58. }
  59. $submitObject->msg = $this->messages;
  60. return $submitObject;
  61. }
  62. private function clean($paymentMethods)
  63. {
  64. //Convert to array (in case one payment method is active)
  65. $pMethodsArray = Mage::helper('icecore')->makeArray($paymentMethods);
  66. //Filter
  67. $pMethods = array_values($this->filterPaymentmethods($pMethodsArray));
  68. return $pMethods;
  69. }
  70. private function filterPaymentmethods($paymentMethods)
  71. {
  72. $filter = Mage::helper("iceadvanced")->filteredPaymentmethods;
  73. foreach (array_keys((array) $paymentMethods) as $key) {
  74. if (in_array($paymentMethods[$key]->PaymentMethodCode, $filter))
  75. unset($paymentMethods[$key]);
  76. };
  77. return $paymentMethods;
  78. }
  79. private function addMessage($val, $type = 'err')
  80. {
  81. $msg = new stdClass();
  82. $msg->type = $type;
  83. $msg->msg = Mage::helper('iceadvanced')->__($val);
  84. array_push($this->messages, $msg);
  85. }
  86. }
  87. ?>