/** * @test */ public function shouldAllowGetFirstAddress() { $request = new GetAddresses('aPno'); $request->addAddress($first = new \KlarnaAddr()); $request->addAddress($second = new \KlarnaAddr()); $this->assertSame($first, $request->getFirstAddress()); }
/** * @test */ public function shouldCallKlarnaGetAddresses() { $first = new \KlarnaAddr(); $first->setCountry('SE'); $second = new \KlarnaAddr(); $second->setCountry('SE'); $klarnaMock = $this->createKlarnaMock(); $klarnaMock->expects($this->once())->method('getAddresses')->with('thePno')->will($this->returnValue(array($first, $second))); $action = new GetAddressesAction($klarnaMock); $action->setApi(new Config()); $action->execute($getAddresses = new GetAddresses('thePno')); $this->assertCount(2, $getAddresses->getAddresses()); $this->assertSame($first, $getAddresses->getFirstAddress()); }
/** * @Extra\Route( * "/prepare_authorize_invoice", * name="acme_klarna_prepare_authorize_invoice" * ) * * @Extra\Template */ public function prepareAuthorizeInvoiceAction(Request $request) { $gatewayName = 'klarna_invoice'; /** @link http://developers.klarna.com/en/testing/invoice-and-account */ $pno = '410321-9202'; $payment = $this->getPayum()->getGateway($gatewayName); $payment->execute($getAddresses = new GetAddresses($pno)); $firstAddress = $getAddresses->getFirstAddress(); $firstAddress->setEmail($firstAddress->getEmail() ?: '*****@*****.**'); $firstAddress->setTelno($firstAddress->getTelno() ?: '0700 00 00 00'); $rawDetails = array('pno' => '410321-9202', 'amount' => -1, 'gender' => \KlarnaFlags::MALE, 'articles' => array(array('qty' => 4, 'artNo' => 'HANDLING', 'title' => 'Handling fee', 'price' => '50.99', 'vat' => '25', 'discount' => '0', 'flags' => \KlarnaFlags::INC_VAT | \KlarnaFlags::IS_HANDLING)), 'billing_address' => $firstAddress->toArray(), 'shipping_address' => $firstAddress->toArray()); if ($request->isMethod('POST')) { $storage = $this->getPayum()->getStorage('Acme\\PaymentBundle\\Model\\PaymentDetails'); /** @var $payment PaymentDetails */ $payment = $storage->create(); foreach ($rawDetails as $name => $value) { $payment[$name] = $value; } $storage->update($payment); $captureToken = $captureToken = $this->getTokenFactory()->createAuthorizeToken($gatewayName, $payment, 'acme_payment_details_view'); return $this->redirect($captureToken->getTargetUrl()); } return array('payment' => $rawDetails); }