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

Commit 1f40cef

Browse files
author
Jens Schulze
committed
feat(Payment): support key for payments
Closes #315
1 parent 0e14d97 commit 1f40cef

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

src/Core/Model/Payment/Payment.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
* @method Payment setTransactions(TransactionCollection $transactions = null)
5151
* @method CustomFieldObjectCollection getInterfaceInteractions()
5252
* @method Payment setInterfaceInteractions(CustomFieldObjectCollection $interfaceInteractions = null)
53+
* @method string getKey()
54+
* @method Payment setKey(string $key = null)
5355
* @method PaymentReference getReference()
5456
*/
5557
class Payment extends Resource
@@ -59,6 +61,7 @@ public function fieldDefinitions()
5961
return [
6062
'id' => [static::TYPE => 'string'],
6163
'version' => [static::TYPE => 'int'],
64+
'key' => [static::TYPE => 'string'],
6265
'createdAt' => [
6366
static::TYPE => DateTime::class,
6467
static::DECORATOR => DateTimeDecorator::class

src/Core/Model/Payment/PaymentDraft.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@
4444
* @method PaymentDraft setTransactions(TransactionCollection $transactions = null)
4545
* @method CustomFieldObjectDraftCollection getInterfaceInteractions()
4646
* @method PaymentDraft setInterfaceInteractions(CustomFieldObjectDraftCollection $interfaceInteractions = null)
47+
* @method string getKey()
48+
* @method PaymentDraft setKey(string $key = null)
4749
*/
4850
class PaymentDraft extends JsonObject
4951
{
5052
public function fieldDefinitions()
5153
{
5254
return [
55+
'key' => [static::TYPE => 'string'],
5356
'customer' => [static::TYPE => CustomerReference::class],
5457
'externalId' => [static::TYPE => 'string'],
5558
'interfaceId' => [static::TYPE => 'string'],
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <jens.schulze@commercetools.de>
4+
*/
5+
6+
namespace Commercetools\Core\Request\Payments\Command;
7+
8+
use Commercetools\Core\Model\Common\Context;
9+
use Commercetools\Core\Request\AbstractAction;
10+
use Commercetools\Core\Model\Common\Money;
11+
12+
/**
13+
* @package Commercetools\Core\Request\Payments\Command
14+
* @link https://dev.commercetools.com/http-api-projects-payments.html#set-key
15+
* @method string getAction()
16+
* @method PaymentSetKeyAction setAction(string $action = null)
17+
* @method string getKey()
18+
* @method PaymentSetKeyAction setKey(string $key = null)
19+
*/
20+
class PaymentSetKeyAction extends AbstractAction
21+
{
22+
public function fieldDefinitions()
23+
{
24+
return [
25+
'action' => [static::TYPE => 'string'],
26+
'key' => [static::TYPE => 'string'],
27+
];
28+
}
29+
30+
/**
31+
* @param array $data
32+
* @param Context|callable $context
33+
*/
34+
public function __construct(array $data = [], $context = null)
35+
{
36+
parent::__construct($data, $context);
37+
$this->setAction('setKey');
38+
}
39+
}

tests/integration/Payment/PaymentUpdateRequestTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomTypeAction;
3030
use Commercetools\Core\Request\Payments\Command\PaymentSetExternalIdAction;
3131
use Commercetools\Core\Request\Payments\Command\PaymentSetInterfaceIdAction;
32+
use Commercetools\Core\Request\Payments\Command\PaymentSetKeyAction;
3233
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoInterfaceAction;
3334
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoMethodAction;
3435
use Commercetools\Core\Request\Payments\Command\PaymentSetMethodInfoNameAction;
@@ -112,6 +113,29 @@ public function testSetCustomer()
112113
$this->assertNotSame($payment->getVersion(), $result->getVersion());
113114
}
114115

116+
public function testSetKey()
117+
{
118+
$key = $this->getTestRun() . '-key';
119+
$draft = $this->getDraft();
120+
$draft->setKey($key);
121+
$payment = $this->createPayment($draft);
122+
$this->assertSame($key, $payment->getKey());
123+
124+
$key = $this->getTestRun() . '-new-key';
125+
$request = PaymentUpdateRequest::ofIdAndVersion($payment->getId(), $payment->getVersion())
126+
->addAction(
127+
PaymentSetKeyAction::of()->setKey($key)
128+
)
129+
;
130+
$response = $request->executeWithClient($this->getClient());
131+
$result = $request->mapResponse($response);
132+
$this->deleteRequest->setVersion($result->getVersion());
133+
134+
$this->assertInstanceOf(Payment::class, $result);
135+
$this->assertSame($key, $result->getKey());
136+
$this->assertNotSame($payment->getVersion(), $result->getVersion());
137+
}
138+
115139
public function testSetExternalId()
116140
{
117141
$draft = $this->getDraft();

0 commit comments

Comments
 (0)