Ejemplo n.º 1
0
    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;
 }
Ejemplo n.º 3
0
    public function testPaymentIn()
    {
        $privKey = $this->getPrivateKeyPem();
        $pubKey = $this->getPublicKeyPem();

        $rawData = 'ulink:0.9:15:XKXvKJpR1iZZiTyYfctuDbnnIAj8WDaCtS9EbYlZxTKdUM9fbfdWWrcg7Lt7k5EuWxP8ai3q1lLe8tNeXKNaTURmFHjWs0WFObssqjKPW0LOxtqEfFPmZ88M1IkjrlYGV1UDKq/vbbdN2d2VVjv1poQr3aW9sXq4UKgUcVsM1irA0bswreyo32UMat62UVQa/jO1ktpc0cxv5CEny75zY0s1RS+9s8orFX6uQPRJOpFRQ2vRlUWjrnwdhdQrBtqzInml09Cs9MiZEaLcHTCrLUBIVJ4h@SgiRRv+oOinM3vA9aDOsfTGjzLePXWRD/ahmryLYEMpK84F4lV2uZAJflxjFDI6+sjX1DGq0vNDE0RUOLw5aSw==:onccukVgVf1T+cyA2CfExPdRVYefv9PnDjdcYC6ak7/f/xt2NC7VoZ6Odg3SxLQe1LA0sR+GkyqwRFXc1BaZqg==';

        $packet = Ulink_TransportPacket::createFromJson($rawData);
        $this->assertNotNull($packet);

        $this->assertEquals(15, $packet->getClientId());

        $this->assertNotNull($packet->getSignature());

        $this->assertTrue($packet->validateAgainstKey($pubKey));

        $request = Ulink_RequestFactory::createFromJson(
            Ulink_CryptoUtils::unseal($packet->getRequest(), $privKey)
        );
        $this->assertInstanceof('Ulink_PaymentRequest', $request);

        $paymentRequest = $request;
        $this->assertEquals("34.90", (string)$paymentRequest->getAmount());
        $this->assertEquals("EUR", $paymentRequest->getCurrency());

        $order = $paymentRequest->getOrder();
        $this->assertNotNull($order);
        $this->assertEquals(2, count($order->getItems()));

        $items = $order->getItems();
        $orderItem1 = $items[0];
        $orderItem2 = $items[1];

        $this->assertEquals("Milk", $orderItem1->getName());
        $this->assertEquals("Puhlqj ez", $orderItem1->getDescription());
        $this->assertEquals("25.90", (string)$orderItem1->getOneItemPrice());

        $this->assertEquals("Mja4ik", $orderItem2->getName());
        $this->assertEquals("Puhlqj mja4", $orderItem2->getDescription());
        $this->assertEquals("9.00", (string)$orderItem2->getOneItemPrice());
    }