public function testCreateRequestWithOrderFromJson() { $json = "{\"type\":\"pay-response\",\"timestamp\":123,\"id\":456,\"data\":{\"amount\":\"23.50\",\"currency\":\"EUR\"},\"success\":true,\"test\":true,\"errors\":[\"Wrong signature\"],\"errorCodes\":[17987]}"; $response = Ulink_RequestFactory::createFromJson($json); $this->assertEquals(Ulink_PaymentResponse::clazz(), get_class($response)); $this->assertEquals(123, $response->getTimestamp()); $paymentResponse = $response; $this->assertEquals(new Ulink_Money("23.50"), $paymentResponse->getAmount()); $this->assertEquals("EUR", $paymentResponse->getCurrency()); $this->assertEquals(123, $paymentResponse->getTimestamp()); $this->assertTrue($paymentResponse->isSuccess()); $this->assertTrue($paymentResponse->isTest()); $this->assertEquals(1, count($paymentResponse->getErrors())); $errors = $paymentResponse->getErrors(); $this->assertEquals("Wrong signature", $errors[0]); $this->assertEquals(1, count($paymentResponse->getErrorCodes())); $codes = $paymentResponse->getErrorCodes(); $this->assertEquals(17987, $codes[0]); }
/** * @throws Exception\UlinkException * @param string $rawData * @return array */ public function decrypt($rawData) { $packet = Ulink_TransportPacket::createFromJson($rawData); if (!$packet) { throw new UlinkException('Can not decrypt packet!'); } if ($this->getClientId() != $packet->getClientId()) { throw new UlinkException('Client id does not match the id given in configuration!'); } if (!$packet->getSignature()) { throw new UlinkException('Packet signature is broken!'); } if (!$packet->validateAgainstKey($this->getPublicKeyPem())) { throw new UlinkException('Data signature does not match the packet content!'); } $responseJson = Ulink_CryptoUtils::unseal($packet->getRequest(), $this->getPrivateKeyPem()); $response = Ulink_RequestFactory::createFromJson($responseJson); $result = array('clientTransactionId' => $response->getClientTransactionId(), 'amount' => (string) $response->getAmount(), 'currency' => $response->getCurrency()); $goBackUrl = $response->getGoBackUrl(); if ($goBackUrl) { $result['goBackUrl'] = $goBackUrl; } $responseUrl = $response->getResponseUrl(); if ($responseUrl) { $result['responseUrl'] = $responseUrl; } if (Ulink_PaymentResponse::clazz() == get_class($response)) { $result = array_merge($result, array('timestamp' => $response->getTimestamp(), 'success' => $response->isSuccess(), 'errors' => $response->getErrors(), 'errorCodes' => $response->getErrorCodes(), 'isTest' => $response->isTest())); } $order = $response->getOrder(); if ($order && count($order->getItems())) { $items = $order->getItems(); $result['order'] = array(); foreach ($items as $item) { $result['order'][] = array('name' => $item->getName(), 'description' => $item->getDescription(), 'oneItemPrice' => (string) $item->getOneItemPrice(), 'quantity' => $item->getQuantity()); } } return $result; }