Skip to content

Commit

Permalink
Merge pull request #105 from Payum/klarna-checkout
Browse files Browse the repository at this point in the history
Add Klarna Checkout.
  • Loading branch information
makasim committed Mar 12, 2014
2 parents 5f8d9a9 + 4265622 commit eda4d61
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 25 deletions.
38 changes: 16 additions & 22 deletions Request/PostRedirectUrlInteractiveRequest.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
<?php

namespace Payum\Core\Request;

class PostRedirectUrlInteractiveRequest extends BaseInteractiveRequest
class PostRedirectUrlInteractiveRequest extends ResponseInteractiveRequest
{
/**
* @var string
* @param string $content
* @param array $fields
*/
protected $url;

/**
* @var array
*/
protected $post;

/**
* @param string $url
* @param array $post
*/
public function __construct($url, array $post = array())
public function __construct($content, array $fields = array())
{
$this->url = $url;
$this->post = $post;
parent::__construct($this->prepareContent($content, $fields));
}

public function getContent()
/**
* @param $url
* @param array $fields
*
* @return string
*/
protected function prepareContent($url, array $fields)
{
$formFields = '';
foreach ($this->post as $name => $value) {
$formFields .= sprintf(
$formInputs = '';
foreach ($fields as $name => $value) {
$formInputs .= sprintf(
'<input type="hidden" name="%1$s" value="%2$s" />',
htmlspecialchars($name, ENT_QUOTES, 'UTF-8'),
htmlspecialchars($value, ENT_QUOTES, 'UTF-8')
Expand All @@ -50,6 +44,6 @@ public function getContent()
</html>
HTML;

return sprintf($content, htmlspecialchars($this->url, ENT_QUOTES, 'UTF-8'), $formFields);
return sprintf($content, htmlspecialchars($url, ENT_QUOTES, 'UTF-8'), $formInputs);
}
}
6 changes: 3 additions & 3 deletions Request/RedirectUrlInteractiveRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class RedirectUrlInteractiveRequest extends BaseInteractiveRequest
protected $url;

/**
* @param string $url
* @param string $content
*/
public function __construct($url)
public function __construct($content)
{
$this->url = $url;
$this->url = $content;
}

/**
Expand Down
26 changes: 26 additions & 0 deletions Request/ResponseInteractiveRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace Payum\Core\Request;

class ResponseInteractiveRequest extends BaseInteractiveRequest
{
/**
* @var string
*/
protected $content;

/**
* @param string $content
*/
public function __construct($content)
{
$this->content = $content;
}

/**
* @return string
*/
public function getContent()
{
return $this->content;
}
}
1 change: 1 addition & 0 deletions Resources/docs/supported-payments.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [Be2Bill Onsite](https://github.com/Payum/Be2Bill/blob/master/Resources/docs/index.md)
* [Payex](https://github.com/Payum/Payex/blob/master/Resources/docs/index.md)
* [Offline](https://github.com/Payum/Offline/blob/master/Resources/docs/index.md)
* [Klarna Checkout](https://github.com/Payum/KlarnaCheckout/blob/master/Resources/docs/get-it-started.md)

## Community

Expand Down
10 changes: 10 additions & 0 deletions Tests/Request/PostRedirectUrlInterativeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public function shouldImplementInteractiveRequestInterface()
$this->assertTrue($rc->implementsInterface('Payum\Core\Request\InteractiveRequestInterface'));
}

/**
* @test
*/
public function shouldBeSubClassOfResponseInteractiveRequest()
{
$rc = new \ReflectionClass('Payum\Core\Request\PostRedirectUrlInteractiveRequest');

$this->assertTrue($rc->isSubclassOf('Payum\Core\Request\ResponseInteractiveRequest'));
}

/**
* @test
*/
Expand Down
37 changes: 37 additions & 0 deletions Tests/Request/ResponseInterativeRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace Payum\Core\Tests\Request;

use Payum\Core\Request\ResponseInteractiveRequest;

class ResponseInteractiveRequestTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function shouldImplementInteractiveRequestInterface()
{
$rc = new \ReflectionClass('Payum\Core\Request\ResponseInteractiveRequest');

$this->assertTrue($rc->implementsInterface('Payum\Core\Request\InteractiveRequestInterface'));
}

/**
* @test
*/
public function couldBeConstructedWithUrlAsArgument()
{
new ResponseInteractiveRequest('html page');
}

/**
* @test
*/
public function shouldAllowGetUrlSetInConstructor()
{
$expectedContent = 'html page';

$request = new ResponseInteractiveRequest($expectedContent);

$this->assertEquals($expectedContent, $request->getContent());
}
}

0 comments on commit eda4d61

Please sign in to comment.