Skip to content

Commit 18c35c4

Browse files
committed
feat(api)!: remove magic service properties from SumUp
Drop property-based service access and keep explicit service methods as the only public SDK entrypoint (e.g. checkouts()). Update README, examples, and tests to use method-based access consistently. Align the dormant codegen SumUp template with method-only service access. BREAKING CHANGE: property access like $sumup->checkouts is no longer supported; use $sumup->checkouts() instead.
1 parent 08a0b17 commit 18c35c4

File tree

9 files changed

+38
-184
lines changed

9 files changed

+38
-184
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ try {
3737
// SDK automatically uses SUMUP_API_KEY environment variable
3838
$sumup = new \SumUp\SumUp();
3939

40-
$checkout = $sumup->checkouts->create([
40+
$checkout = $sumup->checkouts()->create([
4141
'amount' => 10.00,
4242
'currency' => 'EUR',
4343
'checkout_reference' => 'your-checkout-ref',
@@ -119,7 +119,7 @@ $sumup = new \SumUp\SumUp([
119119

120120
## API Reference
121121

122-
For a full list of available services and methods, explore the `src/Services/` directory or check the inline documentation in the code.
122+
For a full list of available services and methods, explore the service files under `src/*/*.php` (for example `src/Checkouts/Checkouts.php`) or check the inline documentation in the code.
123123

124124
## License
125125

codegen/pkg/generator/sumup.go

Lines changed: 13 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88
"path/filepath"
99
"slices"
10-
"strings"
1110

1211
"github.com/iancoleman/strcase"
1312
)
@@ -51,13 +50,7 @@ namespace SumUp;
5150
* Class SumUp
5251
*
5352
* @package SumUp
54-
`)
55-
56-
if propertyDocs := renderSumUpPropertyDocs(services); propertyDocs != "" {
57-
buf.WriteString(propertyDocs)
58-
}
59-
60-
buf.WriteString(` */
53+
*/
6154
class SumUp
6255
{
6356
/**
@@ -74,12 +67,7 @@ class SumUp
7467
7568
`)
7669

77-
if serviceMap := renderSumUpServiceMap(services); serviceMap != "" {
78-
buf.WriteString(serviceMap)
79-
}
80-
8170
buf.WriteString(`
82-
8371
/**
8472
* SumUp constructor.
8573
*
@@ -160,30 +148,20 @@ class SumUp
160148
return $config;
161149
}
162150
163-
/**
164-
* Proxy access to services via properties.
165-
*
166-
* @param string $name
167-
*
168-
* @return SumUpService|null
169-
*/
170-
public function __get($name)
171-
{
172-
if (!array_key_exists($name, self::$serviceClassMap)) {
173-
trigger_error('Undefined property: ' . static::class . '::$' . $name);
174-
175-
return null;
176-
}
177-
178-
if (empty($this->accessToken)) {
179-
throw new ConfigurationException('No access token provided');
180-
}
151+
`)
181152

182-
$token = $this->accessToken;
183-
$serviceClass = self::$serviceClassMap[$name];
153+
for _, service := range services {
154+
method := strcase.ToLowerCamel(service)
155+
fmt.Fprintf(&buf, " public function %s()\n", method)
156+
buf.WriteString(" {\n")
157+
buf.WriteString(" if (empty($this->accessToken)) {\n")
158+
buf.WriteString(" throw new ConfigurationException('No access token provided');\n")
159+
buf.WriteString(" }\n\n")
160+
fmt.Fprintf(&buf, " return new %s($this->client, $this->accessToken);\n", service)
161+
buf.WriteString(" }\n\n")
162+
}
184163

185-
return new $serviceClass($this->client, $token);
186-
}
164+
buf.WriteString(`
187165
}
188166
`)
189167

@@ -236,7 +214,6 @@ func sumUpUseStatements(serviceNames []string) []string {
236214
}
237215

238216
serviceSet := map[string]struct{}{
239-
"SumUp\\Services\\SumUpService": {},
240217
}
241218

242219
for _, name := range serviceNames {
@@ -248,39 +225,3 @@ func sumUpUseStatements(serviceNames []string) []string {
248225

249226
return append(uses, serviceUses...)
250227
}
251-
252-
//nolint:unused // helper for generating the SumUp class docblocks
253-
func renderSumUpPropertyDocs(serviceNames []string) string {
254-
if len(serviceNames) == 0 {
255-
return ""
256-
}
257-
258-
var buf strings.Builder
259-
buf.WriteString(" *\n")
260-
for _, service := range serviceNames {
261-
fmt.Fprintf(&buf, " * @property %s $%s\n", service, strcase.ToLowerCamel(service))
262-
}
263-
264-
return buf.String()
265-
}
266-
267-
//nolint:unused // helper for generating the SumUp class service map
268-
func renderSumUpServiceMap(serviceNames []string) string {
269-
if len(serviceNames) == 0 {
270-
return ""
271-
}
272-
273-
var buf strings.Builder
274-
buf.WriteString(" /**\n")
275-
buf.WriteString(" * Map of property names to service classes.\n")
276-
buf.WriteString(" *\n")
277-
buf.WriteString(" * @var array<string, string>\n")
278-
buf.WriteString(" */\n")
279-
buf.WriteString(" private static $serviceClassMap = [\n")
280-
for _, service := range serviceNames {
281-
fmt.Fprintf(&buf, " '%s' => %s::class,\n", strcase.ToLowerCamel(service), service)
282-
}
283-
buf.WriteString(" ];\n\n")
284-
285-
return buf.String()
286-
}

examples/custom-http-client.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
*/
3636
class CustomLoggingHttpClient implements \SumUp\HttpClient\HttpClientInterface
3737
{
38-
private $wrappedClient;
38+
private \SumUp\HttpClient\HttpClientInterface $wrappedClient;
3939

4040
public function __construct(\SumUp\HttpClient\HttpClientInterface $wrappedClient)
4141
{
4242
$this->wrappedClient = $wrappedClient;
4343
}
4444

45-
public function send($method, $url, $body, $headers, $options = null)
45+
public function send(string $method, string $url, array $body, array $headers, ?array $options = null): \SumUp\HttpClient\Response
4646
{
4747
// Log the request
4848
echo "[HTTP Request] {$method} {$url}\n";
@@ -54,7 +54,7 @@ public function send($method, $url, $body, $headers, $options = null)
5454
$response = $this->wrappedClient->send($method, $url, $body, $headers, $options);
5555

5656
// Log the response
57-
echo "[HTTP Response] Status: " . $response->getHttpStatusCode() . "\n";
57+
echo "[HTTP Response] Status: " . $response->getHttpResponseCode() . "\n";
5858

5959
return $response;
6060
}
@@ -83,7 +83,7 @@ public function send($method, $url, $body, $headers, $options = null)
8383

8484
// Use the SDK normally - all requests will be logged
8585
try {
86-
$merchant = $sumup->merchants->get($merchantCode);
86+
$merchant = $sumup->merchants()->get($merchantCode);
8787
echo "\nMerchant retrieved successfully!\n";
8888
echo "Merchant code: " . $merchant->merchantCode . "\n";
8989
} catch (\SumUp\Exception\SDKException $e) {

examples/guzzle-http-client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
]);
3636

3737
try {
38-
$merchant = $sumup->merchants->get($merchantCode);
38+
$merchant = $sumup->merchants()->get($merchantCode);
3939
echo "\nMerchant retrieved successfully!\n";
4040
echo "Merchant code: " . $merchant->merchantCode . "\n";
4141
} catch (\SumUp\Exception\SDKException $e) {

examples/oauth2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ $sumup = new \SumUp\SumUp();
8686
$sumup->setDefaultAccessToken($accessToken);
8787

8888
// Use the SDK normally
89-
$checkout = $sumup->checkouts->create([
89+
$checkout = $sumup->checkouts()->create([
9090
'amount' => 10.00,
9191
'currency' => 'EUR',
9292
'checkout_reference' => 'order-123',

examples/oauth2/oauth2-server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function handleCallback(GenericProvider $provider): void
154154
if ($defaultMerchantCode) {
155155
echo '<h2>Merchant Information:</h2>';
156156
try {
157-
$merchant = $sumup->merchants->get($defaultMerchantCode);
157+
$merchant = $sumup->merchants()->get($defaultMerchantCode);
158158
echo '<pre>' . htmlspecialchars(json_encode($merchant, JSON_PRETTY_PRINT)) . '</pre>';
159159
} catch (Exception $e) {
160160
echo '<p style="color: red;">Error fetching merchant: ' . htmlspecialchars($e->getMessage()) . '</p>';
@@ -177,7 +177,7 @@ function handleCallback(GenericProvider $provider): void
177177
\'access_token\' => \'' . $accessToken->getToken() . '\',
178178
]);
179179
180-
$checkout = $sumup->checkouts->create([
180+
$checkout = $sumup->checkouts()->create([
181181
\'amount\' => 10.00,
182182
\'currency\' => \'EUR\',
183183
\'checkout_reference\' => \'my-order-123\',

examples/simple.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// $sumup->setDefaultAccessToken('your-token-here');
3434

3535
// Use services with the default token
36-
$merchant = $sumup->merchants->get($merchantCode);
36+
$merchant = $sumup->merchants()->get($merchantCode);
3737
print_r($merchant);
3838

3939
// Override the default token by creating a new client instance instead.

0 commit comments

Comments
 (0)