Skip to content

Commit

Permalink
Merge pull request #7 from mgrinko/master
Browse files Browse the repository at this point in the history
Description accepts now multiple reasons
  • Loading branch information
iasci committed Apr 7, 2014
2 parents e033bcc + c66058e commit f5946e8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Omnipay/Sofort/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ public function getData()
);

$reasons = $data->addChild('reasons');
$reasons->addChild('reason', $this->getDescription());

if (is_string($this->getDescription())) {
$reasons->addChild('reason', $this->getDescription());
} elseif (is_array($this->getDescription())) {
foreach ($this->getDescription() as $reason) {
$reasons->addChild('reason', $reason);
}
}

$su = $data->addChild('su');
$su->addChild('customer_protection', 1);
Expand Down
27 changes: 27 additions & 0 deletions tests/Omnipay/Sofort/Message/AuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,31 @@ public function testGetData()
$this->assertSame('Order Description', (string) $data->reasons->reason);
$this->assertSame('1', (string) $data->su->customer_protection);
}

public function testGetDataWithMultilineDescription()
{
$request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest());

$request->initialize(array(
'amount' => '10.00',
'currency' => 'EUR',
'description' => array('Order Description line 1', 'Order Description line 2'),
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'notifyUrl' => 'https://www.example.com/notify',
));

$data = $request->getData();

$this->assertInstanceOf('SimpleXMLElement', $data);
$this->assertSame('10.00', (string) $data->amount);
$this->assertSame('EUR', (string) $data->currency_code);
$this->assertSame('de', (string) $data->language_code);
$this->assertSame('https://www.example.com/return', (string) $data->success_url);
$this->assertSame('https://www.example.com/cancel', (string) $data->abort_url);
$this->assertSame('https://www.example.com/notify', (string) $data->notification_urls[0]->notification_url);
$this->assertSame('Order Description line 1', (string) $data->reasons->reason[0]);
$this->assertSame('Order Description line 2', (string) $data->reasons->reason[1]);
$this->assertSame('1', (string) $data->su->customer_protection);
}
}

0 comments on commit f5946e8

Please sign in to comment.