Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. <?php
  2.  
  3. class YandexModel extends PaymentModel
  4. {
  5. public $processor;
  6. public $transField = 'orderNumber';
  7.  
  8. public $shopId = '';
  9. public $scid = '';
  10. public $shopPassword = '';
  11. public $mode = 'live';
  12.  
  13. public function getModeUrl()
  14. {
  15. return ($this->mode == self::MODE_LIVE) ? 'https://money.yandex.ru/eshop.xml' : 'https://demomoney.yandex.ru/eshop.xml';
  16. }
  17.  
  18. public function getFormFields()
  19. {
  20. $fields = array(
  21. 'shopId'=>$this->shopId,
  22. 'scid'=>$this->scid,
  23. 'sum'=>round($this->cost, 2),
  24. 'customerNumber'=>$this->id,
  25. $this->transField=>$this->token,
  26. );
  27. return $this->getFormHiddenFields($fields);
  28. }
  29.  
  30. public function verifyPayment()
  31. {
  32. if($this->paymentStatus != 'process')
  33. return false;
  34.  
  35. $request = Yii::app()->request->getParam('invoiceId');
  36. $action = $request->getParam('action');
  37. $invoiceId = $request->getParam('invoiceId');
  38. if($action != 'paymentAviso' && $action != 'checkOrder')
  39. return false;
  40.  
  41. $response = null;
  42. if(!$this->isValidMd5())
  43. {
  44. $response = $this->buildResponse($action, $invoiceId, 1);
  45. }
  46. elseif($this->shopId != $request->getParam('shopId'))
  47. {
  48. $response = $this->buildResponse($action, $invoiceId, 100, 'Invalid shop ID');
  49. }
  50. elseif(!$this->isValidCost($request->getParam('orderSumAmount')))
  51. {
  52. $response = $this->buildResponse($action, $invoiceId, 100, 'Invalid price');
  53. }
  54.  
  55. if($response != null)
  56. {
  57. $this->closeTransaction(2);
  58. $this->sendResponse($response);
  59. }
  60.  
  61. if($action == 'paymentAviso')
  62. $this->runProcess();
  63.  
  64. $response = $this->buildResponse($action, $invoiceId, 0);
  65. $this->sendResponse($response);
  66. }
  67.  
  68. /**
  69. * Checking the MD5 sign.
  70. * @return bool true if MD5 hash is correct
  71. */
  72. private function isValidMd5()
  73. {
  74. $request = Yii::app()->request;
  75. $params = [
  76. $request->getParam('action'),
  77. $request->getParam('orderSumAmount'),
  78. $request->getParam('orderSumCurrencyPaycash'),
  79. $request->getParam('orderSumBankPaycash'),
  80. $request->getParam('shopId'),
  81. $request->getParam('invoiceId'),
  82. trim($request->getParam('customerNumber')),
  83. $this->shopPassword
  84. ];
  85.  
  86. $md5 = strtoupper(md5(implode(';', $params)));
  87. return ($md5 == strtoupper($request->getParam('md5')));
  88. }
  89.  
  90. /**
  91. * Building XML response.
  92. * @param string $functionName "checkOrder" or "paymentAviso" string
  93. * @param string $invoiceId transaction number
  94. * @param string $result_code result code
  95. * @param string $message error message. May be null.
  96. * @return string prepared XML response
  97. */
  98. private function buildResponse($functionName, $invoiceId, $result_code, $message = null)
  99. {
  100. try
  101. {
  102. $performedDatetime = date('c');
  103. $response = '<?xml version="1.0" encoding="UTF-8"?><' . $functionName . 'Response performedDatetime="' . $performedDatetime .
  104. '" code="' . $result_code . '" ' . ($message != null ? 'message="' . $message . '"' : "") . ' invoiceId="' . $invoiceId . '" shopId="' . $this->shopId . '"/>';
  105. return $response;
  106. }
  107. catch (Exception $e)
  108. {
  109. Yii::log($e->getMessage(), 'error');
  110. }
  111. return null;
  112. }
  113.  
  114. private function sendResponse($responseBody)
  115. {
  116. header("HTTP/1.0 200");
  117. header("Content-Type: application/xml");
  118. echo $responseBody;
  119. exit;
  120. }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement