fidor_starter_kits 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/fidor_starter_kits.rb +1 -1
  4. data/lib/fidor_starter_kits/version.rb +1 -1
  5. data/starter_kits/php_advanced/.fidor_meta.json +8 -0
  6. data/starter_kits/php_advanced/Fidor/SDK/Accounts.php +47 -0
  7. data/starter_kits/php_advanced/Fidor/SDK/Authorization.php +276 -0
  8. data/starter_kits/php_advanced/Fidor/SDK/Autoload.php +33 -0
  9. data/starter_kits/php_advanced/Fidor/SDK/Client.php +239 -0
  10. data/starter_kits/php_advanced/Fidor/SDK/Config.php +272 -0
  11. data/starter_kits/php_advanced/Fidor/SDK/Customers.php +27 -0
  12. data/starter_kits/php_advanced/Fidor/SDK/Transactions.php +47 -0
  13. data/starter_kits/php_advanced/Fidor/SDK/Transfers.php +65 -0
  14. data/starter_kits/php_advanced/Fidor/SDK/Transfers/Batch.php +18 -0
  15. data/starter_kits/php_advanced/Fidor/SDK/Transfers/Global.php +18 -0
  16. data/starter_kits/php_advanced/Fidor/SDK/Transfers/Internal.php +33 -0
  17. data/starter_kits/php_advanced/Fidor/SDK/Transfers/SEPA.php +18 -0
  18. data/starter_kits/php_advanced/Fidor/SDK/Users.php +23 -0
  19. data/starter_kits/php_advanced/README.md +19 -0
  20. data/starter_kits/php_advanced/curl-test.php +1 -0
  21. data/starter_kits/php_advanced/demo/assets/css/bootstrap-theme.css +587 -0
  22. data/starter_kits/php_advanced/demo/assets/css/bootstrap-theme.css.map +1 -0
  23. data/starter_kits/php_advanced/demo/assets/css/bootstrap-theme.min.css +6 -0
  24. data/starter_kits/php_advanced/demo/assets/css/bootstrap-theme.min.css.map +1 -0
  25. data/starter_kits/php_advanced/demo/assets/css/bootstrap.css +6760 -0
  26. data/starter_kits/php_advanced/demo/assets/css/bootstrap.css.map +1 -0
  27. data/starter_kits/php_advanced/demo/assets/css/bootstrap.min.css +6 -0
  28. data/starter_kits/php_advanced/demo/assets/css/bootstrap.min.css.map +1 -0
  29. data/starter_kits/php_advanced/demo/assets/fonts/glyphicons-halflings-regular.eot +0 -0
  30. data/starter_kits/php_advanced/demo/assets/fonts/glyphicons-halflings-regular.svg +288 -0
  31. data/starter_kits/php_advanced/demo/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
  32. data/starter_kits/php_advanced/demo/assets/fonts/glyphicons-halflings-regular.woff +0 -0
  33. data/starter_kits/php_advanced/demo/assets/fonts/glyphicons-halflings-regular.woff2 +0 -0
  34. data/starter_kits/php_advanced/demo/assets/js/bootstrap.js +2363 -0
  35. data/starter_kits/php_advanced/demo/assets/js/bootstrap.min.js +7 -0
  36. data/starter_kits/php_advanced/demo/assets/js/jquery.min.js +6 -0
  37. data/starter_kits/php_advanced/demo/assets/js/npm.js +13 -0
  38. data/starter_kits/php_advanced/demo/authorize.php +103 -0
  39. data/starter_kits/php_advanced/demo/config.php +15 -0
  40. data/starter_kits/php_advanced/demo/dashboard.php +154 -0
  41. data/starter_kits/php_advanced/demo/error_auth.php +71 -0
  42. data/starter_kits/php_advanced/demo/error_auth_refresh.php +71 -0
  43. data/starter_kits/php_advanced/demo/error_token_expired.php +76 -0
  44. data/starter_kits/php_advanced/demo/get_accounts.php +152 -0
  45. data/starter_kits/php_advanced/demo/get_customers.php +130 -0
  46. data/starter_kits/php_advanced/demo/get_transactions.php +146 -0
  47. data/starter_kits/php_advanced/demo/index.php +84 -0
  48. data/starter_kits/php_advanced/demo/refresh_token.php +39 -0
  49. data/starter_kits/php_advanced/demo/revoke_access.php +38 -0
  50. data/starter_kits/php_advanced/demo/setup.php +14 -0
  51. data/starter_kits/php_advanced/demo/transfer_money.php +241 -0
  52. data/starter_kits/php_advanced/demo/transfer_money_results.php +126 -0
  53. metadata +50 -2
@@ -0,0 +1,272 @@
1
+ <?php
2
+ namespace Fidor\SDK;
3
+
4
+ /**
5
+ * @method Fidor\SDK\Config setAccessToken( string $access_token )
6
+ * @method Fidor\SDK\Config setRefreshToken( string $refresh_token )
7
+ * @method Fidor\SDK\Config setUserAgent( string $user_agent )
8
+ * @method string getClientId()
9
+ * @method string getClientSecret()
10
+ * @method string getCallbackUrl()
11
+ * @method string getAccessToken( )
12
+ * @method integer getExpiresIn( )
13
+ * @method string getRefreshToken( )
14
+ * @method string getUserAgent( )
15
+ */
16
+ class Config {
17
+
18
+ /**
19
+ *
20
+ * @var string
21
+ */
22
+ protected $client_id;
23
+
24
+ /**
25
+ *
26
+ * @var string
27
+ */
28
+ protected $client_secret;
29
+
30
+ /**
31
+ *
32
+ * @var string
33
+ */
34
+ protected $callback_url;
35
+
36
+ /**
37
+ *
38
+ * @var boolean
39
+ */
40
+ protected $sandbox;
41
+
42
+ /**
43
+ *
44
+ * @var string
45
+ */
46
+ protected $access_token;
47
+
48
+ /**
49
+ *
50
+ * @var integer
51
+ */
52
+ protected $expires_in;
53
+
54
+ /**
55
+ *
56
+ * @var string
57
+ */
58
+ protected $refresh_token;
59
+
60
+ /**
61
+ * The base string used to build endpoints. You can override specific
62
+ * endpoints by providing values for oauth_url and/or api_url keys in the config array
63
+ *
64
+ * @var string
65
+ */
66
+ protected $base_uri = 'fidor.de';
67
+
68
+ /**
69
+ *
70
+ * @var string
71
+ */
72
+ protected $user_agent = 'FidorSDK (+https://docs.fidor.de)';
73
+
74
+ /**
75
+ *
76
+ * @var string
77
+ */
78
+ protected $api_url;
79
+
80
+ /**
81
+ *
82
+ * @var string
83
+ */
84
+ protected $oauth_url;
85
+
86
+ /**
87
+ * Constructor
88
+ *
89
+ * @param string $client_id
90
+ * @param string $client_secret
91
+ * @param boolean $sandbox
92
+ */
93
+ public function __construct( $client_id, $client_secret, $callback_url, $sandbox = false ) {
94
+ $this->client_id = $client_id;
95
+ $this->client_secret = $client_secret;
96
+ $this->callback_url = $callback_url;
97
+ $this->sandbox = (bool) $sandbox;
98
+ }
99
+
100
+ /**
101
+ * Handle setters/getters
102
+ *
103
+ * @param string $name
104
+ * @param array $args
105
+ * @return mixed
106
+ */
107
+ public function __call( $name, $args ) {
108
+ if ( preg_match( '/^get(.*)/', $name, $m ) ) {
109
+ $property = strtolower( preg_replace( '/([a-z])([A-Z])/', '$1_$2', $m[1] ) );
110
+ if ( property_exists( $this, $property ) ) {
111
+ return $this->$property;
112
+ }
113
+ } elseif ( preg_match( '/^set(.*)/', $name, $m ) ) {
114
+ $property = strtolower( preg_replace( '/([a-z])([A-Z])/', '$1_$2', $m[1] ) );
115
+ if ( property_exists( $this, $property ) ) {
116
+ $this->$property = current( $args );
117
+ return $this;
118
+ }
119
+ }
120
+ }
121
+
122
+ /**
123
+ *
124
+ * @param integer $expires_in
125
+ * @return \Fidor\SDK\Config
126
+ */
127
+ public function setExpiresIn( $expires_in ) {
128
+ if ( preg_match( '/^\d+$/', $expires_in ) ) {
129
+ $this->expires_in = $expires_in;
130
+ }
131
+ return $this;
132
+ }
133
+
134
+ /**
135
+ *
136
+ * @return boolean
137
+ */
138
+ public function hasTokenExpired( ) {
139
+ if ( $this->expires_in < time() ) {
140
+ return true;
141
+ }
142
+ return false;
143
+ }
144
+
145
+ /**
146
+ *
147
+ * @return boolean
148
+ */
149
+ public function is_sandbox( ) {
150
+ return $this->sandbox;
151
+ }
152
+
153
+ /**
154
+ *
155
+ * @param string $url
156
+ * @return \Fidor\SDK\Config
157
+ */
158
+ public function setOAuthUrl( $url ) {
159
+ $this->oauth_url = $url;
160
+ return $this;
161
+ }
162
+
163
+ /**
164
+ * Get base endpoint to OAuth authorization server
165
+ *
166
+ * @return string
167
+ */
168
+ public function getOAuthUrl( ) {
169
+ // maybe use user provided OAuth url
170
+ if ( ! empty( $this->oauth_url ) ) {
171
+ return $this->oauth_url;
172
+ }
173
+
174
+ return 'https://' . ( $this->sandbox ? 'aps' : 'apm' ) . '.fidor.de/oauth';
175
+ }
176
+
177
+ /**
178
+ *
179
+ * @param string $url
180
+ * @return \Fidor\SDK\Config
181
+ */
182
+ public function setApiUrl( $url ) {
183
+ $this->api_url = $url;
184
+ return $this;
185
+ }
186
+
187
+ /**
188
+ * Get base endpoint used for API calls
189
+ *
190
+ * @return string
191
+ */
192
+ public function getApiUrl( ) {
193
+ // maybe use user provided API url
194
+ if ( ! empty( $this->api_url ) ) {
195
+ return $this->api_url;
196
+ }
197
+
198
+ return 'https://' . ( $this->sandbox ? 'aps' : 'api' ) . '.fidor.de';
199
+ }
200
+
201
+ /**
202
+ * Create config instance from array
203
+ *
204
+ * @param array $info
205
+ * @return \Fidor\SDK\Config
206
+ */
207
+ public static function fromArray( array $info ) {
208
+ if ( ! empty( $info['client_id'] ) && ! empty( $info['client_secret'] ) ) {
209
+ // default to sandbox
210
+ if ( ! $info['sandbox'] ) {
211
+ $info['sandbox'] = true;
212
+ }
213
+
214
+ $sandbox = false;
215
+ $callback_url = null;
216
+
217
+ if ( 1 == $info['sandbox'] OR 'yes' === $info['sandbox'] OR 'true' === $info['sandbox'] OR true === $info['sandbox'] ) {
218
+ $sandbox = true;
219
+ }
220
+
221
+ if ( ! empty( $info['callback_url'] ) ) {
222
+ $callback_url = $info['callback_url'];
223
+ }
224
+
225
+ $obj = new self( $info['client_id'], $info['client_secret'], $callback_url, $sandbox );
226
+
227
+ $props = array( 'user_agent', 'oauth_url', 'api_url' );
228
+ foreach ( $props as $prop ) {
229
+ if ( empty( $info[ $prop ] ) OR ! is_string( $info[ $prop ] ) ) {
230
+ continue;
231
+ }
232
+
233
+ $value = $info[ $prop ];
234
+ if ( 'user_agent' === $prop ) {
235
+ $obj->setUserAgent( $value );
236
+ } elseif ( 'oauth_url' === $prop ) {
237
+ $obj->setOAuthUrl( $value );
238
+ } elseif ( 'api_url' === $prop ) {
239
+ $obj->setApiUrl( $value );
240
+ }
241
+ }
242
+
243
+ return $obj;
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Create a config instance from JSON string
249
+ *
250
+ * @param string $json
251
+ * @return \Fidor\SDK\Config
252
+ */
253
+ public static function fromJSON( $json ) {
254
+ $info = json_decode( $json, true );
255
+ if ( ! empty( $info['client_id'] ) && ! empty( $info['client_secret'] ) && isset( $info['sandbox'] ) ) {
256
+ return self::fromArray( $info );
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Create a config instance from JSON file
262
+ *
263
+ * @param string $file
264
+ * @return \Fidor\SDK\Config
265
+ */
266
+ public static function fromJSONFile( $file ) {
267
+ if ( is_readable( $file ) ) {
268
+ return self::fromJSON( file_get_contents( $file ) );
269
+ }
270
+ }
271
+
272
+ }
@@ -0,0 +1,27 @@
1
+ <?php
2
+ namespace Fidor\SDK;
3
+
4
+ class Customers extends Client {
5
+
6
+ /**
7
+ *
8
+ * @param \Fidor\SDK\Config $config
9
+ */
10
+ public function __construct( Config $config ) {
11
+ parent::__construct( $config );
12
+ }
13
+
14
+ /**
15
+ *
16
+ * @param integer $id
17
+ * @return string
18
+ */
19
+ public function get( $id = null ) {
20
+ $data = parent::get( $this->config->getApiUrl() . '/customers' );
21
+ if ( ! empty( $data['data'] ) ) {
22
+ $data = $data['data'];
23
+ }
24
+ return $data;
25
+ }
26
+
27
+ }
@@ -0,0 +1,47 @@
1
+ <?php
2
+ namespace Fidor\SDK;
3
+
4
+ class Transactions extends Client {
5
+
6
+ /**
7
+ *
8
+ * @param \Fidor\SDK\Config $config
9
+ */
10
+ public function __construct( Config $config ) {
11
+ parent::__construct( $config );
12
+ }
13
+
14
+ /**
15
+ *
16
+ * @param integer|null $id
17
+ * @param integer|null $page
18
+ * @param integer|null $per_page
19
+ * @return string
20
+ */
21
+ public function get( $id = null, $page = null, $per_page = null ) {
22
+ $url = $this->config->getApiUrl() . '/transactions';
23
+ if ( $id ) {
24
+ $url .= '/' . $id;
25
+ } elseif ( is_numeric( $page ) OR is_numeric( $per_page ) ) {
26
+ $url .= '/?page=' . ( $page ? $page : 1 ) . '&per_page=' . ( $per_page ? $per_page : 10 );
27
+ }
28
+ $data = parent::get( $url );
29
+ if ( ! empty( $data['data'] ) ) {
30
+ $data = $data['data'];
31
+ }
32
+ return $data;
33
+ }
34
+
35
+
36
+ /**
37
+ *
38
+ * @return string
39
+ */
40
+ public static function make_external_uid(){
41
+ if ( function_exists('com_create_guid') === true ) {
42
+ return trim(com_create_guid(), '{}');
43
+ }
44
+ return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
45
+ }
46
+
47
+ }
@@ -0,0 +1,65 @@
1
+ <?php
2
+ namespace Fidor\SDK;
3
+
4
+ /**
5
+ * @property \Fidor\SDK\Transfers_Internals $internal Internal transfers object
6
+ */
7
+ class Transfers extends Client {
8
+
9
+ /**
10
+ *
11
+ * @var integer
12
+ */
13
+ protected $id;
14
+
15
+ /**
16
+ *
17
+ * @var array
18
+ */
19
+ protected $types = array( 'batch', 'global', 'internal', 'sepa' => array( 'SEPA' ) );
20
+
21
+ /**
22
+ *
23
+ * @param \Fidor\SDK\Config $config
24
+ */
25
+ public function __construct( Config $config ) {
26
+ parent::__construct( $config );
27
+ }
28
+
29
+ /**
30
+ *
31
+ * @param integer $id
32
+ * @return \Fidor\SDK\Transfers
33
+ */
34
+ public function setId( $id ) {
35
+ $this->id = $id;
36
+ return $this;
37
+ }
38
+
39
+ /**
40
+ *
41
+ * @param string $name
42
+ * @return mixed
43
+ */
44
+ public function __get( $name ) {
45
+ if ( in_array( $name, $this->types ) ) {
46
+ $name = 'Transfers_' . ucfirst( $name );
47
+ } elseif ( in_array( $name, array_keys( $this->types ) ) ) {
48
+ $name = 'Transfers_' . current( $this->types[ $name ] );
49
+ }
50
+
51
+ return parent::__get( $name );
52
+ }
53
+
54
+ /**
55
+ *
56
+ * @return string
57
+ */
58
+ public static function make_external_uid(){
59
+ if ( function_exists('com_create_guid') === true ) {
60
+ return trim(com_create_guid(), '{}');
61
+ }
62
+ return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
63
+ }
64
+
65
+ }
@@ -0,0 +1,18 @@
1
+ <?php
2
+ namespace Fidor\SDK;
3
+
4
+ class Transfers_Batch extends Client {
5
+
6
+ /**
7
+ *
8
+ * @param \Fidor\SDK\Config $config
9
+ */
10
+ public function __construct( Config $config ) {
11
+ parent::__construct( $config );
12
+ }
13
+
14
+ public function get( ) {
15
+ return parent::get( $this->config->getApiUrl() . '/batch_transfer' );
16
+ }
17
+
18
+ }
@@ -0,0 +1,18 @@
1
+ <?php
2
+ namespace Fidor\SDK;
3
+
4
+ class Transfers_Global extends Client {
5
+
6
+ /**
7
+ *
8
+ * @param \Fidor\SDK\Config $config
9
+ */
10
+ public function __construct( Config $config ) {
11
+ parent::__construct( $config );
12
+ }
13
+
14
+ public function get( ) {
15
+ return parent::get( $this->config->getApiUrl() . '/global_money_transfers' );
16
+ }
17
+
18
+ }