PluginProbe
PayPlug for WooCommerce (Official) / 1.0.5
PayPlug for WooCommerce (Official) v1.0.5
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
payplug / vendor / payplug / payplug-php / lib / Payplug / Authentication.php

Authentication.php in PayPlug for WooCommerce (Official) 1.0.5, at vendor/payplug/payplug-php/lib/Payplug/Authentication.php

96 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Payplug;
3
4 /**
5 *
6 */
7 class Authentication
8 {
9 /**
10 * Retrieve existing API keys for an user, using his email and password.
11 * This function is for user-friendly interface purpose only.
12 * You should probably not use this more than once, login/password MUST NOT be stored and API Keys are enough to interact with API.
13 *
14 * @param string $email the user email
15 * @param string $password the user password
16 *
17 * @return null|array the API keys
18 *
19 * @throws Exception\BadRequestException
20 */
21 public static function getKeysByLogin($email, $password)
22 {
23 $httpClient = new Core\HttpClient(null);
24 $response = $httpClient->post(
25 Core\APIRoutes::getRoute(Core\APIRoutes::KEY_RESOURCE),
26 array('email' => $email, 'password' => $password),
27 false
28 );
29 return $response;
30 }
31
32 /**
33 * Retrieve account info.
34 *
35 * @param Payplug $payplug the client configuration
36 *
37 * @return null|array the account settings
38 *
39 * @throws Exception\ConfigurationNotSetException
40 */
41 public static function getAccount(Payplug $payplug = null)
42 {
43 if ($payplug === null) {
44 $payplug = Payplug::getDefaultConfiguration();
45 }
46
47 $httpClient = new Core\HttpClient($payplug);
48 $response = $httpClient->get(Core\APIRoutes::getRoute(Core\APIRoutes::ACCOUNT_RESOURCE));
49
50 return $response;
51 }
52
53 /**
54 * Retrieve the account permissions
55 *
56 * @param Payplug $payplug the client configuration
57 *
58 * @return null|array the account permissions
59 *
60 * @throws Exception\ConfigurationNotSetException
61 */
62 public static function getPermissions(Payplug $payplug = null)
63 {
64 if ($payplug === null) {
65 $payplug = Payplug::getDefaultConfiguration();
66 }
67
68 $httpClient = new Core\HttpClient($payplug);
69 $response = $httpClient->get(Core\APIRoutes::getRoute(Core\APIRoutes::ACCOUNT_RESOURCE));
70
71 return $response['httpResponse']['permissions'];
72 }
73
74 /**
75 * Retrieve the account permissions, using email and password.
76 * This function is for user-friendly interface purpose only.
77 * You should probably not use this more than once, login/password MUST NOT be stored and API Keys are enough to interact with API.
78 *
79 * @param string $email the user email
80 * @param string $password the user password
81 *
82 * @return null|array the account permissions
83 *
84 * @throws Exception\ConfigurationNotSetException
85 */
86 public static function getPermissionsByLogin($email, $password)
87 {
88 $keys = self::getKeysByLogin($email, $password);
89 $payplug = Payplug::setSecretKey($keys['httpResponse']['secret_keys']['live']);
90 $httpClient = new Core\HttpClient($payplug);
91 $response = $httpClient->get(Core\APIRoutes::getRoute(Core\APIRoutes::ACCOUNT_RESOURCE));
92
93 return $response['httpResponse']['permissions'];
94 }
95 }
96