|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Omnipay\Paysafecard\Message; |
| 4 | + |
| 5 | +use Omnipay\Common\Exception\InvalidResponseException; |
| 6 | +use Omnipay\Common\Message\AbstractResponse; |
| 7 | + |
| 8 | +/** |
| 9 | + * Paysafecard Abstract Request. |
| 10 | + * |
| 11 | + * @author Alexander Fedra <contact@dercoder.at> |
| 12 | + * @copyright 2015 DerCoder |
| 13 | + * @license http://opensource.org/licenses/mit-license.php MIT |
| 14 | + * |
| 15 | + * @version 1.1 Paysafecard API Specification |
| 16 | + */ |
| 17 | +abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest |
| 18 | +{ |
| 19 | + protected $liveEndpoint = 'https://soa.paysafecard.com/psc/services/PscService'; |
| 20 | + protected $testEndpoint = 'https://soatest.paysafecard.com/psc/services/PscService'; |
| 21 | + |
| 22 | + /** |
| 23 | + * Get the method for this request. |
| 24 | + * |
| 25 | + * @return string method |
| 26 | + */ |
| 27 | + abstract protected function getMethod(); |
| 28 | + |
| 29 | + /** |
| 30 | + * Get the username. |
| 31 | + * |
| 32 | + * Custom account username provided by paysafecard for the authentication. |
| 33 | + * |
| 34 | + * @return string username |
| 35 | + */ |
| 36 | + public function getUsername() |
| 37 | + { |
| 38 | + return $this->getParameter('username'); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Set the username. |
| 43 | + * |
| 44 | + * Custom account username provided by paysafecard for the authentication. |
| 45 | + * |
| 46 | + * @param string $value username |
| 47 | + * |
| 48 | + * @return self |
| 49 | + */ |
| 50 | + public function setUsername($value) |
| 51 | + { |
| 52 | + return $this->setParameter('username', $value); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Get the password. |
| 57 | + * |
| 58 | + * Custom account password provided by paysafecard for the authentication. |
| 59 | + * |
| 60 | + * @return string password |
| 61 | + */ |
| 62 | + public function getPassword() |
| 63 | + { |
| 64 | + return $this->getParameter('password'); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Set the password. |
| 69 | + * |
| 70 | + * Custom account password provided by paysafecard for the authentication. |
| 71 | + * |
| 72 | + * @param string $value password |
| 73 | + * |
| 74 | + * @return self |
| 75 | + */ |
| 76 | + public function setPassword($value) |
| 77 | + { |
| 78 | + return $this->setParameter('password', $value); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Get the sub ID. |
| 83 | + * |
| 84 | + * mandatory parameter, value must be left empty if nothing else is agreed. |
| 85 | + * so-called ‘reporting criteria’, offers the possibility to classify transactions. |
| 86 | + * max. length: 8 characters (case sensitive) |
| 87 | + * agreement with paysafecard needed |
| 88 | + * example: shop1 |
| 89 | + * |
| 90 | + * @return string sub id |
| 91 | + */ |
| 92 | + public function getSubId() |
| 93 | + { |
| 94 | + return $this->getParameter('subId'); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Set the sub ID. |
| 99 | + * |
| 100 | + * mandatory parameter, value must be left empty if nothing else is agreed. |
| 101 | + * so-called ‘reporting criteria’, offers the possibility to classify transactions. |
| 102 | + * max. length: 8 characters (case sensitive) |
| 103 | + * agreement with paysafecard needed |
| 104 | + * example: shop1 |
| 105 | + * |
| 106 | + * @param string $value sub id |
| 107 | + * |
| 108 | + * @return self |
| 109 | + */ |
| 110 | + public function setSubId($value) |
| 111 | + { |
| 112 | + return $this->setParameter('subId', $value); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Get the endpoint for this request. |
| 117 | + * |
| 118 | + * @return string endpoint |
| 119 | + */ |
| 120 | + public function getEndpoint() |
| 121 | + { |
| 122 | + return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Send the request with specified data. |
| 127 | + * |
| 128 | + * @param mixed $data The data to send |
| 129 | + * |
| 130 | + * @throws InvalidResponseException |
| 131 | + * |
| 132 | + * @return AbstractResponse |
| 133 | + */ |
| 134 | + public function sendData($data) |
| 135 | + { |
| 136 | + $endpoint = $this->getEndpoint(); |
| 137 | + $headers = array( |
| 138 | + 'Content-Type' => 'text/xml; charset=utf-8', |
| 139 | + 'SOAPAction' => $endpoint.'/'.$this->getMethod(), |
| 140 | + ); |
| 141 | + |
| 142 | + $httpResponse = $this->httpClient->post($endpoint, $headers, $data)->send(); |
| 143 | + //var_dump($httpResponse->getRawHeaders()); |
| 144 | + //var_dump((string)$httpResponse->getBody()); |
| 145 | + return $this->createResponse($httpResponse->xml()); |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Get the response from request. |
| 150 | + * |
| 151 | + * @param \SimpleXMLElement $xml |
| 152 | + * |
| 153 | + * @return AbstractResponse |
| 154 | + */ |
| 155 | + abstract protected function createResponse(\SimpleXMLElement $xml); |
| 156 | +} |
0 commit comments