1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* WebMoney driver for the Omnipay PHP payment processing library |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/ck-developer/omnipay-payline |
7
|
|
|
* @package omnipay-payline |
8
|
|
|
* @license MIT |
9
|
|
|
* @copyright Copyright (c) 2016 Claude Khedhiri <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Omnipay\Payline\Message; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Authorize Request. |
16
|
|
|
* |
17
|
|
|
* @method WebAuthorizeResponse send() |
18
|
|
|
*/ |
19
|
|
|
class WebAuthorizeRequest extends AbstractRequest |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @return bool |
23
|
|
|
*/ |
24
|
6 |
|
public function getMethod() |
25
|
|
|
{ |
26
|
6 |
|
return 'doWebPayment'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
3 |
|
public function getDate() |
33
|
|
|
{ |
34
|
3 |
|
return $this->getParameter('date'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $date |
39
|
|
|
* |
40
|
|
|
* @return $this |
41
|
|
|
*/ |
42
|
3 |
|
public function setDate($date) |
43
|
|
|
{ |
44
|
3 |
|
if ($date instanceof \DateTime) { |
45
|
3 |
|
$date = $date->format('d/m/Y H:i'); |
46
|
3 |
|
} |
47
|
|
|
|
48
|
3 |
|
return $this->setParameter('date', $date); |
49
|
|
|
} |
50
|
|
|
|
51
|
3 |
|
public function getData() |
52
|
|
|
{ |
53
|
3 |
|
$data['payment'] = array( |
|
|
|
|
54
|
3 |
|
'amount' => $this->getAmountInteger(), |
55
|
3 |
|
'currency' => $this->getCurrencyNumeric(), |
56
|
3 |
|
'action' => 100, |
57
|
3 |
|
'mode' => 'CPT', |
58
|
|
|
); |
59
|
|
|
|
60
|
3 |
|
if ($this->getContractNumber()) { |
61
|
3 |
|
$data['payment']['contractNumber'] = $this->getContractNumber(); |
62
|
3 |
|
} |
63
|
|
|
|
64
|
3 |
|
$data['order'] = array( |
65
|
3 |
|
'ref' => $this->getTransactionReference(), |
66
|
3 |
|
'amount' => $this->getAmountInteger(), |
67
|
3 |
|
'currency' => $this->getCurrencyNumeric(), |
68
|
|
|
); |
69
|
|
|
|
70
|
3 |
|
$data['order']['date'] = $this->getDate(); |
71
|
|
|
|
72
|
3 |
|
$data['returnURL'] = $this->getReturnUrl(); |
73
|
3 |
|
$data['cancelURL'] = $this->getCancelUrl(); |
74
|
3 |
|
$data['notificationURL'] = $this->getNotifyUrl(); |
75
|
|
|
|
76
|
3 |
|
return array_replace_recursive($this->getBaseData(), $data); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param \stdClass $data |
81
|
|
|
* |
82
|
|
|
* @return WebAuthorizeResponse |
83
|
|
|
*/ |
84
|
3 |
|
protected function createResponse($data) |
85
|
|
|
{ |
86
|
3 |
|
return $this->response = new WebAuthorizeResponse($this, $data); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.