Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 4dd0e3e

Browse files
committed
feat(Payment): support anonymousId
1 parent fc3b94e commit 4dd0e3e

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

src/Core/Builder/Update/PaymentsActionBuilder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionTimestampAction;
1313
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountPaidAction;
1414
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountRefundedAction;
15+
use Commercetools\Core\Request\Payments\Command\PaymentSetAnonymousIdAction;
1516
use Commercetools\Core\Request\Payments\Command\PaymentSetAuthorizationAction;
1617
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomFieldAction;
1718
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomTypeAction;
@@ -118,6 +119,17 @@ public function setAmountRefunded($action = null)
118119
return $this;
119120
}
120121

122+
/**
123+
* @link https://docs.commercetools.com/http-api-projects-payments#set-anonymousid
124+
* @param PaymentSetAnonymousIdAction|callable $action
125+
* @return $this
126+
*/
127+
public function setAnonymousId($action = null)
128+
{
129+
$this->addAction($this->resolveAction(PaymentSetAnonymousIdAction::class, $action));
130+
return $this;
131+
}
132+
121133
/**
122134
* @link https://docs.commercetools.com/http-api-projects-payments.html#set-authorization
123135
* @param PaymentSetAuthorizationAction|callable $action

src/Core/Model/Payment/Payment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
* @method Payment setInterfaceInteractions(CustomFieldObjectCollection $interfaceInteractions = null)
4343
* @method string getKey()
4444
* @method Payment setKey(string $key = null)
45+
* @method string getAnonymousId()
46+
* @method Payment setAnonymousId(string $anonymousId = null)
4547
* @method PaymentReference getReference()
4648
*/
4749
class Payment extends Resource
@@ -61,6 +63,7 @@ public function fieldDefinitions()
6163
static::DECORATOR => DateTimeDecorator::class
6264
],
6365
'customer' => [static::TYPE => CustomerReference::class],
66+
'anonymousId' => [static::TYPE => 'string'],
6467
'externalId' => [static::TYPE => 'string'],
6568
'interfaceId' => [static::TYPE => 'string'],
6669
'amountPlanned' => [static::TYPE => Money::class],

src/Core/Model/Payment/PaymentDraft.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* @method PaymentDraft setInterfaceInteractions(CustomFieldObjectDraftCollection $interfaceInteractions = null)
3535
* @method string getKey()
3636
* @method PaymentDraft setKey(string $key = null)
37+
* @method string getAnonymousId()
38+
* @method PaymentDraft setAnonymousId(string $anonymousId = null)
3739
*/
3840
class PaymentDraft extends JsonObject
3941
{
@@ -42,6 +44,7 @@ public function fieldDefinitions()
4244
return [
4345
'key' => [static::TYPE => 'string'],
4446
'customer' => [static::TYPE => CustomerReference::class],
47+
'anonymousId' => [static::TYPE => 'string'],
4548
'externalId' => [static::TYPE => 'string'],
4649
'interfaceId' => [static::TYPE => 'string'],
4750
'amountPlanned' => [static::TYPE => Money::class],
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
*/
4+
5+
namespace Commercetools\Core\Request\Payments\Command;
6+
7+
use Commercetools\Core\Model\Common\Context;
8+
use Commercetools\Core\Request\AbstractAction;
9+
10+
/**
11+
* @package Commercetools\Core\Request\Payments\Command
12+
* @link https://docs.commercetools.com/http-api-projects-payments#set-anonymousid
13+
* @method string getAction()
14+
* @method PaymentSetAnonymousIdAction setAction(string $action = null)
15+
* @method string getAnonymousId()
16+
* @method PaymentSetAnonymousIdAction setAnonymousId(string $anonymousId = null)
17+
*/
18+
class PaymentSetAnonymousIdAction extends AbstractAction
19+
{
20+
public function fieldDefinitions()
21+
{
22+
return [
23+
'action' => [static::TYPE => 'string'],
24+
'anonymousId' => [static::TYPE => 'string'],
25+
];
26+
}
27+
28+
/**
29+
* @param array $data
30+
* @param Context|callable $context
31+
*/
32+
public function __construct(array $data = [], $context = null)
33+
{
34+
parent::__construct($data, $context);
35+
$this->setAction('setAnonymousId');
36+
}
37+
}

tests/integration/Payment/PaymentUpdateRequestTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Commercetools\Core\Request\Payments\Command\PaymentChangeTransactionTimestampAction;
2424
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountPaidAction;
2525
use Commercetools\Core\Request\Payments\Command\PaymentSetAmountRefundedAction;
26+
use Commercetools\Core\Request\Payments\Command\PaymentSetAnonymousIdAction;
2627
use Commercetools\Core\Request\Payments\Command\PaymentSetAuthorizationAction;
2728
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomerAction;
2829
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomFieldAction;
@@ -136,6 +137,29 @@ public function testSetCustomer()
136137
$this->assertNotSame($payment->getVersion(), $result->getVersion());
137138
}
138139

140+
public function testSetAnonymousId()
141+
{
142+
$anonymousId = $this->getTestRun() . '-anon';
143+
$draft = $this->getDraft();
144+
$draft->setAnonymousId($anonymousId);
145+
$payment = $this->createPayment($draft);
146+
$this->assertSame($anonymousId, $payment->getAnonymousId());
147+
148+
$anonymousId = $this->getTestRun() . '-new-anon';
149+
$request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
150+
->addAction(
151+
PaymentSetAnonymousIdAction::of()->setAnonymousId($anonymousId)
152+
)
153+
;
154+
$response = $request->executeWithClient($this->getClient());
155+
$result = $request->mapResponse($response);
156+
$this->deleteRequest->setVersion($result->getVersion());
157+
158+
$this->assertInstanceOf(Payment::class, $result);
159+
$this->assertSame($anonymousId, $result->getAnonymousId());
160+
$this->assertNotSame($payment->getVersion(), $result->getVersion());
161+
}
162+
139163
public function testSetKey()
140164
{
141165
$key = $this->getTestRun() . '-key';

0 commit comments

Comments
 (0)