TCheckout.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ NW0tN+KW3/Loov+wdxJOceAmyV8skdMBUoE1tqoXkBA=
  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. * 2checkout payment gateway model class
  14. */
  15. namespace Ppb\Model\PaymentGateway;
  16. use Cube\Controller\Request\AbstractRequest;
  17. class TCheckout extends AbstractPaymentGateway
  18. {
  19. /**
  20. * payment gateway name
  21. */
  22. const NAME = 'TCheckout';
  23. /**
  24. * required settings
  25. */
  26. const SID = 'sid';
  27. /**
  28. * form post url
  29. */
  30. const POST_URL = 'https://www.2checkout.com/checkout/purchase';
  31. /**
  32. * 2checkout description
  33. */
  34. protected $_description = 'Click to pay through 2Checkout.';
  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::SID])) {
  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' => 'TCheckout',
  64. 'id' => self::SID,
  65. 'element' => 'text',
  66. 'label' => $this->_('2Checkout Account Number'),
  67. 'description' => $translate->_('Enter your account number <br>'
  68. . '2Checkout 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::SID,
  80. 'value' => $this->_data[self::SID],
  81. 'element' => 'hidden',
  82. ),
  83. array(
  84. 'id' => 'mode',
  85. 'value' => '2CO',
  86. 'element' => 'hidden',
  87. ),
  88. array(
  89. 'id' => 'li_0_type',
  90. 'value' => 'product',
  91. 'element' => 'hidden',
  92. ),
  93. array(
  94. 'id' => 'li_0_name',
  95. 'value' => $this->_shortenString($this->getName(), 128),
  96. 'element' => 'hidden',
  97. ),
  98. array(
  99. 'id' => 'li_0_price',
  100. 'value' => $this->getAmount(),
  101. 'element' => 'hidden',
  102. ),
  103. array(
  104. 'id' => 'transaction_id',
  105. 'value' => $this->getTransactionId(),
  106. 'element' => 'hidden',
  107. ),
  108. array(
  109. 'id' => 'currency_code',
  110. 'value' => $this->getCurrency(),
  111. 'element' => 'hidden',
  112. ),
  113. array(
  114. 'id' => 'x_receipt_link_url',
  115. 'value' => $this->getIpnUrl(),
  116. 'element' => 'hidden',
  117. ),
  118. );
  119. }
  120. public function getPostUrl()
  121. {
  122. return self::POST_URL;
  123. }
  124. /**
  125. *
  126. * process ipn
  127. *
  128. * @param \Cube\Controller\Request\AbstractRequest $request
  129. *
  130. * @return bool
  131. */
  132. public function processIpn(AbstractRequest $request)
  133. {
  134. $response = false;
  135. if ($request->isPost()) {
  136. $paymentStatus = $request->getParam('credit_card_processed');
  137. $this->setTransactionId($request->getParam('transaction_id'))
  138. ->setAmount($request->getParam('total'))
  139. ->setCurrency($request->getParam('currency_code'))
  140. ->setGatewayPaymentStatus($request->getParam('credit_card_processed'))
  141. ->setGatewayTransactionCode($request->getParam('order_number'));
  142. if ($paymentStatus == 'Y') {
  143. $response = true;
  144. }
  145. }
  146. return $response;
  147. }
  148. }