Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add InitiatingSystemUserAgent #45

Merged
merged 6 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
interface PaymentInterface extends ResourceInterface
{
const INITIATING_SYSTEM_AGENT = 'initiatingSystemUserAgent';
const INTENT = 'intent';
const CURRENCY = 'currency';
const DESCRIPTION = 'description';
Expand All @@ -22,6 +23,21 @@ interface PaymentInterface extends ResourceInterface
const URLS = 'urls';
const PAYEE_INFO = 'payee_info';

/**
* Get Initiating System User Agent.
*
* @return string|null
*/
public function getInitiatingSystemUserAgent();

/**
* Set Initiating System User Agent.
*
* @param string $agent
* @return $this
*/
public function setInitiatingSystemUserAgent($agent);

/**
* @return string
*/
Expand Down
21 changes: 21 additions & 0 deletions src/SwedbankPay/Api/Service/Payment/Resource/PaymentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
*/
trait PaymentTrait
{
/**
* Get Initiating System User Agent.
*
* @return string|null
*/
public function getInitiatingSystemUserAgent()
{
return $this->offsetGet(self::INITIATING_SYSTEM_AGENT);
}

/**
* Set Initiating System User Agent.
*
* @param string $agent
* @return $this
*/
public function setInitiatingSystemUserAgent($agent)
{
return $this->offsetSet(self::INITIATING_SYSTEM_AGENT, $agent);
}

/**
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SwedbankPay\Api\Service\Payment\Resource\Request;

use SwedbankPay\Api\Client\ClientVersion;
use SwedbankPay\Api\Service\Payment\Resource\PaymentTrait;
use SwedbankPay\Api\Service\Payment\Resource\Request\Data\PayeeInfoInterface;
use SwedbankPay\Api\Service\Payment\Resource\Request\Data\PrefillInfoInterface;
Expand All @@ -17,6 +18,14 @@ class Payment extends RequestResource implements PaymentRequestInterface
{
use PaymentTrait;

public function __construct($data = [])
{
parent::__construct($data);

$version = new ClientVersion();
$this->setInitiatingSystemUserAgent('swedbankpay-sdk-php/' . $version->getVersion());
}

/**
* @return UrlInterface
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
interface PaymentorderInterface extends RequestInterface
{
const INITIATING_SYSTEM_AGENT = 'initiatingSystemUserAgent';
const CURRENCY = 'currency';
const AMOUNT = 'amount';
const VAT_AMOUNT = 'vat_amount';
Expand All @@ -36,6 +37,21 @@ interface PaymentorderInterface extends RequestInterface
const INTENT = 'intent';
const PAYMENT_TOKEN = 'payment_token';
const RISK_INDICATOR = 'risk_indicator';

/**
* Get Initiating System User Agent.
*
* @return string|null
*/
public function getInitiatingSystemUserAgent();

/**
* Set Initiating System User Agent.
*
* @param string $agent
* @return $this
*/
public function setInitiatingSystemUserAgent($agent);

/**
* @return string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SwedbankPay\Api\Service\Paymentorder\Resource\Request;

use SwedbankPay\Api\Client\ClientVersion;
use SwedbankPay\Api\Service\Paymentorder\Resource\Collection\OrderItemsCollection;
use SwedbankPay\Api\Service\Paymentorder\Resource\Collection\PaymentorderItemsCollection;
use SwedbankPay\Api\Service\Paymentorder\Resource\Data\PaymentorderRiskIndicatorInterface;
Expand All @@ -17,6 +18,40 @@
*/
class Paymentorder extends RequestResource implements PaymentorderInterface
{
/**
* Paymentorder constructor.
*
* @param array $data
*/
public function __construct($data = [])
{
parent::__construct($data);

$version = new ClientVersion();
$this->setInitiatingSystemUserAgent('swedbankpay-sdk-php/' . $version->getVersion());
}

/**
* Get Initiating System User Agent.
*
* @return string|null
*/
public function getInitiatingSystemUserAgent()
{
return $this->offsetGet(self::INITIATING_SYSTEM_AGENT);
}

/**
* Set Initiating System User Agent.
*
* @param string $agent
* @return $this
*/
public function setInitiatingSystemUserAgent($agent)
{
return $this->offsetSet(self::INITIATING_SYSTEM_AGENT, $agent);
}

/**
* @return string
*/
Expand Down
23 changes: 23 additions & 0 deletions tests/PaymentRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use SwedbankPay\Api\Service\Payment\Resource\Request\Payment;

class PaymentRequestTest extends TestCase
{
public function testInitiatingSystemUserAgent()
{
$payment = new Payment();

$this->assertTrue(method_exists($payment, 'getInitiatingSystemUserAgent'));
$this->assertTrue(method_exists($payment, 'setInitiatingSystemUserAgent'));

$result = $payment->setInitiatingSystemUserAgent('swedbankpay-sdk-php/123');
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Payment\Resource\Request\Data\PaymentRequestInterface',
$result
);

$result = $payment->getInitiatingSystemUserAgent();
$this->assertEquals('swedbankpay-sdk-php/123', $result);
}
}
177 changes: 177 additions & 0 deletions tests/PaymentorderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

use SwedbankPay\Api\Service\Paymentorder\Resource\Request\Paymentorder;

class PaymentorderTest extends TestCase
{
public function testInitiatingSystemUserAgent()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'getInitiatingSystemUserAgent'));
$this->assertTrue(method_exists($paymentOrder, 'setInitiatingSystemUserAgent'));

$result = $paymentOrder->setInitiatingSystemUserAgent('swedbankpay-sdk-php/123');
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->getInitiatingSystemUserAgent();
$this->assertEquals('swedbankpay-sdk-php/123', $result);
}

public function testCurrency()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'getCurrency'));
$this->assertTrue(method_exists($paymentOrder, 'setCurrency'));

$result = $paymentOrder->setCurrency('SEK');
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->getCurrency();
$this->assertEquals('SEK', $result);
}

public function testAmount()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'getAmount'));
$this->assertTrue(method_exists($paymentOrder, 'setAmount'));

$result = $paymentOrder->setAmount(1);
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->getAmount();
$this->assertEquals(1, $result);
}

public function testVatAmount()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'getVatAmount'));
$this->assertTrue(method_exists($paymentOrder, 'setVatAmount'));

$result = $paymentOrder->setVatAmount(1);
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->getVatAmount();
$this->assertEquals(1, $result);
}

public function testDescription()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'getDescription'));
$this->assertTrue(method_exists($paymentOrder, 'setDescription'));

$result = $paymentOrder->setDescription('Description');
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->getDescription();
$this->assertEquals('Description', $result);
}

public function testUserAgent()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'getUserAgent'));
$this->assertTrue(method_exists($paymentOrder, 'setUserAgent'));

$result = $paymentOrder->setUserAgent('UserAgent');
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->getUserAgent();
$this->assertEquals('UserAgent', $result);
}

public function testLanguage()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'getLanguage'));
$this->assertTrue(method_exists($paymentOrder, 'setLanguage'));

$result = $paymentOrder->setLanguage('en-US');
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->getLanguage();
$this->assertEquals('en-US', $result);
}

public function testGeneratePaymentToken()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'isGeneratePaymentToken'));
$this->assertTrue(method_exists($paymentOrder, 'setGeneratePaymentToken'));

$result = $paymentOrder->setGeneratePaymentToken(true);
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->isGeneratePaymentToken();
$this->assertEquals(true, $result);
}

public function testDisablePaymentMenu()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'isDisablePaymentMenu'));
$this->assertTrue(method_exists($paymentOrder, 'setDisablePaymentMenu'));

$result = $paymentOrder->setDisablePaymentMenu(true);
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->isDisablePaymentMenu();
$this->assertEquals(true, $result);
}

public function testPayerReference()
{
$paymentOrder = new Paymentorder();

$this->assertTrue(method_exists($paymentOrder, 'getPayerReference'));
$this->assertTrue(method_exists($paymentOrder, 'setPayerReference'));

$result = $paymentOrder->setPayerReference('123');
$this->assertInstanceOf(
'\SwedbankPay\Api\Service\Paymentorder\Resource\Request\Data\PaymentorderInterface',
$result
);

$result = $paymentOrder->getPayerReference();
$this->assertEquals('123', $result);
}

}