/** * returns the request fields to post to service */ public function prepareRequest() { $this->validateRequest(); $xmlBuilder = new HostedXmlBuilder(); // get our merchantid & secret $merchantId = $this->config->getMerchantId(\ConfigurationProvider::HOSTED_TYPE, $this->countryCode); $secret = $this->config->getSecret(\ConfigurationProvider::HOSTED_TYPE, $this->countryCode); $message = $this->createRequestXml(); // calculate mac $mac = hash("sha512", base64_encode($message) . $secret); // encode the request elements $request_fields = array('merchantid' => urlencode($merchantId), 'message' => urlencode(base64_encode($message)), 'mac' => urlencode($mac)); return $request_fields; }
/** * 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(); }