/** * HostedPaymentResponse validates the hosted payment response. * * For successful payment requests it sets the accepted attribute to 1 and * other response attributes accordingly. * * In case of a response error, it sets the the accepted attribute to 0 and * the resultcode to 0. For responses indicating that something went wrong * at the service, it sets accepted to 0 and responsecode with corresponding * errormessage accordingly. * * @param string $response hosted request response xml message * @param string $countryCode two-letter country code * @param ConfigurationProvider $config */ function __construct($response, $countryCode, $config) { if (is_array($response)) { if (array_key_exists("mac", $response)) { if (array_key_exists("response", $response)) { $decodedXml = base64_decode($response["response"]); $secret = $config->getSecret(\ConfigurationProvider::HOSTED_TYPE, $countryCode); if ($this->validateMac($response["response"], $response['mac'], $secret)) { $this->formatXml($decodedXml); } else { $this->accepted = 0; $this->resultcode = '0'; $this->errormessage = "Response failed authorization. MAC not valid."; } } else { $this->accepted = 0; $this->resultcode = '0'; $this->errormessage = "Response is not recognized."; } } else { $this->accepted = 0; $this->resultcode = '0'; $this->errormessage = "Response is not recognized."; } } else { $this->accepted = 0; $this->resultcode = '0'; $this->errormessage = "Response is not recognized."; } }
/** * populates the payment form object from the given parameters and generates * the $completeHtmlFormWithSubmitButton & $htmlFormFieldsAsArray attributes * * @param type $xmlMessage * @param ConfigurationProvider $config * @param string $countryCode */ function __construct($xmlMessage, $config, $countryCode = NULL) { $this->xmlMessage = $xmlMessage; $this->xmlMessageBase64 = base64_encode($xmlMessage); $this->endPointUrl = $config->getEndPoint(\ConfigurationProvider::HOSTED_TYPE); $this->merchantid = $config->getMerchantId(\ConfigurationProvider::HOSTED_TYPE, $countryCode); $this->secretWord = $config->getSecret(\ConfigurationProvider::HOSTED_TYPE, $countryCode); $this->mac = hash("sha512", $this->xmlMessageBase64 . $this->secretWord); $this->setForm(); $this->setHtmlFields(); $this->setRawFields(); $this->setSubmitMessage(); }
/** * Performs a request using cURL, parsing the response using SveaResponse * and returning the resulting HostedAdminResponse instance. * * @return HostedAdminResponse */ public function doRequest() { $fields = $this->prepareRequest(); $fieldsString = ""; foreach ($fields as $key => $value) { $fieldsString .= $key . '=' . $value . '&'; } rtrim($fieldsString, '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->config->getEndpoint(\Svea\SveaConfigurationProvider::HOSTED_ADMIN_TYPE) . $this->method); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldsString); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //force curl to trust https curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //returns a html page with redirecting to bank... $responseXML = curl_exec($ch); curl_close($ch); // create SveaResponse to handle response $responseObj = new \SimpleXMLElement($responseXML); return $this->parseResponse($responseObj); }
/** * Constructor, sets up soap server and SoapClient * @param ConfigurationProvider $config * @param string $orderType -- see ConfigurationProvider:: constants */ public function __construct($config, $ordertype) { $this->svea_server = $config->getEndPoint($ordertype); $this->client = $this->SetSoapClient($config); }
/** * Allows to register a configuration provider that is specified by the * ConfigurationProvider interface. Please note, that the extension is * the file extension of the configuration file. * * @param string $extension The file extension. * @param ConfigurationProvider $provider The provider to register. * * @author Christian Achatz * @version * Version 0.1, 27.09.2010<br /> * Version 0.2, 10.10.2010 (Added support to inject the extension into the provider to reuse a provider for several extensions)<br /> */ public static function registerProvider($extension, ConfigurationProvider $provider) { $provider->setExtension($extension); self::$PROVIDER[strtolower($extension)] = $provider; }