|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Omnipay\CapitaPay360\Message; |
|
4
|
|
|
|
|
5
|
|
|
use SoapClient; |
|
6
|
|
|
use Omnipay\Common\Message\AbstractRequest; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* CapitaPay360 Purchase Request |
|
10
|
|
|
*/ |
|
11
|
|
|
class PurchaseRequest extends AbstractRequest |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var string */ |
|
14
|
|
|
protected $liveWSDL = 'https://sbsc.e-paycapita.com/scp/scpws/scpSimpleClient.wsdl'; |
|
15
|
|
|
/** @var string */ |
|
16
|
|
|
protected $testWSDL = 'https://sbsctest.e-paycapita.com/scp/scpws/scpSimpleClient.wsdl'; |
|
17
|
|
|
|
|
18
|
|
|
public function getCardholder() |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->getParameter('cardholder'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function setCardholder($value) |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->setParameter('cardholder', $value); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getConsumerLanguage() |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->getParameter('consumerLanguage'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getHmacKey() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->getParameter('hmacKey'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function setHmacKey($value) |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->setParameter('hmacKey', $value); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getMerchantData() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->getParameter('merchantData'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function setMerchantData($value) |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->setParameter('merchantData', $value); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getScpId() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getParameter('scpId'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function setScpId($value) |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->setParameter('scpId', $value); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getSiteID() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->getParameter('siteID'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function setSiteID($value) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->setParameter('siteID', $value); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getHmacKeyID() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->getParameter('hmacKeyID'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function setHmacKeyID($value) |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->setParameter('hmacKeyID', $value); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function getData() |
|
84
|
|
|
{ |
|
85
|
|
|
$this->validate('scpId', 'hmacKeyID', 'amount', 'currency'); |
|
86
|
|
|
$timeStamp = gmdate("YmdHis"); |
|
87
|
|
|
$uniqueReference = uniqid('PB'); |
|
88
|
|
|
$subjectType = 'CapitaPortal'; |
|
89
|
|
|
$algorithm = 'Original'; |
|
90
|
|
|
$credentialsToHash = implode('!', array( |
|
91
|
|
|
$subjectType, |
|
92
|
|
|
$this->getScpId(), |
|
93
|
|
|
$uniqueReference, |
|
94
|
|
|
$timeStamp, |
|
95
|
|
|
$algorithm, |
|
96
|
|
|
$this->getHmacKeyId() |
|
97
|
|
|
)); |
|
98
|
|
|
$key = base64_decode($this->getHmacKey()); |
|
99
|
|
|
$hash = hash_hmac('sha256', $credentialsToHash, $key, true); |
|
100
|
|
|
$digest = base64_encode($hash); |
|
101
|
|
|
|
|
102
|
|
|
// Create items array to return |
|
103
|
|
|
$saleItems = array(); |
|
104
|
|
|
$items = $this->getItems(); |
|
105
|
|
|
if ($items) { |
|
106
|
|
|
foreach($items as $itemIndex => $item) { |
|
107
|
|
|
$saleItems[] = array( |
|
108
|
|
|
'itemSummary' => array( |
|
109
|
|
|
'description' => $item->getDescription(), |
|
110
|
|
|
'amountInMinorUnits' => $item->getPrice() * pow(10, $this->getCurrencyDecimalPlaces()), |
|
111
|
|
|
'reference' => $item->getName(), |
|
112
|
|
|
), |
|
113
|
|
|
'quantity' => $item->getQuantity(), |
|
114
|
|
|
// 'lgItemDetails' => array( |
|
115
|
|
|
// 'fundCode' => $, |
|
116
|
|
|
// ), |
|
117
|
|
|
'lineId' => $itemIndex+1 |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return array( |
|
123
|
|
|
'credentials' => array( |
|
124
|
|
|
'subject' => array( |
|
125
|
|
|
'subjectType' => $subjectType, |
|
126
|
|
|
'identifier' => $this->getScpId(), |
|
127
|
|
|
'systemCode' => 'SCP' |
|
128
|
|
|
), |
|
129
|
|
|
'requestIdentification' => array( |
|
130
|
|
|
'uniqueReference' => $uniqueReference, |
|
131
|
|
|
'timeStamp' => $timeStamp |
|
132
|
|
|
), |
|
133
|
|
|
'signature' => array( |
|
134
|
|
|
'algorithm' => $algorithm, |
|
135
|
|
|
'hmacKeyID' => $this->getHmacKeyId(), |
|
136
|
|
|
'digest' => $digest |
|
137
|
|
|
) |
|
138
|
|
|
), |
|
139
|
|
|
'requestType' => 'payOnly', |
|
140
|
|
|
'requestId' => $this->getTransactionId(), |
|
141
|
|
|
'routing' => array( |
|
142
|
|
|
'returnUrl' => $this->getReturnUrl(), |
|
143
|
|
|
'backUrl' => $this->getCancelUrl(), |
|
144
|
|
|
'siteId' => $this->getSiteId(), |
|
145
|
|
|
'scpId' => $this->getScpId() |
|
146
|
|
|
), |
|
147
|
|
|
'panEntryMethod' => 'ECOM', |
|
148
|
|
|
'sale' => array( |
|
149
|
|
|
'items' => $saleItems, |
|
150
|
|
|
'saleSummary' => array( |
|
151
|
|
|
'description' => $this->getDescription(), |
|
152
|
|
|
'amountInMinorUnits' => $this->getAmountInteger() |
|
153
|
|
|
) |
|
154
|
|
|
) |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function sendData($data) |
|
159
|
|
|
{ |
|
160
|
|
|
$responseData = $this->getSoapClient()->scpSimpleInvoke($data); |
|
161
|
|
|
|
|
162
|
|
|
return $this->response = new PurchaseResponse($this, $responseData); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
protected function getSoapClient() { |
|
166
|
|
|
return new SoapClient($this->getEndpoint(), array()); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function getEndpoint() |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->getTestMode() ? $this->testWSDL : $this->liveWSDL; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|