Paymate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ +spayWRTYaFwFUEhxXH5dAlBSNazHRQkRs9oOBNtJKM=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2014 Online Ventures Software LTD & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.2
  11. */
  12. /**
  13. * paymate payment gateway model class
  14. */
  15. namespace Ppb\Model\PaymentGateway;
  16. use Cube\Controller\Request\AbstractRequest;
  17. class Paymate extends AbstractPaymentGateway
  18. {
  19. /**
  20. * payment gateway name
  21. */
  22. const NAME = 'Paymate';
  23. /**
  24. * required settings
  25. */
  26. const MERCHANT_ID = 'mid';
  27. /**
  28. * form post url
  29. */
  30. const POST_URL = 'https://www.paymate.com/PayMate/ExpressPayment';
  31. /**
  32. * paymate description
  33. */
  34. protected $_description = 'Click to pay using Paymate Express Payments.';
  35. public function __construct($userId = null)
  36. {
  37. parent::__construct(self::NAME, $userId);
  38. }
  39. /**
  40. *
  41. * check if the gateway is enabled
  42. *
  43. * @return bool
  44. */
  45. public function enabled()
  46. {
  47. if (!empty($this->_data[self::MERCHANT_ID])) {
  48. return true;
  49. }
  50. return false;
  51. }
  52. /**
  53. *
  54. * get setup form elements
  55. *
  56. * @return array
  57. */
  58. public function getElements()
  59. {
  60. $translate = $this->getTranslate();
  61. return array(
  62. array(
  63. 'form_id' => 'Paymate',
  64. 'id' => self::MERCHANT_ID,
  65. 'element' => 'text',
  66. 'label' => $this->_('Paymate Username'),
  67. 'description' => $translate->_('Enter the username you use to log into the Paymate website <br>'
  68. . 'Paymate IPN URL: <br>') . $this->getIpnUrl(),
  69. 'attributes' => array(
  70. 'class' => 'form-control input-medium',
  71. ),
  72. ),
  73. );
  74. }
  75. public function formElements()
  76. {
  77. return array(
  78. array(
  79. 'id' => self::MERCHANT_ID,
  80. 'value' => $this->_data[self::MERCHANT_ID],
  81. 'element' => 'hidden',
  82. ),
  83. array(
  84. 'id' => 'amt',
  85. 'value' => $this->getAmount(),
  86. 'element' => 'hidden',
  87. ),
  88. array(
  89. 'id' => 'amt_editable',
  90. 'value' => 'N',
  91. 'element' => 'hidden',
  92. ),
  93. array(
  94. 'id' => 'currency',
  95. 'value' => $this->getCurrency(),
  96. 'element' => 'hidden',
  97. ),
  98. array(
  99. 'id' => 'return',
  100. 'value' => $this->getIpnUrl(),
  101. 'element' => 'hidden',
  102. ),
  103. array(
  104. 'id' => 'ref',
  105. 'value' => $this->getTransactionId(),
  106. 'element' => 'hidden',
  107. ),
  108. array(
  109. 'id' => 'popup',
  110. 'value' => 'false',
  111. 'element' => 'hidden',
  112. ),
  113. );
  114. }
  115. public function getPostUrl()
  116. {
  117. return self::POST_URL;
  118. }
  119. /**
  120. *
  121. * process ipn
  122. *
  123. * @param \Cube\Controller\Request\AbstractRequest $request
  124. *
  125. * @return bool
  126. */
  127. public function processIpn(AbstractRequest $request)
  128. {
  129. $response = false;
  130. if ($request->isPost()) {
  131. $paymentStatus = $request->getParam('responseCode');
  132. $this->setTransactionId($request->getParam('ref'))
  133. ->setAmount($request->getParam('paymentAmount'))
  134. ->setCurrency($request->getParam('currency'))
  135. ->setGatewayPaymentStatus($request->getParam('responseCode'))
  136. ->setGatewayTransactionCode($request->getParam('transactionID'));
  137. if ($paymentStatus == 'PA') {
  138. $response = true;
  139. }
  140. }
  141. return $response;
  142. }
  143. }