public static function createFromJson($json) { $parts = explode(':', $json); $packet = new Ulink_TransportPacket(); $packet->setClientId($parts[2]); $packet->setRequest($parts[3]); $packet->setSignature(base64_decode($parts[4])); return $packet; }
public function testCreateFromJson() { $signature = "=signature="; $encodedSignature = base64_encode($signature); $packet = Ulink_TransportPacket::createFromJson('ulink:0.9:15:foobar:'.$encodedSignature); $this->assertEquals('foobar', $packet->getRequest()); $this->assertEquals('=signature=', $packet->getSignature()); $this->assertEquals(15, $packet->getClientId()); }
/** * @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; }
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()); }