예제 #1
0
 public function testMakeOrderJwtWithExistingApplication()
 {
     $order = Order::create($expectedPackageId = 123);
     $order->setAppId($expectedApplicationId = 456)->setPrice($expectedPrice = 100)->setTrialDuration($expectedTrialDuration = 3)->setTrialDurationUnit($expectedTrialDurationUnit = Order::DURATION_UNIT_MONTH)->setFirstBillingDate($expectedFirstBillingDate = new \DateTime('now +1 day'))->setBillingDayOfMonth($expectedBillingDayOfMonth = 15)->setDescription($expectedDescription = 'description');
     $client = new MarketClient($encoder = new Encoder(), new PrivateKeyFileProvider('file://' . __DIR__ . '/key.pem'), $expectedIssuer = 'zYua50VjHMoK443jTsKaentBe15U6z4B', $expectedTarget = 'https://market.appsco.com/checkout');
     $response = $client->makeOrder($order);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\RedirectResponse', $response);
     $url = $response->getTargetUrl();
     $this->assertStringStartsWith($expectedTarget, $url);
     $jwt = null;
     $arr = parse_url($url);
     $query = $arr['query'];
     parse_str($query);
     $this->assertNotEmpty($jwt);
     /** @var Order $jwt */
     $jwt = $encoder->decode($jwt, 'Appsco\\Market\\ApiBundle\\Model\\Order');
     $this->assertNotEmpty($jwt->getJwtId());
     $this->assertEquals($expectedIssuer, $jwt->getIssuer());
     $this->assertGreaterThanOrEqual(0, time() - $jwt->getIssuedAt());
     $this->assertInstanceOf('Appsco\\Market\\ApiBundle\\Model\\Order', $jwt);
     $this->assertEquals($expectedPackageId, $jwt->getPackageId());
     $this->assertEquals($expectedApplicationId, $order->getAppId());
     $this->assertEquals($expectedPrice, $order->getPrice());
     $this->assertEquals($expectedTrialDuration, $order->getTrialDuration());
     $this->assertEquals($expectedTrialDurationUnit, $order->getTrialDurationUnit());
     $this->assertEquals($expectedFirstBillingDate->setTime(0, 0, 0), $order->getFirstBillingDate());
     $this->assertEquals($expectedBillingDayOfMonth, $order->getBillingDayOfMonth());
     $this->assertEquals($expectedDescription, $order->getDescription());
     $encoder->verify($jwt, 'file://' . __DIR__ . '/key.crt');
 }
 /**
  * @param Notification $notification
  * @throws InvalidNotificationException
  * @return void
  */
 public function validate(Notification $notification)
 {
     $certificateList = $this->client->certificateGet($notification->getIssuer());
     if (0 == count($certificateList->getCertificates())) {
         throw new InvalidNotificationException(sprintf("Issuer '%s' has no Appsco certificates", $notification->getIssuer()));
     }
     $error = null;
     foreach ($certificateList->getCertificates() as $certificate) {
         try {
             $this->jwtEncoder->verify($notification, $certificate->getCertificate());
             $error = null;
             break;
         } catch (\Exception $ex) {
             $error = $ex;
         }
     }
     if ($error) {
         throw new InvalidNotificationException(sprintf("Unable to verify certificate of issuer '%s'", $notification->getIssuer()), 0, $error);
     }
 }