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

Commit fc2143a

Browse files
committed
feat(Keys): adds method to get public key from moip account
1 parent d547d8a commit fc2143a

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

src/Moip.php

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Moip\Resource\Account;
77
use Moip\Resource\Customer;
88
use Moip\Resource\Entry;
9+
use Moip\Resource\Keys;
910
use Moip\Resource\Multiorders;
1011
use Moip\Resource\NotificationPreferences;
1112
use Moip\Resource\Orders;
@@ -213,6 +214,16 @@ public function webhooks()
213214
return new WebhookList($this);
214215
}
215216

217+
/**
218+
* Create a new Keys instance.
219+
*
220+
* @return Keys
221+
*/
222+
public function keys()
223+
{
224+
return new Keys($this);
225+
}
226+
216227
/**
217228
* Get the endpoint.
218229
*

src/Resource/Keys.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Moip\Resource;
4+
5+
use Requests;
6+
use stdClass;
7+
8+
/**
9+
* Class Keys.
10+
*/
11+
class Keys extends MoipResource
12+
{
13+
/**
14+
* @const string
15+
*/
16+
const PATH = 'keys';
17+
18+
/**
19+
* Initializes new instances.
20+
*/
21+
public function initialize()
22+
{
23+
$this->data = new stdClass();
24+
}
25+
26+
/**
27+
* Mount keys structure.
28+
*
29+
* @param \stdClass $response
30+
*
31+
* @return $this
32+
*/
33+
protected function populate(stdClass $response)
34+
{
35+
$keys = clone $this;
36+
37+
$resp = $response->keys;
38+
$keys->data->basicAuth = $this->getIfSet('basicAuth', $resp);
39+
$keys->data->encryption = $this->getIfSet('encryption', $resp);
40+
41+
return $keys;
42+
}
43+
44+
/**
45+
* Get encryption.
46+
*
47+
* @return string
48+
*/
49+
public function getEncryption()
50+
{
51+
return $this->getIfSet('encryption');
52+
}
53+
54+
/**
55+
* Get Basic Auth.
56+
*
57+
* @return stdClass
58+
*/
59+
public function getBasicAuth()
60+
{
61+
return $this->getIfSet('basicAuth');
62+
}
63+
64+
/**
65+
* Get keys.
66+
*
67+
* @return stdClass
68+
*/
69+
public function get()
70+
{
71+
return $this->getByPath(sprintf('/%s/%s', MoipResource::VERSION, self::PATH));
72+
}
73+
}

tests/Resource/KeyTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Moip\Tests\Resource;
4+
5+
use Moip\Tests\TestCase;
6+
7+
class KeyTest extends TestCase
8+
{
9+
public function testGetKey()
10+
{
11+
$this->mockHttpSession($this->body_keys);
12+
13+
$keys = $this->moip->keys()->get();
14+
15+
$this->assertNotNull($keys->getBasicAuth()->token);
16+
$this->assertNotNull($keys->getBasicAuth()->secret);
17+
$this->assertNotNull($keys->getEncryption());
18+
}
19+
}

tests/TestCase.php

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ public function __construct()
175175
$this->body_get_pay = $this->readJsonFile('jsons/payment/get');
176176

177177
$this->body_get_multipay = $this->readJsonFile('jsons/multipayment/get');
178+
179+
$this->body_keys = $this->readJsonFile('jsons/keys/get');
178180
}
179181

180182
/**

tests/jsons/keys/get.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"keys":{"basicAuth":{"secret":"ABABABABABABABABABABABABABABABABABABABAB","token":"01010101010101010101010101010101"},"encryption":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoBttaXwRoI1Fbcond5mS\n7QOb7X2lykY5hvvDeLJelvFhpeLnS4YDwkrnziM3W00UNH1yiSDU+3JhfHu5G387\nO6uN9rIHXvL+TRzkVfa5iIjG+ap2N0\/toPzy5ekpgxBicjtyPHEgoU6dRzdszEF4\nItimGk5ACx\/lMOvctncS5j3uWBaTPwyn0hshmtDwClf6dEZgQvm\/dNaIkxHKV+9j\nMn3ZfK\/liT8A3xwaVvRzzuxf09xJTXrAd9v5VQbeWGxwFcW05oJulSFjmJA9Hcmb\nDYHJT+sG2mlZDEruCGAzCVubJwGY1aRlcs9AQc1jIm\/l8JwH7le2kpk3QoX+gz0w\nWwIDAQAB\n-----END PUBLIC KEY-----\n"}}

0 commit comments

Comments
 (0)