WorldPay.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ cclgGpZWf4CD9dmUJE1yVPr1eZhglksEE6j2s/pS8PE=
  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. * worldpay payment gateway model class
  14. */
  15. namespace Ppb\Model\PaymentGateway;
  16. use Cube\Controller\Request\AbstractRequest;
  17. class WorldPay extends AbstractPaymentGateway
  18. {
  19. /**
  20. * payment gateway name
  21. */
  22. const NAME = 'WorldPay';
  23. /**
  24. * required settings
  25. */
  26. const INSTID = 'instId';
  27. /**
  28. * form post url
  29. */
  30. const POST_URL = 'https://select.worldpay.com/wcc/purchase';
  31. /**
  32. * worldpay description
  33. */
  34. protected $_description = 'Click to pay though WorldPay.';
  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::INSTID])) {
  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' => 'WorldPay',
  64. 'id' => self::INSTID,
  65. 'element' => 'text',
  66. 'label' => $this->_('WorldPay ID'),
  67. 'description' => $translate->_('Enter your merchant installation Id <br>'
  68. . 'WorldPay 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::INSTID,
  80. 'value' => $this->_data[self::INSTID],
  81. 'element' => 'hidden',
  82. ),
  83. array(
  84. 'id' => 'cartId',
  85. 'value' => $this->getTransactionId(),
  86. 'element' => 'hidden',
  87. ),
  88. array(
  89. 'id' => 'amount',
  90. 'value' => $this->getAmount(),
  91. 'element' => 'hidden',
  92. ),
  93. array(
  94. 'id' => 'currency',
  95. 'value' => $this->getCurrency(),
  96. 'element' => 'hidden',
  97. ),
  98. array(
  99. 'id' => 'desc',
  100. 'value' => $this->getName(),
  101. 'element' => 'hidden',
  102. ),
  103. array(
  104. 'id' => 'MC_callback',
  105. 'value' => $this->getIpnUrl(),
  106. 'element' => 'hidden',
  107. ),
  108. );
  109. }
  110. public function getPostUrl()
  111. {
  112. return self::POST_URL;
  113. }
  114. /**
  115. *
  116. * process ipn
  117. *
  118. * @param \Cube\Controller\Request\AbstractRequest $request
  119. *
  120. * @return bool
  121. */
  122. public function processIpn(AbstractRequest $request)
  123. {
  124. $response = false;
  125. if ($request->isPost()) {
  126. $paymentStatus = $request->getParam('transStatus');
  127. $this->setTransactionId($request->getParam('cartId'))
  128. ->setAmount($request->getParam('amount'))
  129. ->setCurrency($request->getParam('currency'))
  130. ->setGatewayPaymentStatus($request->getParam('rawAuthMessage'))
  131. ->setGatewayTransactionCode($request->getParam('transId'));
  132. if ($paymentStatus == 'Y') {
  133. $response = true;
  134. }
  135. }
  136. return $response;
  137. }
  138. }