1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* OKPAY driver for Omnipay PHP payment library. |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/omnipay-okpay |
6
|
|
|
* @package omnipay-okpay |
7
|
|
|
* @license MIT |
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Omnipay\OKPAY\Message; |
12
|
|
|
|
13
|
|
|
use Omnipay\Common\Exception\InvalidRequestException; |
14
|
|
|
|
15
|
|
|
class RefundRequest extends AbstractRequest |
16
|
|
|
{ |
17
|
|
|
protected $endpoint = 'https://api.okpay.com/OkPayAPI?wsdl'; |
18
|
|
|
|
19
|
1 |
|
public function getSecret() |
20
|
|
|
{ |
21
|
1 |
|
return $this->getParameter('secret'); |
22
|
|
|
} |
23
|
|
|
|
24
|
2 |
|
public function setSecret($value) |
25
|
|
|
{ |
26
|
2 |
|
return $this->setParameter('secret', $value); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function getPayeeAccount() |
30
|
|
|
{ |
31
|
|
|
return $this->getParameter('payeeAccount'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function setPayeeAccount($value) |
35
|
|
|
{ |
36
|
|
|
return $this->setParameter('payeeAccount', $value); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getData() |
40
|
|
|
{ |
41
|
|
|
$this->validate('purse', 'payeeAccount', 'amount', 'secret', 'description'); |
42
|
|
|
|
43
|
|
|
$data['secret'] = $this->getSecret(); |
|
|
|
|
44
|
|
|
$data['walletId'] = $this->getPurse(); |
45
|
|
|
$data['receiver'] = $this->getPayeeAccount(); |
46
|
|
|
$data['amount'] = $this->getAmount(); |
47
|
|
|
$data['currency'] = $this->getCurrency(); |
48
|
|
|
$data['description'] = $this->getDescription(); |
49
|
|
|
|
50
|
|
|
return $data; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function sendData($data) |
54
|
|
|
{ |
55
|
|
|
$response = $this->soapCall($data); |
56
|
|
|
|
57
|
|
|
return $this->response = new RefundResponse($this, $response); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function soapCall($data) |
61
|
|
|
{ |
62
|
|
|
$datePart = gmdate('Ymd'); |
63
|
|
|
$timePart = gmdate('H'); |
64
|
|
|
$authString = "{$data['secret']}:{$datePart}:{$timePart}"; |
65
|
|
|
|
66
|
|
|
$sha256 = bin2hex(hash('sha256', $authString, true)); |
67
|
|
|
$secToken = strtoupper($sha256); |
68
|
|
|
|
69
|
|
|
try { |
70
|
|
|
$client = new \SoapClient( |
71
|
|
|
$this->endpoint, [ |
72
|
|
|
'soap_version' => SOAP_1_1, |
73
|
|
|
'stream_context' => stream_context_create( |
74
|
|
|
[ |
75
|
|
|
'ssl' => [ |
76
|
|
|
'verify_peer' => false, |
77
|
|
|
'verify_peer_name' => false, |
78
|
|
|
], |
79
|
|
|
] |
80
|
|
|
), |
81
|
|
|
] |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->WalletID = $data['walletId']; |
|
|
|
|
85
|
|
|
$this->SecurityToken = $secToken; |
|
|
|
|
86
|
|
|
$this->Currency = $data['currency']; |
|
|
|
|
87
|
|
|
$this->Receiver = $data['receiver']; |
|
|
|
|
88
|
|
|
$this->Amount = $data['amount']; |
|
|
|
|
89
|
|
|
$this->Comment = $data['description']; |
|
|
|
|
90
|
|
|
$this->IsReceiverPaysFees = false; |
|
|
|
|
91
|
|
|
|
92
|
|
|
$webService = $client->Send_Money($this); |
93
|
|
|
$wsResult = $webService->Send_MoneyResult; |
94
|
|
|
|
95
|
|
|
return $wsResult; |
96
|
|
|
} catch (\Exception $e) { |
97
|
|
|
throw new InvalidRequestException($e->getMessage()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.