Skip to content

Commit 772b810

Browse files
committed
Add an ability to enable/disable customers
1 parent 9d45052 commit 772b810

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

src/Api/Operator/Customer.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,48 @@ public function getAll()
5757
{
5858
return $this->_getItems(Struct\GeneralInfo::class, 'gen_info');
5959
}
60+
61+
/**
62+
* @param string $field
63+
* @param int|string $value
64+
*
65+
* @return bool
66+
*/
67+
public function enable(string $field, $value): bool
68+
{
69+
return $this->setProperty($field, $value, 'status', 0);
70+
}
71+
72+
/**
73+
* @param string $field
74+
* @param int|string $value
75+
*
76+
* @return bool
77+
*/
78+
public function disable(string $field, $value): bool
79+
{
80+
return $this->setProperty($field, $value, 'status', 1);
81+
}
82+
83+
/**
84+
* @param string $field
85+
* @param int|string $value
86+
* @param string $property
87+
* @param int|string $propertyValue
88+
*
89+
* @return bool
90+
*/
91+
public function setProperty(string $field, $value, string $property, $propertyValue): bool
92+
{
93+
$packet = $this->_client->getPacket();
94+
$setTag = $packet->addChild($this->_wrapperTag)->addChild('set');
95+
$setTag->addChild('filter')->addChild($field, (string) $value);
96+
$genInfoTag = $setTag->addChild('values')->addChild('gen_info');
97+
$genInfoTag->addChild($property, (string) $propertyValue);
98+
99+
$response = $this->_client->request($packet);
100+
101+
return 'ok' === (string) $response->status;
102+
}
103+
60104
}

src/Api/Struct/Customer/GeneralInfo.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class GeneralInfo extends Struct
2222
public string $country;
2323
public string $description;
2424
public string $externalId;
25+
public bool $enabled;
2526

2627
public function __construct(\SimpleXMLElement $apiResponse)
2728
{
@@ -41,5 +42,7 @@ public function __construct(\SimpleXMLElement $apiResponse)
4142
'external-id',
4243
'description',
4344
]);
45+
46+
$this->enabled = '0' === (string) $apiResponse->status;
4447
}
4548
}

tests/CustomerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,25 @@ public function testGetAll()
8484
static::$_client->customer()->delete('login', 'customer-a');
8585
static::$_client->customer()->delete('login', 'customer-b');
8686
}
87+
88+
public function testEnable()
89+
{
90+
$customer = static::$_client->customer()->create($this->_customerProperties);
91+
static::$_client->customer()->disable('id', $customer->id);
92+
static::$_client->customer()->enable('id', $customer->id);
93+
$customerInfo = static::$_client->customer()->get('id', $customer->id);
94+
$this->assertTrue($customerInfo->enabled);
95+
96+
static::$_client->customer()->delete('id', $customer->id);
97+
}
98+
99+
public function testDisable()
100+
{
101+
$customer = static::$_client->customer()->create($this->_customerProperties);
102+
static::$_client->customer()->disable('id', $customer->id);
103+
$customerInfo = static::$_client->customer()->get('id', $customer->id);
104+
$this->assertFalse($customerInfo->enabled);
105+
106+
static::$_client->customer()->delete('id', $customer->id);
107+
}
87108
}

0 commit comments

Comments
 (0)