AvaiBookSports /
omnipay-redsys
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Omnipay\Redsys\Message; |
||||
| 6 | |||||
| 7 | use SimpleXMLElement; |
||||
| 8 | |||||
| 9 | class CaptureRequest extends AbstractRequest |
||||
| 10 | { |
||||
| 11 | use WebserviceTrait; |
||||
| 12 | |||||
| 13 | public function getData() |
||||
| 14 | { |
||||
| 15 | $this->validate('merchantId', 'terminalId', 'amount', 'currency'); |
||||
| 16 | |||||
| 17 | $data = [ |
||||
| 18 | // mandatory fields |
||||
| 19 | 'DS_MERCHANT_ORDER' => $this->getTransactionId(), |
||||
| 20 | 'DS_MERCHANT_MERCHANTCODE' => (string) $this->getMerchantId(), |
||||
| 21 | 'DS_MERCHANT_TERMINAL' => (string) $this->getTerminalId(), |
||||
| 22 | 'DS_MERCHANT_CURRENCY' => (string) $this->getCurrencyNumeric(), |
||||
| 23 | 'DS_MERCHANT_TRANSACTIONTYPE' => '2', |
||||
| 24 | 'DS_MERCHANT_AMOUNT' => (string) $this->getAmountInteger(), |
||||
| 25 | ]; |
||||
| 26 | |||||
| 27 | $request = new SimpleXMLElement('<REQUEST/>'); |
||||
| 28 | $requestData = $request->addChild('DATOSENTRADA'); |
||||
| 29 | foreach ($data as $tag => $value) { |
||||
| 30 | $requestData->addChild($tag, $value); |
||||
| 31 | } |
||||
| 32 | |||||
| 33 | $security = new Security(); |
||||
| 34 | |||||
| 35 | $request->addChild('DS_SIGNATUREVERSION', Security::VERSION); |
||||
| 36 | $request->addChild('DS_SIGNATURE', $security->createSignature( |
||||
| 37 | $requestData->asXML(), |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 38 | $data['DS_MERCHANT_ORDER'], |
||||
| 39 | $this->getHmacKey() |
||||
| 40 | )); |
||||
| 41 | |||||
| 42 | // keep data as nested array for method signature compatibility |
||||
| 43 | return [ |
||||
| 44 | 'DATOSENTRADA' => $data, |
||||
| 45 | 'DS_SIGNATUREVERSION' => (string) $request->DS_SIGNATUREVERSION, |
||||
| 46 | 'DS_SIGNATURE' => (string) $request->DS_SIGNATURE, |
||||
| 47 | ]; |
||||
| 48 | } |
||||
| 49 | |||||
| 50 | public function sendData($data) |
||||
| 51 | { |
||||
| 52 | // re-create the XML |
||||
| 53 | $request = new SimpleXMLElement('<REQUEST/>'); |
||||
| 54 | $requestData = $request->addChild('DATOSENTRADA'); |
||||
| 55 | foreach ($data['DATOSENTRADA'] as $tag => $value) { |
||||
| 56 | $requestData->addChild($tag, $value); |
||||
| 57 | } |
||||
| 58 | $request->addChild('DS_SIGNATUREVERSION', $data['DS_SIGNATUREVERSION']); |
||||
| 59 | $request->addChild('DS_SIGNATURE', $data['DS_SIGNATURE']); |
||||
| 60 | |||||
| 61 | // wrap in SOAP envelope |
||||
| 62 | $requestEnvelope = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> |
||||
| 63 | <soapenv:Header/> |
||||
| 64 | <soapenv:Body> |
||||
| 65 | <impl:trataPeticion xmlns:impl='http://webservice.sis.sermepa.es'> |
||||
| 66 | <impl:datosEntrada> |
||||
| 67 | ".htmlspecialchars($request->asXML()).' |
||||
|
0 ignored issues
–
show
It seems like
$request->asXML() can also be of type true; however, parameter $string of htmlspecialchars() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 68 | </impl:datosEntrada> |
||||
| 69 | </impl:trataPeticion> |
||||
| 70 | </soapenv:Body> |
||||
| 71 | </soapenv:Envelope>'; |
||||
| 72 | |||||
| 73 | // send the actual SOAP request |
||||
| 74 | $httpResponse = $this->httpClient->request( |
||||
| 75 | 'POST', |
||||
| 76 | $this->getEndpoint(), |
||||
| 77 | ['SOAPAction' => 'trataPeticion'], |
||||
| 78 | $requestEnvelope |
||||
| 79 | ); |
||||
| 80 | |||||
| 81 | // unwrap httpResponse into actual data as SimpleXMLElement tree |
||||
| 82 | $responseEnvelope = simplexml_load_string($httpResponse->getBody()->getContents()); |
||||
| 83 | $responseData = new SimpleXMLElement(htmlspecialchars_decode( |
||||
| 84 | (string) $responseEnvelope->children('http://schemas.xmlsoap.org/soap/envelope/') |
||||
| 85 | ->Body->children('http://webservice.sis.sermepa.es') |
||||
| 86 | ->trataPeticionResponse |
||||
| 87 | ->trataPeticionReturn |
||||
| 88 | )); |
||||
| 89 | |||||
| 90 | // convert to nested arrays (drop the 'true' to use simple objects) |
||||
| 91 | $responseData = json_decode(json_encode($responseData), true); |
||||
| 92 | |||||
| 93 | return $this->response = new CaptureResponse($this, $responseData); |
||||
| 94 | } |
||||
| 95 | } |
||||
| 96 |