Skip to content

Commit

Permalink
Merge pull request #45 from SwedbankPay/feature/woo-66-initiatingSyst…
Browse files Browse the repository at this point in the history
…emUserAgent

Add InitiatingSystemUserAgent
  • Loading branch information
aait authored Jan 7, 2021
2 parents 497edae + 1d0eceb commit 7a97c0e
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 0 deletions.
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);
}

}

0 comments on commit 7a97c0e

Please sign in to comment.