Skip to content

Commit 8124cfd

Browse files
Merge pull request #27 from PropaySystems/Feature/Add-Companies-Interaction
Feature/Add-Companies-Interaction
2 parents cac89b0 + 5d9db80 commit 8124cfd

File tree

3 files changed

+150
-75
lines changed

3 files changed

+150
-75
lines changed

src/Traits/Contact.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ public function updateContact(string $id, array $data = [], string $version = 'v
9898
return $this->execute();
9999
}
100100

101+
/**
102+
* Bulk updates specific contact by ID with provided data for a specified API version.
103+
*
104+
* This method prepares the request to bulk update contacts identified by the given ID with the provided data array.
105+
* It sets the API version, configures the data payload as form parameters, sets the endpoint to target the specific
106+
* contact by appending the ID to the 'contacts/' endpoint, and specifies the request type as 'PUT'.
107+
* Finally, it executes the request and returns the response.
108+
*
109+
* @param string $id The unique identifier of the contact to update.
110+
* @param array $data (Optional) An associative array of data to update the contact with. The array keys and values
111+
* depend on the contact model's attributes and the API's update capabilities.
112+
* @param string $version (Optional) The version of the API to target. Defaults to 'v1'.
113+
* @return mixed The response from the API, typically an object or array containing the updated contact details.
114+
* The exact return type may vary depending on the implementation of the `execute` method.
115+
*
116+
* @throws \Exception
117+
*/
118+
public function bulkUpdateContact(string $id, array $data = [], string $version = 'v1'): mixed
119+
{
120+
$this->init();
121+
$this->setVersion($version);
122+
$this->setData([
123+
'form_params' => $data,
124+
]);
125+
$this->setEndpoint('contacts/bulkUpdate/'.$id);
126+
$this->setRequestType('PUT');
127+
128+
return $this->execute();
129+
}
130+
101131
/**
102132
* Creates a new contact with the provided data for a specified API version.
103133
*
@@ -126,6 +156,34 @@ public function createContact(array $data = [], string $version = 'v1'): mixed
126156
return $this->execute();
127157
}
128158

159+
/**
160+
* Creates a new contact with the provided data for a specified API version.
161+
*
162+
* This method prepares the request to create a new contact with the given data array. It sets the API version,
163+
* configures the data payload as form parameters, sets the endpoint to the 'contacts/' for contact creation,
164+
* and specifies the request type as 'POST'. Finally, it executes the request and returns the response.
165+
*
166+
* @param array $data (Optional) An associative array of data for creating the contact. The array keys and values
167+
* should match the contact model's attributes and the API's creation capabilities.
168+
* @param string $version (Optional) The version of the API to target. Defaults to 'v1'.
169+
* @return mixed The response from the API, typically an object or array containing the details of the newly created contact.
170+
* The exact return type may vary depending on the implementation of the `execute` method.
171+
*
172+
* @throws \Exception
173+
*/
174+
public function bulkCreateContacts(array $data = [], string $version = 'v1'): mixed
175+
{
176+
$this->init();
177+
$this->setVersion($version);
178+
$this->setData([
179+
'form_params' => $data,
180+
]);
181+
$this->setEndpoint('contacts/bulkCreate');
182+
$this->setRequestType('POST');
183+
184+
return $this->execute();
185+
}
186+
129187
/**
130188
* Retrieves the allowed statuses for contacts.
131189
*

tests/Traits/ContactTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@
8383
expect($result)->toBe($expectedResult);
8484
});
8585

86+
test('bulkUpdateContact calls expected methods and returns result', function () {
87+
$mock = $this->getMockBuilder(PaymentPlatformAPI::class)
88+
->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
89+
->getMock();
90+
91+
$id = 'contact-456';
92+
$data = ['name' => 'Updated Contacts'];
93+
$version = 'v3.0';
94+
95+
$mock->expects($this->once())->method('init')->willReturnSelf();
96+
$mock->expects($this->once())->method('setVersion')->with($version)->willReturnSelf();
97+
$mock->expects($this->once())->method('setData')->with(['form_params' => $data])->willReturnSelf();
98+
$mock->expects($this->once())->method('setEndpoint')->with('contacts/bulkUpdate/'.$id)->willReturnSelf();
99+
$mock->expects($this->once())->method('setRequestType')->with('PUT')->willReturnSelf();
100+
101+
$expectedResult = 'update-contact-result';
102+
$mock->expects($this->once())->method('execute')->willReturn($expectedResult);
103+
104+
$result = $mock->bulkUpdateContact($id, $data, $version);
105+
expect($result)->toBe($expectedResult);
106+
});
107+
86108
test('createContact calls expected methods and returns result', function () {
87109
$mock = $this->getMockBuilder(PaymentPlatformAPI::class)
88110
->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
@@ -104,6 +126,27 @@
104126
expect($result)->toBe($expectedResult);
105127
});
106128

129+
test('bulkCreateContacts calls expected methods and returns result', function () {
130+
$mock = $this->getMockBuilder(PaymentPlatformAPI::class)
131+
->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
132+
->getMock();
133+
134+
$data = ['name' => 'New Contacts'];
135+
$version = 'v4.0';
136+
137+
$mock->expects($this->once())->method('init')->willReturnSelf();
138+
$mock->expects($this->once())->method('setVersion')->with($version)->willReturnSelf();
139+
$mock->expects($this->once())->method('setData')->with(['form_params' => $data])->willReturnSelf();
140+
$mock->expects($this->once())->method('setEndpoint')->with('contacts/bulkCreate')->willReturnSelf();
141+
$mock->expects($this->once())->method('setRequestType')->with('POST')->willReturnSelf();
142+
143+
$expectedResult = 'create-bulk-contact-result';
144+
$mock->expects($this->once())->method('execute')->willReturn($expectedResult);
145+
146+
$result = $mock->bulkCreateContacts($data, $version);
147+
expect($result)->toBe($expectedResult);
148+
});
149+
107150
test('allowedContactStatuses calls expected methods and returns result', function () {
108151
$mock = $this->getMockBuilder(PaymentPlatformAPI::class)
109152
->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])

tests/Traits/OrganisationTest.php

Lines changed: 49 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -35,95 +35,69 @@
3535
expect($result)->toBe($expectedResult);
3636
});
3737

38-
test('bank calls expected methods and returns result', function () {
38+
test('updateOrganisation calls expected methods and returns result', function () {
3939
$mock = $this->getMockBuilder(PaymentPlatformAPI::class)
4040
->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
4141
->getMock();
4242

4343
$id = '1';
44-
$includes = ['statuses'];
45-
$version = 'v2.1';
44+
$data = ['name' => 'Updated Organisation'];
45+
$version = 'v3.0';
4646

4747
$mock->expects($this->once())->method('init')->willReturnSelf();
4848
$mock->expects($this->once())->method('setVersion')->with($version)->willReturnSelf();
49-
$mock->expects($this->once())->method('setData')->with($this->callback(function ($data) use ($includes) {
49+
$mock->expects($this->once())->method('setData')->with(['form_params' => $data])->willReturnSelf();
50+
$mock->expects($this->once())->method('setEndpoint')->with('organisations/'.$id)->willReturnSelf();
51+
$mock->expects($this->once())->method('setRequestType')->with('PUT')->willReturnSelf();
52+
53+
$expectedResult = 'update-bank-result';
54+
$mock->expects($this->once())->method('execute')->willReturn($expectedResult);
55+
56+
$result = $mock->updateOrganisation($id, $data, $version);
57+
expect($result)->toBe($expectedResult);
58+
});
59+
60+
test('createOrganisation calls expected methods and returns result', function () {
61+
$mock = $this->getMockBuilder(PaymentPlatformAPI::class)
62+
->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
63+
->getMock();
64+
65+
$data = ['name' => 'New Organisation'];
66+
$version = 'v4.0';
67+
68+
$mock->expects($this->once())->method('init')->willReturnSelf();
69+
$mock->expects($this->once())->method('setVersion')->with($version)->willReturnSelf();
70+
$mock->expects($this->once())->method('setData')->with(['form_params' => $data])->willReturnSelf();
71+
$mock->expects($this->once())->method('setEndpoint')->with('organisations')->willReturnSelf();
72+
$mock->expects($this->once())->method('setRequestType')->with('POST')->willReturnSelf();
73+
74+
$expectedResult = 'create-organisation-result';
75+
$mock->expects($this->once())->method('execute')->willReturn($expectedResult);
76+
77+
$result = $mock->createOrganisation($data, $version);
78+
expect($result)->toBe($expectedResult);
79+
});
80+
81+
test('allowedOrganisationStatuses calls expected methods and returns result', function () {
82+
$mock = $this->getMockBuilder(PaymentPlatformAPI::class)
83+
->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
84+
->getMock();
85+
86+
$version = 'v5.0';
87+
88+
$mock->expects($this->once())->method('init')->willReturnSelf();
89+
$mock->expects($this->once())->method('setVersion')->with($version)->willReturnSelf();
90+
$mock->expects($this->once())->method('setData')->with($this->callback(function ($data) {
5091
parse_str($data['query'], $queryArray);
5192

52-
return $queryArray['include'] === $includes;
93+
return $queryArray === [];
5394
}))->willReturnSelf();
54-
$mock->expects($this->once())->method('setEndpoint')->with('banks/show/'.$id)->willReturnSelf();
95+
$mock->expects($this->once())->method('setEndpoint')->with('organisations/allowedStatuses')->willReturnSelf();
5596
$mock->expects($this->once())->method('setRequestType')->with('GET')->willReturnSelf();
5697

57-
$expectedResult = 'bank-result';
98+
$expectedResult = 'allowed-statuses-result';
5899
$mock->expects($this->once())->method('execute')->willReturn($expectedResult);
59100

60-
$result = $mock->bank($id, $includes, $version);
101+
$result = $mock->allowedOrganisationStatuses($version);
61102
expect($result)->toBe($expectedResult);
62103
});
63-
//
64-
//test('updateBank calls expected methods and returns result', function () {
65-
// $mock = $this->getMockBuilder(PaymentPlatformAPI::class)
66-
// ->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
67-
// ->getMock();
68-
//
69-
// $id = 'bank-101';
70-
// $data = ['name' => 'Updated Bank'];
71-
// $version = 'v3.0';
72-
//
73-
// $mock->expects($this->once())->method('init')->willReturnSelf();
74-
// $mock->expects($this->once())->method('setVersion')->with($version)->willReturnSelf();
75-
// $mock->expects($this->once())->method('setData')->with(['form_params' => $data])->willReturnSelf();
76-
// $mock->expects($this->once())->method('setEndpoint')->with('banks/'.$id)->willReturnSelf();
77-
// $mock->expects($this->once())->method('setRequestType')->with('PUT')->willReturnSelf();
78-
//
79-
// $expectedResult = 'update-bank-result';
80-
// $mock->expects($this->once())->method('execute')->willReturn($expectedResult);
81-
//
82-
// $result = $mock->updateBank($id, $data, $version);
83-
// expect($result)->toBe($expectedResult);
84-
//});
85-
//
86-
//test('createBank calls expected methods and returns result', function () {
87-
// $mock = $this->getMockBuilder(PaymentPlatformAPI::class)
88-
// ->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
89-
// ->getMock();
90-
//
91-
// $data = ['name' => 'New Bank'];
92-
// $version = 'v4.0';
93-
//
94-
// $mock->expects($this->once())->method('init')->willReturnSelf();
95-
// $mock->expects($this->once())->method('setVersion')->with($version)->willReturnSelf();
96-
// $mock->expects($this->once())->method('setData')->with(['form_params' => $data])->willReturnSelf();
97-
// $mock->expects($this->once())->method('setEndpoint')->with('banks')->willReturnSelf();
98-
// $mock->expects($this->once())->method('setRequestType')->with('POST')->willReturnSelf();
99-
//
100-
// $expectedResult = 'create-bank-result';
101-
// $mock->expects($this->once())->method('execute')->willReturn($expectedResult);
102-
//
103-
// $result = $mock->createBank($data, $version);
104-
// expect($result)->toBe($expectedResult);
105-
//});
106-
//
107-
//test('allowedBankStatuses calls expected methods and returns result', function () {
108-
// $mock = $this->getMockBuilder(PaymentPlatformAPI::class)
109-
// ->onlyMethods(['init', 'setVersion', 'setData', 'setEndpoint', 'setRequestType', 'execute'])
110-
// ->getMock();
111-
//
112-
// $version = 'v5.0';
113-
//
114-
// $mock->expects($this->once())->method('init')->willReturnSelf();
115-
// $mock->expects($this->once())->method('setVersion')->with($version)->willReturnSelf();
116-
// $mock->expects($this->once())->method('setData')->with($this->callback(function ($data) {
117-
// parse_str($data['query'], $queryArray);
118-
//
119-
// return $queryArray === [];
120-
// }))->willReturnSelf();
121-
// $mock->expects($this->once())->method('setEndpoint')->with('banks/allowedStatuses')->willReturnSelf();
122-
// $mock->expects($this->once())->method('setRequestType')->with('GET')->willReturnSelf();
123-
//
124-
// $expectedResult = 'allowed-statuses-result';
125-
// $mock->expects($this->once())->method('execute')->willReturn($expectedResult);
126-
//
127-
// $result = $mock->allowedBankStatuses($version);
128-
// expect($result)->toBe($expectedResult);
129-
//});

0 commit comments

Comments
 (0)