/** * Test sending a payment request and receiving a payment response. */ public function testSend() { //get sample response XML $path = SampleXmlValidationUtils::PAYMENT_RESPONSE_XML_PATH; $prefix = __DIR__ . '/../../resources'; $xml = file_get_contents($prefix . $path); $fromXMLResponse = new PaymentResponse(); $fromXMLResponse = $fromXMLResponse->fromXml($xml); //mock HttpResponse /** @var HttpResponse $httpResponseMock */ $httpResponseMock = Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpResponse"); \Phockito::when($httpResponseMock->getBody())->return($fromXMLResponse->toXML()); \Phockito::when($httpResponseMock->getResponseCode())->return(200); // create empty request $request = new PaymentRequest(); $httpConfiguration = new HttpConfiguration(); $httpConfiguration->setOnlyAllowHttps(false); // mock HttpClient instance $httpClientMock = Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpClient"); \Phockito::when($httpClientMock->execute(\Hamcrest_Core_IsAnything::anything(), \Hamcrest_Core_IsAnything::anything()))->return($httpResponseMock); // execute and send on client $realexClient = new RealexClient(SampleXmlValidationUtils::SECRET, $httpConfiguration, $httpClientMock); $response = $realexClient->send($request); // validate response SampleXmlValidationUtils::checkUnmarshalledPaymentResponse($response, $this); }
/** * Tests conversion of {@link PaymentResponse} to and from XML. */ public function testPaymentResponseXmlAndDeserializeOverallResults() { $response = new PaymentResponse(); $response->setAccount(SampleXmlValidationUtils::ACCOUNT); $response->setAcquirerResponse(SampleXmlValidationUtils::ACQUIRER_RESPONSE); $response->setAuthCode(SampleXmlValidationUtils::AUTH_CODE); $response->setAuthTimeTaken(SampleXmlValidationUtils::AUTH_TIME_TAKEN); $response->setBatchId(SampleXmlValidationUtils::BATCH_ID); $cardIssuer = new CardIssuer(); $cardIssuer->setBank(SampleXmlValidationUtils::BANK); $cardIssuer->setCountry(SampleXmlValidationUtils::COUNTRY); $cardIssuer->setCountryCode(SampleXmlValidationUtils::COUNTRY_CODE); $cardIssuer->setRegion(SampleXmlValidationUtils::REGION); $response->setCardIssuer($cardIssuer); $response->setCvnResult(SampleXmlValidationUtils::CVN_RESULT); $response->setMerchantId(SampleXmlValidationUtils::MERCHANT_ID); $response->setMessage(SampleXmlValidationUtils::MESSAGE); $response->setOrderId(SampleXmlValidationUtils::ORDER_ID); $response->setPaymentsReference(SampleXmlValidationUtils::PASREF); $response->setResult(SampleXmlValidationUtils::RESULT_SUCCESS); $response->setHash(SampleXmlValidationUtils::RESPONSE_HASH); $response->setTimeStamp(SampleXmlValidationUtils::TIMESTAMP_RESPONSE); $response->setTimeTaken(SampleXmlValidationUtils::TIME_TAKEN); $tssResult = new TssResult(); $tssResult->setResult(SampleXmlValidationUtils::TSS_RESULT); $response->setTssResult($tssResult); $response->setAvsAddressResponse(SampleXmlValidationUtils::AVS_ADDRESS); $response->setAvsPostcodeResponse(SampleXmlValidationUtils::AVS_POSTCODE); //marshal to XML $xml = $response->toXml(); //unmarshal back to response /* @var PaymentResponse $fromXmlResponse */ $fromXmlResponse = new PaymentResponse(); $fromXmlResponse = $fromXmlResponse->fromXml($xml); SampleXmlValidationUtils::checkUnmarshalledPaymentResponse($fromXmlResponse, $this, true); }