Exemplo n.º 1
0
 public function testSettersAndGettersAttributes()
 {
     $preApproval = new PreApproval();
     $preApproval->setName('Name Assinatura');
     $preApproval->setChargeType('auto');
     $preApproval->setDetails('Cobranca Mensal');
     $preApproval->setPeriod('MONTHLY');
     $preApproval->setFinalDate(new DateTime('2016-11-18'));
     $preApproval->setMaxTotalAmount(3000);
     $preApproval->setAmountPerPayment(100);
     $preApproval->setMaxAmountPerPayment(150);
     $preApproval->setMaxPaymentsPerPeriod(12);
     $preApproval->setMaxAmountPerPeriod(1200);
     $preApproval->setInitialDate(new DateTime('2015-11-18'));
     $this->assertAttributeEquals('Name Assinatura', 'name', $preApproval);
     $this->assertAttributeEquals('auto', 'chargeType', $preApproval);
     $this->assertAttributeEquals('Cobranca Mensal', 'details', $preApproval);
     $this->assertAttributeEquals('MONTHLY', 'period', $preApproval);
     $this->assertAttributeEquals(new DateTime('2016-11-18'), 'finalDate', $preApproval);
     $this->assertAttributeEquals(3000, 'maxTotalAmount', $preApproval);
     $this->assertAttributeEquals(100, 'amountPerPayment', $preApproval);
     $this->assertAttributeEquals(150, 'maxAmountPerPayment', $preApproval);
     $this->assertAttributeEquals(12, 'maxPaymentsPerPeriod', $preApproval);
     $this->assertAttributeEquals(1200, 'maxAmountPerPeriod', $preApproval);
     $this->assertAttributeEquals(new DateTime('2015-11-18'), 'initialDate', $preApproval);
     $this->assertEquals('Name Assinatura', $preApproval->getName());
     $this->assertEquals('auto', $preApproval->getChargeType());
     $this->assertEquals('Cobranca Mensal', $preApproval->getDetails());
     $this->assertEquals('MONTHLY', $preApproval->getPeriod());
     $this->assertEquals(new DateTime('2016-11-18'), $preApproval->getFinalDate());
     $this->assertEquals(3000, $preApproval->getMaxTotalAmount());
     $this->assertEquals(100, $preApproval->getAmountPerPayment());
     $this->assertEquals(150, $preApproval->getMaxAmountPerPayment());
     $this->assertEquals(12, $preApproval->getMaxPaymentsPerPeriod());
     $this->assertEquals(1200, $preApproval->getMaxAmountPerPeriod());
     $this->assertEquals(new DateTime('2015-11-18'), $preApproval->getInitialDate());
 }
 public function testSerializeShouldXMLFull()
 {
     $preApproval = new PreApproval();
     $preApproval->setChargeType('auto');
     $preApproval->setName('Assinatura Revista');
     $preApproval->setPeriod('MONTHLY');
     $preApproval->setFinalDate(new DateTime('2016-11-18'));
     $preApproval->setMaxTotalAmount(3000);
     $preApproval->setDetails('Cobranca Mensal da Revista');
     $preApproval->setAmountPerPayment(100);
     $preApproval->setMaxAmountPerPayment(150);
     $preApproval->setInitialDate(new DateTime('2015-11-18'));
     $preApproval->setMaxPaymentsPerPeriod(12);
     $preApproval->setMaxAmountPerPeriod(1200);
     $customerAddress = new Address('AC', 'Sao Maite', '99500-079', 'Centro', 'Rua David Delgado', '55', 'Fundos');
     $customerPhone = new Phone('11', '99999999');
     $customer = new Customer('*****@*****.**', 'FooBar', $customerPhone, $customerAddress);
     $request = new Request($preApproval);
     $request->setCustomer($customer);
     $request->setReference('abcdef');
     $request->setReviewOn('http://localhost/return.php');
     $request->setRedirectTo('http://localhost/success.php');
     $serializer = new RequestSerializer();
     $xml = $serializer->serialize($request);
     $this->assertInstanceOf(SimpleXMLElement::class, $xml);
     $expected = simplexml_load_file(__DIR__ . '/xml/preAprovalsRequestFull.xml');
     $this->assertEquals($expected, $xml);
 }
 /**
  * @param SimpleXMLElement $xml
  * @param PreApproval $approval
  */
 private function appendPreApproval(SimpleXMLElement $xml, PreApproval $approval)
 {
     $child = $xml->addChild('preApproval');
     $child->addChild('charge', $approval->getChargeType());
     $child->addChild('name', substr($approval->getName(), 0, 100));
     $child->addChild('period', $approval->getPeriod());
     $child->addChild('finalDate', $approval->getFinalDate()->format(DateTime::W3C));
     $child->addChild('maxTotalAmount', number_format($approval->getMaxTotalAmount(), 2, '.', ''));
     if ($details = $approval->getDetails()) {
         $child->addChild('details', substr($details, 0, 255));
     }
     if ($amountPerPayment = $approval->getAmountPerPayment()) {
         $child->addChild('amountPerPayment', number_format($amountPerPayment, 2, '.', ''));
     }
     if ($maxAmountPerPayment = $approval->getMaxAmountPerPayment()) {
         $child->addChild('maxAmountPerPayment', number_format($maxAmountPerPayment, 2, '.', ''));
     }
     if ($initialDate = $approval->getInitialDate()) {
         $child->addChild('initialDate', $initialDate->format(DateTime::W3C));
     }
     if ($maxPaymentsPerPeriod = $approval->getMaxPaymentsPerPeriod()) {
         $child->addChild('maxPaymentsPerPeriod', (int) $maxPaymentsPerPeriod);
     }
     if ($maxAmountPerPeriod = $approval->getMaxAmountPerPeriod()) {
         $child->addChild('maxAmountPerPeriod', number_format($maxAmountPerPeriod, 2, '.', ''));
     }
 }