├── .github
├── dependabot.yml
└── workflows
│ ├── ci.yaml
│ └── lint-actions.yaml
├── .gitignore
├── .php-cs-fixer.php
├── LICENSE
├── Makefile
├── README.md
├── SECURITY.md
├── composer.json
├── docs
├── ExceptionsHandling.md
├── HowToAuthorize.md
├── HowToOverrideHttpClient.md
├── README.md
└── reference
│ ├── AccessToken.md
│ ├── ApplicationConfiguration.md
│ ├── Authorization.md
│ ├── Checkouts.md
│ ├── Custom.md
│ ├── Customers.md
│ ├── Merchant.md
│ ├── Payouts.md
│ ├── Response.md
│ ├── SumUp.md
│ ├── SumUpArgumentException.md
│ ├── SumUpAuthenticationException.md
│ ├── SumUpConfigurationException.md
│ ├── SumUpConnectionException.md
│ ├── SumUpResponseException.md
│ ├── SumUpSDKException.md
│ ├── SumUpServerException.md
│ ├── SumUpValidationException.md
│ └── Transactions.md
├── examples
└── simple.php
└── src
└── SumUp
├── Application
├── ApplicationConfiguration.php
└── ApplicationConfigurationInterface.php
├── Authentication
└── AccessToken.php
├── Exceptions
├── SumUpArgumentException.php
├── SumUpAuthenticationException.php
├── SumUpConfigurationException.php
├── SumUpConnectionException.php
├── SumUpResponseException.php
├── SumUpSDKException.php
├── SumUpServerException.php
└── SumUpValidationException.php
├── HttpClients
├── HttpClientsFactory.php
├── Response.php
├── SumUpCUrlClient.php
├── SumUpGuzzleHttpClient.php
└── SumUpHttpClientInterface.php
├── Services
├── Authorization.php
├── Checkouts.php
├── Custom.php
├── Customers.php
├── Merchant.php
├── Payouts.php
├── SumUpService.php
└── Transactions.php
├── SumUp.php
└── Utils
├── ExceptionMessages.php
└── Headers.php
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "github-actions"
4 | directory: "/"
5 | schedule:
6 | interval: "weekly"
7 | open-pull-requests-limit: 3
8 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | workflow_dispatch: {}
5 | push:
6 | branches:
7 | - master
8 | tags:
9 | - v[0-9]+.[0-9]+.[0-9]+*
10 | pull_request:
11 | branches:
12 | - master
13 |
14 | jobs:
15 | lint:
16 | name: Lint
17 | runs-on: ubuntu-latest
18 | steps:
19 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20 |
21 | - name: Lint
22 | uses: docker://oskarstark/php-cs-fixer-ga:3.4.0
23 | with:
24 | args: --format=txt --diff --dry-run --using-cache=no --verbose
25 |
--------------------------------------------------------------------------------
/.github/workflows/lint-actions.yaml:
--------------------------------------------------------------------------------
1 | name: Github Actions
2 |
3 | on:
4 | pull_request:
5 | paths:
6 | - '.github/**'
7 |
8 | defaults:
9 | run:
10 | working-directory: ./.github
11 |
12 | permissions:
13 | contents: read
14 |
15 | jobs:
16 | actionlint:
17 | name: Lint
18 | runs-on: ubuntu-latest
19 | steps:
20 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21 | with:
22 | persist-credentials: false
23 | sparse-checkout: |
24 | .github
25 |
26 | - uses: reviewdog/action-actionlint@a5524e1c19e62881d79c1f1b9b6f09f16356e281 # v1.65.2
27 | with:
28 | filter_mode: nofilter
29 | fail_on_error: true
30 | reporter: github-pr-check
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | composer.phar
2 | composer.lock
3 | /vendor/
4 | **/coverage
5 |
6 | # PHP CS Fixer
7 | .php_cs
8 | .php_cs.cache
9 | .php-cs-fixer.cache
10 |
--------------------------------------------------------------------------------
/.php-cs-fixer.php:
--------------------------------------------------------------------------------
1 | in(__DIR__);
5 |
6 | $config = new PhpCsFixer\Config();
7 | $config->setRules([
8 | '@PSR2' => true,
9 | 'no_unused_imports' => true,
10 | 'no_trailing_whitespace' => true,
11 | 'single_blank_line_at_eof' => true,
12 | 'encoding' => true,
13 | 'full_opening_tag' => true,
14 | 'no_closing_tag' => true,
15 | 'concat_space' => ['spacing' => 'one'],
16 |
17 | // PHP 5.6 compatibility
18 | 'visibility_required' => [
19 | 'elements' => [
20 | 'method',
21 | 'property',
22 | ],
23 | ],
24 | ]);
25 | $config->setFinder($finder);
26 | return $config;
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2019 SumUp Ltd
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # Make this makefile self-documented with target `help`
2 | .PHONY: help
3 | .DEFAULT_GOAL := help
4 | help: ## Show help
5 | @grep -Eh '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
6 |
7 | export PHPDOCUMENTOR_VERSION := v3.0.0
8 |
9 | .PHONY: vendor
10 | vendor: composer.json ## Install dependencies
11 | composer install
12 |
13 | .PHONY: fmt
14 | fmt: vendor ## Format code using php-cs-fixer
15 | PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix -v --using-cache=no
16 |
17 | .PHONY: fmtcheck
18 | fmtcheck: vendor ## Check code formatting
19 | PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # SumUp Ecommerce PHP SDK
4 |
5 | [](https://github.com/sumup/sumup-go/)
6 | [](https://packagist.org/packages/sumup/sumup-ecom-php-sdk)
7 | [](https://packagist.org/packages/sumup/sumup-ecom-php-sdk)
8 | [](./LICENSE)
9 | [](https://github.com/sumup/sumup-go/tree/main/CODE_OF_CONDUCT.md)
10 |
11 |
12 |
13 | ## Overview
14 |
15 | This repository contains the open source PHP SDK that allows you to integrate quickly with the SumUp's [API](https://developer.sumup.com/rest-api) endpoints.
16 |
17 | ## Installation
18 |
19 | The SumUp eCom PHP SDK can be installed with [Composer](https://getcomposer.org/). Run the following command:
20 |
21 | ```
22 | composer require sumup/sumup-ecom-php-sdk
23 | ```
24 |
25 | ## Basic usage
26 |
27 | ```php
28 | try {
29 | $sumup = new \SumUp\SumUp([
30 | 'app_id' => 'YOUR-CLIENT-ID',
31 | 'app_secret' => 'YOUR-CLIENT-SECRET',
32 | 'code' => 'YOUR-AUTHORIZATION-CODE'
33 | ]);
34 | $checkoutService = $sumup->getCheckoutService();
35 | $checkoutResponse = $checkoutService->create($amount, $currency, $checkoutRef, $payToEmail);
36 | $checkoutId = $checkoutResponse->getBody()->id;
37 | // pass the $chekoutId to the front-end to be processed
38 | } catch (\SumUp\Exceptions\SumUpAuthenticationException $e) {
39 | echo 'Authentication error: ' . $e->getMessage();
40 | } catch (\SumUp\Exceptions\SumUpResponseException $e) {
41 | echo 'Response error: ' . $e->getMessage();
42 | } catch(\SumUp\Exceptions\SumUpSDKException $e) {
43 | echo 'SumUp SDK error: ' . $e->getMessage();
44 | }
45 | ```
46 |
47 | ## API Reference
48 |
49 | For a full list of classes, see the [API reference page](https://github.com/sumup/sumup-ecom-php-sdk/tree/master/docs).
50 |
51 | ## FAQ
52 |
53 | * [How to authorize?](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/HowToAuthorize.md)
54 | * [How to handle exceptions?](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/ExceptionsHandling.md)
55 | * [How to use my own HTTP client?](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/HowToOverrideHttpClient.md)
56 |
57 | ## Roadmap
58 |
59 | | Version | Status | PHP Version |
60 | |--- |--- |--- |
61 | | 1.x | Latest | \>= 5.6 |
62 |
63 | ## License
64 |
65 | For information about the license see the [license](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/LICENSE.md) file.
66 |
67 | ## Contact us
68 |
69 | If you have found a bug or you lack some functionality please [open an issue](https://github.com/sumup/sumup-ecom-php-sdk/issues/new). If you have other issues when integrating with SumUp's API you can send an email to [integration@sumup.com](mailto:integration@sumup.com).
70 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | The security of SumUp PHP SDK is of paramount importance to us, and we genuinely appreciate the community's efforts to identify and report vulnerabilities.
4 |
5 | ## Supported Versions
6 |
7 | We recommend users stay updated with the latest version of our project for optimal stability and security.
8 |
9 | ## Reporting a Vulnerability
10 |
11 | Please do not open GitHub issues or pull requests - this makes the vulnerability immediately visible to everyone, including malicious actors. Security issues in this open-source project can be safely reported via the private SumUp bug bounty program.
12 |
13 | To get an invite to our Hackerone private bug bounty program reach out to us via bugbounty at sumup com.
14 |
15 | The SumUp security team will triage your report and determine whether or not is it eligible for a bounty under our program.
16 |
17 | ## General Guidelines
18 |
19 | - **Prioritize Confidentiality:** We urge you not to disclose the vulnerability publicly until it's been addressed, ensuring the broader community isn't inadvertently put at risk.
20 | - **Ethical Practices:** Engage in responsible and ethical behavior. Refrain from actions that compromise user privacy, system integrity, or availability.
21 | - **When in Doubt, Reach Out:** If you're uncertain about the significance of a potential security issue, it's always better to err on the side of caution and notify us.
22 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sumup/sumup-ecom-php-sdk",
3 | "description": "SumUp PHP SDK",
4 | "type": "library",
5 | "license": "Apache-2.0",
6 | "version": "1.2.0",
7 | "keywords": [
8 | "sumup",
9 | "sdk",
10 | "payment processing",
11 | "ecommerce",
12 | "payment",
13 | "checkout"
14 | ],
15 | "homepage": "https://developer.sumup.com",
16 | "authors": [
17 | {
18 | "name": "SumUp",
19 | "email": "integration@sumup.com",
20 | "homepage": "https://github.com/sumup"
21 | }
22 | ],
23 | "scripts": {
24 | "cs": "php-cs-fixer fix --dry-run --diff"
25 | },
26 | "require": {
27 | "php": "^5.6|^7.0|^8.0"
28 | },
29 | "require-dev": {
30 | "friendsofphp/php-cs-fixer": "3.5.0"
31 | },
32 | "suggest": {
33 | "guzzlehttp/guzzle": "Allows for implementation of the Guzzle HTTP client"
34 | },
35 | "autoload": {
36 | "psr-4": {
37 | "SumUp\\": "src/SumUp/"
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/docs/ExceptionsHandling.md:
--------------------------------------------------------------------------------
1 | # Exceptions handling
2 |
3 | Exceptions handling is an important part of our code. We pay attention to this detail and **we recommend to wrap every statement from this SDK with a `try {} catch() {}` clause**.
4 |
5 | You should at least handle `\SumUp\Exceptions\SumUpSDKException` exception but if you want you can handle all sorts of exceptions.
6 |
7 | ```php
8 | try {
9 | $sumup = new \SumUp\SumUp($config);
10 | } catch (\SumUp\Exceptions\SumUpAuthenticationException $e) {
11 | echo $e->getCode() . ': ' . $e->getMessage();
12 | } catch (\SumUp\Exceptions\SumUpResponseException $e) {
13 | echo $e->getCode() . ': ' . $e->getMessage();
14 | } catch (\SumUp\Exceptions\SumUpSDKException $e) {
15 | echo $e->getCode() . ': ' . $e->getMessage();
16 | }
17 | ```
18 |
19 | More information about the exceptions can be found in [the reference](https://github.com/sumup/sumup-ecom-php-sdk/tree/master/docs#exceptions).
20 |
--------------------------------------------------------------------------------
/docs/HowToAuthorize.md:
--------------------------------------------------------------------------------
1 | # How to authorize using the SDK
2 |
3 | ## Overview
4 |
5 | This guide will help you to authorize and get an OAuth 2.0 token using the SDK. If you want to know what happens behind the scenes you can visit this [authorization guide](https://developer.sumup.com/docs/authorization).
6 |
7 | Every time you make an instance of the `\SumUp\SumUp` class you get a valid OAuth 2.0 access token. The access token is then passed to every service call you make (but of course you can [override](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/HowToOverrideHttpClient.md) this).
8 |
9 | ## Authorization code flow
10 |
11 | > **Note:** this is the flow we recommend.
12 |
13 | First you need to send the merchant to pass through the [authorization flow](https://developer.sumup.com/docs/authorization#1-your-application-requests-authorization) so you can get a `code` and after that you can continue with the following example code.
14 |
15 | ```php
16 | $sumup = new \SumUp\SumUp([
17 | 'app_id' => 'YOUR-CLIENT-ID',
18 | 'app_secret' => 'YOUR-CLIENT-SECRET',
19 | 'grant_type' => 'authorization_code',
20 | 'scopes' => ['payments', 'transactions.history', 'user.app-settings', 'user.profile_readonly'],
21 | 'code' => 'YOUR-AUTHORIZATION-CODE'
22 | ]);
23 | $accessToken = $sumup->getAccessToken();
24 | $refreshToken = $accessToken->getRefreshToken();
25 | $value = $accessToken->getValue();
26 | ```
27 |
28 | > **Note:** once you get a refresh token you can store it in a database and then use it to get new access tokens for the same merchant.
29 |
30 | For more information about this flow read in [this guide](https://developer.sumup.com/docs/authorization#authorization-code-flow).
31 |
32 | ## Client credentials flow
33 |
34 | If you want to use just the `client_id` and the `client_secret` you can use following snippet of code but keep in mind that not all endpoints can be requested with access token from this flow.
35 |
36 | ```php
37 | $sumup = new \SumUp\SumUp([
38 | 'app_id' => 'YOUR-CLIENT-ID',
39 | 'app_secret' => 'YOUR-CLIENT-SECRET',
40 | 'grant_type' => 'client_credentials',
41 | 'scopes' => ['payments', 'transactions.history', 'user.app-settings', 'user.profile_readonly']
42 | ]);
43 | $accessToken = $sumup->getAccessToken();
44 | $value = $accessToken->getValue();
45 | ```
46 |
47 | For more information about this flow read in [this guide](https://developer.sumup.com/docs/authorization#client-credentials-flow).
48 |
49 | ## How to get new access from a refresh token
50 |
51 | Here is how to get a **new access token from a refresh token**:
52 |
53 | ```php
54 | $sumup = new \SumUp\SumUp([
55 | 'app_id' => 'YOUR-CLIENT-ID',
56 | 'app_secret' => 'YOUR-CLIENT-SECRET',
57 | 'scopes' => ['payments', 'transactions.history', 'user.app-settings', 'user.profile_readonly'],
58 | 'refresh_token' => 'REFRESH-TOKEN'
59 | ]);
60 | // you need to call the method `refreshToken()` to get a new access token
61 | $refreshedAccessToken = $sumup->refreshToken();
62 | $value = $refreshedAccessToken->getValue();
63 | ```
64 |
65 | > **Note:** keep in mind that the refresh token can also expire although it has long life span. For more information you can read [here](https://developer.sumup.com/docs/authorization#6-the-authorization-server-returns-an-access-token).
66 |
67 | ## How to reuse a valid access token
68 |
69 | If you already have a valid access token you can reuse it like this:
70 |
71 | ```php
72 | $sumup = new \SumUp\SumUp([
73 | 'app_id' => 'YOUR-CLIENT-ID',
74 | 'app_secret' => 'YOUR-CLIENT-SECRET',
75 | 'scopes' => ['payments', 'transactions.history', 'user.app-settings', 'user.profile_readonly'],
76 | 'access_token' => 'VALID-ACCESS-TOKEN'
77 | ]);
78 | ```
79 |
80 | ## Override access token for a service
81 |
82 | You can always initialize a service with an access token that is different from the one you already have from your `SumUp\SumUp` instance.
83 |
84 | ```php
85 | $checkoutService = $sumup->getCheckoutService('ACCESS-TOKEN-INSTANCE');
86 | ```
87 |
--------------------------------------------------------------------------------
/docs/HowToOverrideHttpClient.md:
--------------------------------------------------------------------------------
1 | # How to override HttpClient
2 |
3 | ## Overview
4 |
5 | We provide two clients for dealing with HTTP communication: `\SumUp\HttpClients\SumUpCUrlClient` and `\SumUp\HttpClients\SumUpGuzzleHttpClient`. We also give the option to use your own HTTP client if you want to.
6 |
7 | ## \SumUp\HttpClients\SumUpCUrlClient
8 |
9 | The `SumUpCUrlClient` client provides functionality for creating HTTP requests and getting responses using the PHP module [cURL](http://php.net/manual/en/book.curl.php).
10 |
11 | ## \SumUp\HttpClients\SumUpGuzzleHttpClient
12 |
13 | The `SumUpGuzzleHttpClient` client provides functionality for creating HTTP requests and getting responses using the open-source library [Guzzle](https://packagist.org/packages/guzzlehttp/guzzle). We support **version 6.x** of the library.
14 |
15 | > **Note:** This library is not required for using this SDK.
16 |
17 | ## Create your own HTTP client
18 |
19 | If you have another way of HTTP communication you can make a class that implements the interface `\SumUp\HttpClients\SumUpHttpClientInterface`. After that you can pass an instance of that class to the constructor of `\SumUp\SumUp` as second parameter. Then the SDK would use this client for every request to the SumUp's servers.
20 |
21 | > **Note:** you also have to **handle** all the **responses** and all the **exceptions** that might occur.
22 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # SumUp Ecommerce PHP SDK Reference
2 |
3 | Here is the API reference for the SumUp Ecommerce SDK for PHP.
4 |
5 | ## Core API
6 |
7 | | Class name | Description |
8 | |--- |--- |
9 | | [\SumUp\SumUp](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUp.md) | The main object that helps tie all the SDK components together. |
10 | | [\SumUp\Application\ApplicationConfiguration](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/ApplicationConfiguration.md) | An entity that represents all the application's configurations. |
11 | | [\SumUp\Authentication\AccessToken](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/AccessToken.md) | An entity that represents an access token. |
12 | | [\SumUp\HttpClients\Response](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Response.md) | The response object that every service returns. |
13 |
14 | ## Services
15 |
16 | | Class name | Description |
17 | |--- |--- |
18 | | [\SumUp\Services\Authorization](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Authorization.md) | The service that manages creating and refreshing OAuth2.0 access tokens. |
19 | | [\SumUp\Services\Checkouts](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Checkouts.md) | The service that manages checkouts. |
20 | | [\SumUp\Services\Custom](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Custom.md) | The generic service that can be used for endpoints that are not part of the core functionality. |
21 | | [\SumUp\Services\Customers](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Customers.md) | The service that manages customers. |
22 | | [\SumUp\Services\Merchant](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Merchant.md) | The service that manages merchant's profile. |
23 | | [\SumUp\Services\Payouts](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Payouts.md) | The service that manages payouts. |
24 | | [\SumUp\Services\Transactions](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Transactions.md) | The service that manages transactions. |
25 |
26 |
33 |
34 | ## Exceptions
35 |
36 | | Class name | Description |
37 | |--- |--- |
38 | | [\SumUp\Exceptions\SumUpSDKException](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUpSDKException.md) | The core exception that every other exception in the SDK inherits from. |
39 | | [\SumUp\Exceptions\SumUpArgumentException](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUpArgumentException.md) | The exception for passing bad arguments to functions. |
40 | | [\SumUp\Exceptions\SumUpAuthenticationException](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUpAuthenticationException.md) | The exception for problems with the authentication. |
41 | | [\SumUp\Exceptions\SumUpConfigurationException](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUpConfigurationException.md) | The exception for passing bad configurations to the SDK. |
42 | | [\SumUp\Exceptions\SumUpConnectionException](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUpConnectionException.md) | The exception for problems with network communication. |
43 | | [\SumUp\Exceptions\SumUpResponseException](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUpResponseException.md) | The exception for errors in the response from a request. |
44 | | [\SumUp\Exceptions\SumUpServerException](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUpServerException.md) | The exception for server errors. |
45 | | [\SumUp\Exceptions\SumUpValidationException](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/SumUpValidationException.md) | The exception for server validation of the sent values. |
46 |
--------------------------------------------------------------------------------
/docs/reference/AccessToken.md:
--------------------------------------------------------------------------------
1 | # AccessToken for the SumUp Ecommerce SDK for PHP
2 |
3 | Requests to the SumUp's API need to have an access token sent with them to identify the application and the user. The `\SumUp\Authentication\AccessToken` entity represents an access token.
4 |
5 | ## \SumUp\Authentication\AccessToken
6 |
7 | Every time you create an instance of `\SumUp\SumUp` you get an `AccessToken` that can be used to request other resources.
8 |
9 | ## Instance Methods
10 |
11 | ### getValue()
12 |
13 | ```php
14 | public function getValue(): string
15 | ```
16 |
17 | Returns the actual value of the access token as a string.
18 |
19 | ### getType()
20 |
21 | ```php
22 | public function getType(): string
23 | ```
24 |
25 | Returns the type of authentication that the access token should be used for.
26 |
27 | ### getExpiresIn()
28 |
29 | ```php
30 | public function getExpiresIn(): int
31 | ```
32 |
33 | Returns the total number of seconds the access token is valid for.
34 |
35 | ### getScopes()
36 |
37 | ```php
38 | public function getScopes(): array
39 | ```
40 |
41 | Returns the scopes for which the access token is valid.
42 |
43 | ### getRefreshToken()
44 |
45 | ```php
46 | public function getRefreshToken(): ?string
47 | ```
48 |
49 | Returns the value of a refresh token if there is one provided.
50 |
--------------------------------------------------------------------------------
/docs/reference/ApplicationConfiguration.md:
--------------------------------------------------------------------------------
1 | # ApplicationConfiguration for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\Application\ApplicationConfiguration
4 |
5 | The `\SumUp\Application\ApplicationConfiguration` entity provides all the configurations needed to work with this SDK.
6 |
7 | ## Instance Methods
8 |
9 | ### getAppId()
10 |
11 | ```php
12 | public function getAppId(): string
13 | ```
14 |
15 | Returns the app id.
16 |
17 | ### getAppSecret()
18 |
19 | ```php
20 | public function getAppSecret(): string
21 | ```
22 |
23 | Returns the app secret.
24 |
25 | ### getScopes()
26 |
27 | ```php
28 | public function getScopes(): array
29 | ```
30 |
31 | Returns an array with scopes.
32 |
33 | ### getFormattedScopes()
34 |
35 | ```php
36 | public function getFormattedScopes(): string
37 | ```
38 |
39 | Returns scopes formatted for requests.
40 |
41 | ### getCode()
42 |
43 | ```php
44 | public function getCode(): ?string
45 | ```
46 |
47 | Returns code needed for authorization with grant type `authorization_code`.
48 |
49 | ### getGrantType()
50 |
51 | ```php
52 | public function getGrantType(): string
53 | ```
54 |
55 | Returns a string with value one of: `authorization_code`, `client_credentials`, `password`.
56 |
57 | ### getUsername()
58 |
59 | ```php
60 | public function getUsername(): ?string
61 | ```
62 |
63 | Returns username needed for authorization with grant type `password`.
64 |
65 | ### getPassword()
66 |
67 | ```php
68 | public function getPassword(): ?string
69 | ```
70 |
71 | Returns password needed for authorization with grant type `password`.
72 |
73 | ### getAccessToken()
74 |
75 | ```php
76 | public function getAccessToken(): ?string
77 | ```
78 |
79 | Returns the value of an access token.
80 |
81 | ### getRefreshToken()
82 |
83 | ```php
84 | public function getRefreshToken(): ?string
85 | ```
86 |
87 | Returns the value of a refresh token.
88 |
89 | ### getForceGuzzle()
90 |
91 | ```php
92 | public function getForceGuzzle(): bool
93 | ```
94 |
95 | Returns a flag whether [GuzzleHttp](https://packagist.org/packages/guzzlehttp/guzzle) should be used instead of cURL.
96 |
--------------------------------------------------------------------------------
/docs/reference/Authorization.md:
--------------------------------------------------------------------------------
1 | # Authorization service for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\Services\Authorization
4 |
5 | The `\SumUp\Services\Authorization` service is responsible for getting a valid access token.
6 |
7 | ```php
8 | $authService = new \SumUp\Services\Authorization(
9 | \SumUp\HttpClients\SumUpHttpClientInterface $client,
10 | \SumUp\Application\ApplicationConfiguration $configuration
11 | );
12 | ```
13 |
14 | ## Instance Methods
15 |
16 | ### getToken()
17 |
18 | ```php
19 | public function getToken(): \SumUp\Authentication\AccessToken
20 | ```
21 |
22 | Returns a `\SumUp\Authentication\AccessToken` according to the initial configuration or throws an exception.
23 |
24 | ### getTokenByCode()
25 |
26 | ```php
27 | public function getTokenByCode(): \SumUp\Authentication\AccessToken
28 | ```
29 |
30 | Returns a `\SumUp\Authentication\AccessToken` according to the initial configuration or throws an exception.
31 |
32 | ### getTokenByClientCredentials()
33 |
34 | ```php
35 | public function getTokenByClientCredentials(): \SumUp\Authentication\AccessToken
36 | ```
37 |
38 | Returns a `\SumUp\Authentication\AccessToken` according to the initial configuration or throws an exception.
39 |
40 | ### getTokenByPassword()
41 |
42 | ```php
43 | public function getTokenByPassword(): \SumUp\Authentication\AccessToken
44 | ```
45 |
46 | Returns a `\SumUp\Authentication\AccessToken` according to the initial configuration or throws an exception.
47 |
48 | ### refreshToken()
49 |
50 | ```php
51 | public function refreshToken($refreshToken): \SumUp\Authentication\AccessToken
52 |
53 | ```
54 |
55 | Returns a `\SumUp\Authentication\AccessToken` using the provided the refresh token or throws an exception.
56 |
--------------------------------------------------------------------------------
/docs/reference/Checkouts.md:
--------------------------------------------------------------------------------
1 | # Checkouts service for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\Services\Checkouts
4 |
5 | The `\SumUp\Services\Checkouts` service is responsible for managing the checkouts - creating, listing, processing, deactivating.
6 |
7 | ```php
8 | $checkoutService = new \SumUp\Services\Checkouts(
9 | \SumUp\HttpClients\SumUpHttpClientInterface $client,
10 | \SumUp\Authentication\AccessToken $accessToken
11 | );
12 | ```
13 |
14 | ## Instance Methods
15 |
16 | ### create()
17 |
18 | Creates a new checkout.
19 |
20 | ```php
21 | public function create(
22 | float $amount,
23 | string $currency,
24 | string $checkoutRef,
25 | string $payToEmail,
26 | string $description = '',
27 | string $payFromEmail = null,
28 | string $returnURL = null
29 | ): \SumUp\HttpClients\Response
30 | ```
31 |
32 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
33 |
34 | ### findById()
35 |
36 | Searches for a checkout with particular `id`.
37 |
38 | ```php
39 | public function findById(string $checkoutId): \SumUp\HttpClients\Response
40 | ```
41 |
42 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
43 |
44 | ### findByReferenceId()
45 |
46 | Searches for a checkout with particular `checkout_reference_id`.
47 |
48 | ```php
49 | public function findByReferenceId(string $referenceId): \SumUp\HttpClients\Response
50 | ```
51 |
52 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
53 |
54 | ### delete()
55 |
56 | Deactivates a checkout with particular `checkout_reference_id`;
57 |
58 | ```php
59 | public function delete(string $checkoutId): \SumUp\HttpClients\Response
60 | ```
61 |
62 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
63 |
64 | ### pay()
65 |
66 | Processes a checkout with tokenized card for a customer.
67 |
68 | > **Note:** this is not the only way to process a checkout. For more information [read this guide](https://developer.sumup.com/docs/single-payment).
69 |
70 | ```php
71 | public function pay(
72 | string $checkoutId,
73 | string $customerId,
74 | string $cardToken,
75 | int $installments = 1
76 | ): \SumUp\HttpClients\Response
77 | ```
78 |
79 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
80 |
--------------------------------------------------------------------------------
/docs/reference/Custom.md:
--------------------------------------------------------------------------------
1 | # Custom service for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\Services\Custom
4 |
5 | The `\SumUp\Services\Custom` service should be used for the [endpoints](https://developer.sumup.com/rest-api/) that are not implemented by the SDK.
6 |
7 | ```php
8 | $customService = new \SumUp\Services\Custom(
9 | \SumUp\HttpClients\SumUpHttpClientInterface $client,
10 | \SumUp\Authentication\AccessToken $accessToken
11 | );
12 | ```
13 |
14 | ## Instance Methods
15 |
16 | ### request()
17 |
18 | ```php
19 | public function request(
20 | string $method,
21 | string $relativePath,
22 | array $payload = null
23 | ): \SumUp\HttpClients\Response
24 | ```
25 |
26 | `$method` is one of: `GET`, `POST`, `PUT`, `DELETE`.
27 |
28 | `$relativePath` is relative path to the resource. For example: `/v0.1/me`.
29 |
30 | `$payload` is *optional* but if you provide it it have to be an associative array with the data needed for that particular endpoint.
31 |
--------------------------------------------------------------------------------
/docs/reference/Customers.md:
--------------------------------------------------------------------------------
1 | # Customers service for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\Services\Customers
4 |
5 | The `\SumUp\Services\Customers` is responsible for managing customers and assigning payment instruments to them (if you have that functionality enabled).
6 |
7 | ```php
8 | $customerService = new \SumUp\Services\Customers(
9 | \SumUp\HttpClients\SumUpHttpClientInterface $client,
10 | \SumUp\Authentication\AccessToken $accessToken
11 | );
12 | ```
13 |
14 | ## Instance Methods
15 |
16 | ### create()
17 |
18 | Creates a new customer.
19 |
20 | ```php
21 | public function create(
22 | string $customerId,
23 | array $customerDetails = [],
24 | array $customerAddress = []
25 | ): \SumUp\HttpClients\Response
26 | ```
27 |
28 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
29 |
30 | ### update()
31 |
32 | Updates information about a customer.
33 |
34 | ```php
35 | public function update(
36 | string $customerId,
37 | array $customerDetails = [],
38 | array $customerAddress = []
39 | ): \SumUp\HttpClients\Response
40 | ```
41 |
42 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
43 |
44 | ### get()
45 |
46 | Returns information about a particular customer.
47 |
48 | ```php
49 | public function get(string $customerId): \SumUp\HttpClients\Response
50 | ```
51 |
52 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
53 |
54 | ### getPaymentInstruments()
55 |
56 | Returns payment instruments assigned to that particular customer.
57 |
58 | ```php
59 | public function getPaymentInstruments(string $customerId): \SumUp\HttpClients\Response
60 | ```
61 |
62 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
63 |
64 | ### deletePaymentInstruments()
65 |
66 | Deactivates a payment instrument for a customer.
67 |
68 | ```php
69 | public function deletePaymentInstruments(
70 | string $customerId,
71 | string $cardToken
72 | ): \SumUp\HttpClients\Response
73 | ```
74 |
75 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
76 |
--------------------------------------------------------------------------------
/docs/reference/Merchant.md:
--------------------------------------------------------------------------------
1 | # Merchant service for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\Services\Merchant
4 |
5 | The `\SumUp\Services\Merchant` service is responsible for managing data about merchants.
6 |
7 | ```php
8 | $merchantService = new \SumUp\Services\Merchant(
9 | \SumUp\HttpClients\SumUpHttpClientInterface $client,
10 | \SumUp\Authentication\AccessToken $accessToken
11 | );
12 | ```
13 |
14 | ## Instance Methods
15 |
16 | ### getProfile()
17 |
18 | Returns information about the merchant's profile.
19 |
20 | ```php
21 | public function getProfile(): \SumUp\HttpClients\Response
22 | ```
23 |
24 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
25 |
26 | ### updateProfile()
27 |
28 | Updates merchant's profile.
29 |
30 | ```php
31 | public function updateProfile(array $data): \SumUp\HttpClients\Response
32 | ```
33 |
34 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
35 |
36 | ### getDoingBusinessAs()
37 |
38 | Returns doing-business-as profile.
39 |
40 | ```php
41 | public function getDoingBusinessAs(): \SumUp\HttpClients\Response
42 | ```
43 |
44 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
45 |
46 | ### updateDoingBusinessAs()
47 |
48 | Updates doing-business-as profile.
49 |
50 | ```php
51 | public function updateDoingBusinessAs(array $data): \SumUp\HttpClients\Response
52 | ```
53 |
54 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
55 |
--------------------------------------------------------------------------------
/docs/reference/Payouts.md:
--------------------------------------------------------------------------------
1 | # Payouts service for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\Services\Payouts
4 |
5 | The `\SumUp\Services\Payouts` service is responsible for getting information about payouts.
6 |
7 | ```php
8 | $payoutService = new \SumUp\Services\Payouts(
9 | \SumUp\HttpClients\SumUpHttpClientInterface $client,
10 | \SumUp\Authentication\AccessToken $accessToken
11 | );
12 | ```
13 |
14 | ## Instance Methods
15 |
16 | ### getPayouts()
17 |
18 | Returns information about payouts.
19 |
20 | ```php
21 | public function getPayouts(
22 | string $startDate,
23 | string $endDate,
24 | int $limit = 10,
25 | bool $descendingOrder = true,
26 | string $format = 'json'
27 | ): \SumUp\HttpClients\Response
28 | ```
29 |
30 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
31 |
32 | ### getTransactions()
33 |
34 | Returns information about payed out transactions.
35 |
36 | ```php
37 | public function getTransactions(
38 | string $startDate,
39 | string $endDate,
40 | int $limit = 10,
41 | boo $descendingOrder = true,
42 | string $format = 'json'
43 | ): \SumUp\HttpClients\Response
44 | ```
45 |
46 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
47 |
--------------------------------------------------------------------------------
/docs/reference/Response.md:
--------------------------------------------------------------------------------
1 | # Response for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\HttpClients\Response
4 |
5 | The `\SumUp\HttpClients\Response` object is the main object that is returned from every successful service call.
6 |
7 | ## Instance Methods
8 |
9 | ### getHttpResponseCode()
10 |
11 | ```php
12 | public function getHttpResponseCode(): int
13 | ```
14 |
15 | Returns the HTTP response code.
16 |
17 | ### getBody()
18 |
19 | ```php
20 | public function getBody(): mixed
21 | ```
22 |
23 | Returns different object according to the service's response.
24 |
--------------------------------------------------------------------------------
/docs/reference/SumUp.md:
--------------------------------------------------------------------------------
1 | # SumUp service for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\SumUp
4 |
5 | The `\SumUp\SumUp` service is the main entry point for the SDK. From it you can get an instance to every other service (this is the recommended way of using it).
6 |
7 | Every time when an instance of `\SumUp\SumUp` is created a call to SumUp's servers is made to acquire an access token. If don't need this you can pass configuration with an existing access token or a refresh token.
8 |
9 | ```php
10 | try {
11 | $sumup = new \SumUp\SumUp([
12 | 'app_id' => 'YOUR-CLIENT-ID',
13 | 'app_secret' => 'YOUR-CLIENT-SECRET',
14 | 'code' => 'YOUR-AUTHORIZATION-CODE'
15 | ]);
16 | } catch(\SumUp\Exceptions\SumUpSDKException $e) {
17 | echo 'SumUp SDK error: ' . $e->getMessage();
18 | }
19 | try {
20 | $checkoutService = $sumup->getCheckoutService();
21 | $checkoutResponse = $checkoutService->create(/* pass here the required arguments */);
22 | // use the variable $checkoutResponse
23 | } catch(\SumUp\Exceptions\SumUpSDKException $e) {
24 | echo 'SumUp SDK error: ' . $e->getMessage();
25 | }
26 | ```
27 |
28 | ## Configurations
29 |
30 | ```php
31 | $sumup = new \SumUp\SumUp([
32 | // 'config-name': 'config-value'
33 | ]);
34 | ```
35 |
36 | | Name | Description | Value | Default value | Required |
37 | |--- |--- |--- |--- |--- |
38 | |app_id | This is the client id that you receive after you [register](https://developer.sumup.com/docs/register-app) your application in SumUp | `string`| *No default value* | Yes |
39 | |app_secret | This is the client secret that corresponds to the client id | `string` | *No default value* | Yes |
40 | |grant_type | This indicates which authorization flow should be used to acquire OAuth token | One of: `authorization_code`, `client_credentials`, `password` | '`authorization_code`' | No |
41 | |scopes | This is an array with all the [authorization scopes](https://developer.sumup.com/docs/authorization#authorization-scopes) that you need for your application | `array` with possible values: `payments`, `transactions.history`, `user.app-settings`, `user.profile_readonly`, `user.profile`, `user.subaccounts`, `user.payout-settings`, `balance`, `products` | `['payments', 'transactions.history', 'user.app-settings', 'user.profile_readonly']` | No |
42 | |code | This is the code returned at the last step from [authorization code flow](https://developer.sumup.com/docs/authorization#authorization-flows) | `string` | `null` | Conditional (required only if `grant_type => 'authorization_code'`) |
43 | |username | This is your SumUp's username if you want to use password authorization flow | `string` | `null` | Conditional (required only if `grant_type => 'password'`) |
44 | |password | This is your SumUp's password if you want to use password authorization flow | `string` | `null` | Conditional (required only if `grant_type => 'password'`) |
45 | |access_token | This is the value of a valid access token that is acquired through other methods. It is used if you don't want to request new access token | `string` | `null` | No |
46 | |refresh_token | This is the refresh token through which can be requested new access token | `string` | `null` | No |
47 | |use_guzzlehttp_over_curl | This is a configuration whether to use GuzzleHttp if both GuzzleHttp library and cURL module are installed. | `bool` | `false` | No |
48 |
49 | ## Instance Methods
50 |
51 | ### getAccessToken()
52 |
53 | ```php
54 | public function getAccessToken(): \SumUp\Authentication\AccessToken
55 | ```
56 |
57 | Returns a `\SumUp\Authentication\AccessToken` object.
58 |
59 | ### refreshToken()
60 |
61 | ```php
62 | public function refreshToken(string $refreshToken = null): \SumUp\Authentication\AccessToken
63 | ```
64 |
65 | Returns a `\SumUp\Authentication\AccessToken` or throws an exception.
66 |
67 | ### getAuthorizationService()
68 |
69 | ```php
70 | public function getAuthorizationService(\SumUp\Application\ApplicationConfigurationInterface $config = null): \SumUp\Services\Authorization
71 | ```
72 |
73 | Returns an instance of `\SumUp\Services\Authorization`.
74 |
75 | ### getCheckoutService()
76 |
77 | ```php
78 | public function getCheckoutService(\SumUp\Application\ApplicationConfigurationInterface $config = null): \SumUp\Services\Checkouts
79 | ```
80 |
81 | Returns an instance of `\SumUp\Services\Checkouts`.
82 |
83 | ### getCustomerService()
84 |
85 | ```php
86 | public function getCustomerService(\SumUp\Application\ApplicationConfigurationInterface $config = null): \SumUp\Services\Customers
87 | ```
88 |
89 | Returns an instance of `\SumUp\Services\Customers`.
90 |
91 | ### getTransactionService()
92 |
93 | ```php
94 | public function getTransactionService(\SumUp\Application\ApplicationConfigurationInterface $config = null): \SumUp\Services\Transactions
95 | ```
96 |
97 | Returns an instance of `\SumUp\Services\Transactions`.
98 |
99 | ### getMerchantService()
100 |
101 | ```php
102 | public function getMerchantService(\SumUp\Application\ApplicationConfigurationInterface $config = null): \SumUp\Services\Merchant
103 | ```
104 |
105 | Returns an instance of `\SumUp\Services\Merchant`.
106 |
107 | ### getPayoutService()
108 |
109 | ```php
110 | public function getPayoutService(\SumUp\Application\ApplicationConfigurationInterface $config = null): \SumUp\Services\Payouts
111 | ```
112 |
113 | Returns an instance of `\SumUp\Services\Payouts`.
114 |
115 | ### getCustomService()
116 |
117 | ```php
118 | public function getCustomService(\SumUp\Application\ApplicationConfigurationInterface $config = null): \SumUp\Services\Custom
119 | ```
120 |
121 | Returns an instance of `\SumUp\Services\Custom`.
122 |
--------------------------------------------------------------------------------
/docs/reference/SumUpArgumentException.md:
--------------------------------------------------------------------------------
1 | # SumUpArgumentException for the SumUp Ecommerce SDK for PHP
2 |
3 | Represents an exception thrown by any service in the SDK.
4 |
5 | ## \SumUp\Exceptions\SumUpArgumentException
6 |
7 | A `SumUpArgumentException` is thrown when there is a wrong parameter passed to a SDK method.
8 |
9 | ## Instance Methods
10 |
11 | `SumUpArgumentException` extends from the base `\SumUp\Exceptions\SumUpSDKException` class, so `getCode()` and `getMessage()` are available by default.
12 |
--------------------------------------------------------------------------------
/docs/reference/SumUpAuthenticationException.md:
--------------------------------------------------------------------------------
1 | # SumUpAuthenticationException for the SumUp Ecommerce SDK for PHP
2 |
3 | Represents an exception thrown by any service in the SDK.
4 |
5 | ## \SumUp\Exceptions\SumUpAuthenticationException
6 |
7 | A `SumUpAuthenticationException` is thrown when there are problems with the authentication. For example if the OAuth token is invalid or expired.
8 |
9 | ## Instance Methods
10 |
11 | `SumUpAuthenticationException` extends from the base `\SumUp\Exceptions\SumUpSDKException` class, so `getCode()` and `getMessage()` are available by default.
12 |
--------------------------------------------------------------------------------
/docs/reference/SumUpConfigurationException.md:
--------------------------------------------------------------------------------
1 | # SumUpConfigurationException for the SumUp Ecommerce SDK for PHP
2 |
3 | Represents an exception thrown by any service in the SDK.
4 |
5 | ## \SumUp\Exceptions\SumUpConfigurationException
6 |
7 | A `SumUpConfigurationException` is thrown when there is a problem with some configuration parameters mostly when initializing the main `\SumUp\SumUp` instance.
8 |
9 | > **Note:** This exception is helpful during development but in most cases there is no need to be handled for production code.
10 |
11 | ## Instance Methods
12 |
13 | `SumUpConfigurationException` extends from the base `\SumUp\Exceptions\SumUpSDKException` class, so `getCode()` and `getMessage()` are available by default.
14 |
--------------------------------------------------------------------------------
/docs/reference/SumUpConnectionException.md:
--------------------------------------------------------------------------------
1 | # SumUpConnectionException for the SumUp Ecommerce SDK for PHP
2 |
3 | Represents an exception thrown by any service in the SDK.
4 |
5 | ## \SumUp\Exceptions\SumUpConnectionException
6 |
7 | A `SumUpConnectionException` is thrown when there are problems communicating with SumUp's servers. For example if you are experiencing bad or no connectivity to the Internet.
8 |
9 | ## Instance Methods
10 |
11 | `SumUpConnectionException` extends from the base `\SumUp\Exceptions\SumUpSDKException` class, so `getCode()` and `getMessage()` are available by default.
12 |
--------------------------------------------------------------------------------
/docs/reference/SumUpResponseException.md:
--------------------------------------------------------------------------------
1 | # SumUpResponseException for the SumUp Ecommerce SDK for PHP
2 |
3 | Represents an exception thrown by any service in the SDK.
4 |
5 | ## \SumUp\Exceptions\SumUpResponseException
6 |
7 | A `SumUpResponseException` is thrown when there are 4xx http errors. For example if there is an error `404 Not Found`.
8 |
9 | ## Instance Methods
10 |
11 | `SumUpResponseException` extends from the base `\SumUp\Exceptions\SumUpSDKException` class, so `getCode()` and `getMessage()` are available by default.
12 |
--------------------------------------------------------------------------------
/docs/reference/SumUpSDKException.md:
--------------------------------------------------------------------------------
1 | # SumUpSDKException for the SumUp Ecommerce SDK for PHP
2 |
3 | Represents an exception thrown by the SDK.
4 |
5 | ## \SumUp\Exceptions\SumUpSDKException
6 |
7 | A `\SumUpSDKException` is thrown when something goes wrong. For example if there is a network problem or if your access token has expired.
8 |
9 | This is the basic exception that every other exception in the SDK inherits from.
10 |
11 | ## Instance Methods
12 |
13 | `SumUpSDKException` extends from the base `\Exception` class, so `getCode()` and `getMessage()` are available by default.
14 |
--------------------------------------------------------------------------------
/docs/reference/SumUpServerException.md:
--------------------------------------------------------------------------------
1 | # SumUpServerException for the SumUp Ecommerce SDK for PHP
2 |
3 | Represents an exception thrown by any service in the SDK.
4 |
5 | ## \SumUp\Exceptions\SumUpServerException
6 |
7 | A `SumUpServerException` is thrown when there are 5xx http errors. For example if there is an error `500 Internal Server Error`.
8 |
9 | ## Instance Methods
10 |
11 | `SumUpServerException` extends from the base `\SumUp\Exceptions\SumUpSDKException` class, so `getCode()` and `getMessage()` are available by default.
12 |
--------------------------------------------------------------------------------
/docs/reference/SumUpValidationException.md:
--------------------------------------------------------------------------------
1 | # SumUpValidationException for the SumUp Ecommerce SDK for PHP
2 |
3 | Represents an exception thrown by any service in the SDK.
4 |
5 | ## \SumUp\Exceptions\SumUpValidationException
6 |
7 | A `SumUpValidationException` is thrown when there are values sent to the server that don't comply with the server's validations.
8 |
9 | ## Instance Methods
10 |
11 | `SumUpValidationException` extends from the base `\SumUp\Exceptions\SumUpSDKException` class, so `getCode()` and `getMessage()` are available by default.
12 |
13 | It also has a method `getInvalidFields()` that returns an array with all the incorrect fields.
14 |
--------------------------------------------------------------------------------
/docs/reference/Transactions.md:
--------------------------------------------------------------------------------
1 | # Transactions service for the SumUp Ecommerce SDK for PHP
2 |
3 | ## \SumUp\Services\Transactions
4 |
5 | The `\SumUp\Services\Transactions` service is responsible for managing transactions: getting transactions, getting transactions history, making refunds, getting receipts.
6 |
7 | ```php
8 | $transactionService = new \SumUp\Services\Transactions(
9 | \SumUp\HttpClients\SumUpHttpClientInterface $client,
10 | \SumUp\Authentication\AccessToken $accessToken
11 | );
12 | ```
13 |
14 | ## Instance Methods
15 |
16 | ### findById()
17 |
18 | Searches for a transaction by `id`.
19 |
20 | ```php
21 | public function findById(string $transactionId): \SumUp\HttpClients\Response
22 | ```
23 |
24 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
25 |
26 | ### findByInternalId()
27 |
28 | Searches for a transaction by `internal_id`.
29 |
30 | ```php
31 | public function findByInternalId(string $internalId): \SumUp\HttpClients\Response
32 | ```
33 |
34 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
35 |
36 |
37 |
38 |
39 | ### findByForeignId()
40 |
41 | Searches for a transaction by `foreign transaction id`.
42 |
43 | ```php
44 | public function findByForeignId(string $foreignId): \SumUp\HttpClients\Response
45 | ```
46 |
47 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
48 |
49 |
50 |
51 |
52 | ### findByTransactionCode()
53 |
54 | Searches for a transaction by `transaction_code`.
55 |
56 | ```php
57 | public function findByTransactionCode(string $transactionCode): \SumUp\HttpClients\Response
58 | ```
59 |
60 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
61 |
62 | ### getTransactionHistory()
63 |
64 | Returns a list of all transactions according to the provided filter.
65 |
66 | ```php
67 | public function getTransactionHistory(array $filters = []): \SumUp\HttpClients\Response
68 | ```
69 |
70 | Available `filters` are:
71 |
72 | | Key | Type | Default value |
73 | |--- |--- |--- |
74 | | `order` | String | `ascending`. |
75 | | `limit` | Integer | 10 |
76 | | `user_id` | String | `null` |
77 | | `users ` | Array | `[]` |
78 | | `statuses` | Array | `[]` |
79 | | `payment_types` | Array | `[]` |
80 | | `types` | Array | `[]` |
81 | | `changes_since` | String\ | `null` |
82 | | `newest_time` | String\ | `null` |
83 | | `newest_ref` | String | `null` |
84 | | `oldest_time` | String\ | `null` |
85 | | `oldest_ref` | String | `null` |
86 |
87 | > **Note:** for more information about the filters read the [API documentation](https://developer.sumup.com/rest-api/#tag/Transactions).
88 |
89 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
90 |
91 | ### refund()
92 |
93 | Refunds a transaction partially or fully depending on the `amount`.
94 |
95 | ```php
96 | public function refund(string $transactionId, float $amount = null): \SumUp\HttpClients\Response
97 | ```
98 |
99 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
100 |
101 | ### getReceipt()
102 |
103 | Returns receipt data about a transaction.
104 |
105 | ```php
106 | public function getReceipt(string $transactionId, string $merchantId): \SumUp\HttpClients\Response
107 | ```
108 |
109 | Returns a `\SumUp\HttpClients\Response` or throws an exception.
110 |
--------------------------------------------------------------------------------
/examples/simple.php:
--------------------------------------------------------------------------------
1 | getenv('SUMUP_API_KEY'),
10 | ]);
11 |
12 | $dba = $sumup->getMerchantService()->getDoingBusinessAs();
13 | print_r($dba->getBody());
14 |
--------------------------------------------------------------------------------
/src/SumUp/Application/ApplicationConfiguration.php:
--------------------------------------------------------------------------------
1 | null,
126 | 'app_id' => null,
127 | 'app_secret' => null,
128 | 'grant_type' => 'authorization_code',
129 | 'base_uri' => 'https://api.sumup.com',
130 | 'scopes' => [],
131 | 'code' => null,
132 | 'access_token' => null,
133 | 'refresh_token' => null,
134 | 'username' => null,
135 | 'password' => null,
136 | 'use_guzzlehttp_over_curl' => false,
137 | 'custom_headers' => []
138 | ], $config);
139 |
140 | $this->apiKey = $config['api_key'];
141 | $this->setAppId($config['app_id']);
142 | $this->setAppSecret($config['app_secret']);
143 | $this->setScopes($config['scopes']);
144 | $this->setGrantType($config['grant_type']);
145 | $this->baseURL = $config['base_uri'];
146 | $this->username = $config['username'];
147 | $this->password = $config['password'];
148 | $this->code = $config['code'];
149 | $this->accessToken = $config['access_token'];
150 | $this->refreshToken = $config['refresh_token'];
151 | $this->setForceGuzzle($config['use_guzzlehttp_over_curl']);
152 | $this->setCustomHeaders($config['custom_headers']);
153 | }
154 |
155 | /**
156 | * Returns the client ID.
157 | *
158 | * @return string
159 | */
160 | public function getAppId()
161 | {
162 | return $this->appId;
163 | }
164 |
165 | /**
166 | * Returns the client secret.
167 | *
168 | * @return string
169 | */
170 | public function getAppSecret()
171 | {
172 | return $this->appSecret;
173 | }
174 |
175 | /**
176 | * Returns the scopes.
177 | *
178 | * @return array
179 | */
180 | public function getScopes()
181 | {
182 | return $this->scopes;
183 | }
184 |
185 | /**
186 | * Returns the scopes formatted as they should appear in the request.
187 | *
188 | * @return string
189 | */
190 | public function getFormattedScopes()
191 | {
192 | return implode(' ', $this->scopes);
193 | }
194 |
195 | /**
196 | * Returns the base URL of the SumUp API.
197 | *
198 | * @return string
199 | */
200 | public function getBaseURL()
201 | {
202 | return $this->baseURL;
203 | }
204 |
205 | /**
206 | * Returns authorization code.
207 | *
208 | * @return null|string
209 | */
210 | public function getCode()
211 | {
212 | return $this->code;
213 | }
214 |
215 | /**
216 | * Returns grant type.
217 | *
218 | * @return string;
219 | */
220 | public function getGrantType()
221 | {
222 | return $this->grantType;
223 | }
224 |
225 | /**
226 | * Returns merchant's username.
227 | *
228 | * @return null|string
229 | */
230 | public function getUsername()
231 | {
232 | return $this->username;
233 | }
234 |
235 | /**
236 | * Returns merchant's password.
237 | *
238 | * @return null|string
239 | */
240 | public function getPassword()
241 | {
242 | return $this->password;
243 | }
244 |
245 | /**
246 | * Returns initial access token.
247 | *
248 | * @return null|string
249 | */
250 | public function getAccessToken()
251 | {
252 | return $this->accessToken;
253 | }
254 |
255 | /**
256 | * Returns initial refresh token.
257 | *
258 | * @return null|string
259 | */
260 | public function getRefreshToken()
261 | {
262 | return $this->refreshToken;
263 | }
264 |
265 | /**
266 | * Returns the flag whether to use GuzzleHttp.
267 | *
268 | * @return bool
269 | */
270 | public function getForceGuzzle()
271 | {
272 | return $this->forceGuzzle;
273 | }
274 |
275 | /**
276 | * Returns associative array with custom headers.
277 | *
278 | * @return array
279 | */
280 | public function getCustomHeaders()
281 | {
282 | return $this->customHeaders;
283 | }
284 |
285 | /**
286 | * Returns the API key if set.
287 | *
288 | * @return string|null
289 | */
290 | public function getApiKey()
291 | {
292 | return $this->apiKey;
293 | }
294 |
295 | /**
296 | * Set application ID.
297 | *
298 | * @param string $appId
299 | *
300 | * @throws SumUpConfigurationException
301 | */
302 | protected function setAppId($appId)
303 | {
304 | if (empty($appId) && empty($this->apiKey)) {
305 | throw new SumUpConfigurationException('Missing mandatory parameter app_id or api_key');
306 | }
307 | $this->appId = $appId;
308 | }
309 |
310 | /**
311 | * Set application secret.
312 | *
313 | * @param string $appSecret
314 | *
315 | * @throws SumUpConfigurationException
316 | */
317 | protected function setAppSecret($appSecret)
318 | {
319 | if (empty($appSecret) && empty($this->apiKey)) {
320 | throw new SumUpConfigurationException('Missing mandatory parameter app_secret or api_key');
321 | }
322 | $this->appSecret = $appSecret;
323 | }
324 |
325 | /**
326 | * Set the authorization grant type.
327 | *
328 | * @param array $grantType
329 | *
330 | * @throws SumUpConfigurationException
331 | */
332 | protected function setGrantType($grantType)
333 | {
334 | if (!in_array($grantType, $this::GRANT_TYPES)) {
335 | throw new SumUpConfigurationException('Invalid parameter for "grant_type". Allowed values are: ' . implode($this::GRANT_TYPES, ' | ') . '.');
336 | }
337 | $this->grantType = $grantType;
338 | }
339 |
340 | /**
341 | * Set the scopes and always include the default ones.
342 | *
343 | * @param array $scopes
344 | */
345 | protected function setScopes(array $scopes = [])
346 | {
347 | $this->scopes = array_unique(array_merge($this::DEFAULT_SCOPES, $scopes), SORT_REGULAR);
348 | ;
349 | }
350 |
351 | /**
352 | * Set the flag whether to use GuzzleHttp.
353 | *
354 | * @param bool $forceGuzzle
355 | *
356 | * @throws SumUpConfigurationException
357 | */
358 | protected function setForceGuzzle($forceGuzzle)
359 | {
360 | if (!is_bool($forceGuzzle)) {
361 | throw new SumUpConfigurationException('Invalid value for boolean parameter use_guzzlehttp_over_curl.');
362 | }
363 | $this->forceGuzzle = $forceGuzzle;
364 | }
365 |
366 | /**
367 | * Set the associative array with custom headers.
368 | *
369 | * @param array $customHeaders
370 | */
371 | public function setCustomHeaders($customHeaders)
372 | {
373 | $this->customHeaders = is_array($customHeaders) ? $customHeaders : [];
374 | }
375 | }
376 |
--------------------------------------------------------------------------------
/src/SumUp/Application/ApplicationConfigurationInterface.php:
--------------------------------------------------------------------------------
1 | value = $value;
60 | }
61 | if ($type) {
62 | $this->type = $type;
63 | }
64 | if ($expiresIn) {
65 | $this->expiresIn = $expiresIn;
66 | }
67 | if ($scope) {
68 | $this->scope = $scope;
69 | }
70 | if ($refreshToken) {
71 | $this->refreshToken = $refreshToken;
72 | }
73 | }
74 |
75 | /**
76 | * Returns the access token.
77 | *
78 | * @return string
79 | */
80 | public function getValue()
81 | {
82 | return $this->value;
83 | }
84 |
85 | /**
86 | * Returns the type of the access token.
87 | *
88 | * @return string
89 | */
90 | public function getType()
91 | {
92 | return $this->type;
93 | }
94 |
95 | /**
96 | * Returns the total number of seconds that the token will be valid.
97 | *
98 | * @return int
99 | */
100 | public function getExpiresIn()
101 | {
102 | return $this->expiresIn;
103 | }
104 |
105 | /**
106 | * Returns the scopes for the current access token.
107 | *
108 | * @return array
109 | */
110 | public function getScopes()
111 | {
112 | return $this->scope;
113 | }
114 |
115 | /**
116 | * Returns the refresh token if any.
117 | *
118 | * @return null|string
119 | */
120 | public function getRefreshToken()
121 | {
122 | return $this->refreshToken;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/SumUp/Exceptions/SumUpArgumentException.php:
--------------------------------------------------------------------------------
1 | fields = $fields;
30 | $message = self::VALIDATION_ERROR_BASE . implode(', ', $fields);
31 | parent::__construct($message, $code, $previous);
32 | }
33 |
34 | /**
35 | * Returns the fields that failed the server validation.
36 | *
37 | * @return array
38 | */
39 | public function getInvalidFields()
40 | {
41 | return $this->fields;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/SumUp/HttpClients/HttpClientsFactory.php:
--------------------------------------------------------------------------------
1 | getBaseURL(), $appConfig->getForceGuzzle(), $appConfig->getCustomHeaders());
36 | }
37 |
38 | /**
39 | * Detect the default HTTP client.
40 | *
41 | * @param string $baseURL
42 | * @param bool $forceUseGuzzle
43 | *
44 | * @return SumUpCUrlClient|SumUpGuzzleHttpClient
45 | *
46 | * @throws SumUpConfigurationException
47 | */
48 | private static function detectDefaultClient($baseURL, $forceUseGuzzle, $customHeaders)
49 | {
50 | if (extension_loaded('curl') && !$forceUseGuzzle) {
51 | return new SumUpCUrlClient($baseURL, $customHeaders);
52 | }
53 | if (class_exists('GuzzleHttp\Client')) {
54 | return new SumUpGuzzleHttpClient($baseURL, $customHeaders);
55 | }
56 |
57 | throw new SumUpConfigurationException('No default http client found. Please install cURL or GuzzleHttp.');
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/SumUp/HttpClients/Response.php:
--------------------------------------------------------------------------------
1 | httpResponseCode = $httpResponseCode;
47 | $this->body = $body;
48 | $this->parseResponseForErrors();
49 | }
50 |
51 | /**
52 | * Get HTTP response code.
53 | *
54 | * @return number
55 | */
56 | public function getHttpResponseCode()
57 | {
58 | return $this->httpResponseCode;
59 | }
60 |
61 | /**
62 | * Get the response body.
63 | *
64 | * @return array|mixed
65 | */
66 | public function getBody()
67 | {
68 | return $this->body;
69 | }
70 |
71 | /**
72 | * Parses the response for containing errors.
73 | *
74 | * @return mixed
75 | *
76 | * @throws SumUpAuthenticationException
77 | * @throws SumUpResponseException
78 | * @throws SumUpValidationException
79 | * @throws SumUpServerException
80 | * @throws \SumUp\Exceptions\SumUpSDKException
81 | */
82 | protected function parseResponseForErrors()
83 | {
84 | if (isset($this->body->error_code) && $this->body->error_code === 'NOT_AUTHORIZED') {
85 | throw new SumUpAuthenticationException($this->body->error_message, $this->httpResponseCode);
86 | }
87 | if (isset($this->body->error_code) && ($this->body->error_code === 'MISSING' || $this->body->error_code === 'INVALID')) {
88 | throw new SumUpValidationException([$this->body->param], $this->httpResponseCode);
89 | }
90 | if (is_array($this->body) && sizeof($this->body) > 0 && isset($this->body[0]->error_code) && ($this->body[0]->error_code === 'MISSING' || $this->body[0]->error_code === 'INVALID')) {
91 | $invalidFields = [];
92 | foreach ($this->body as $errorObject) {
93 | $invalidFields[] = $errorObject->param;
94 | }
95 | throw new SumUpValidationException($invalidFields, $this->httpResponseCode);
96 | }
97 | if ($this->httpResponseCode >= 500) {
98 | $message = $this->parseErrorMessage('Server error');
99 | throw new SumUpServerException($message, $this->httpResponseCode);
100 | }
101 | if ($this->httpResponseCode >= 400) {
102 | $message = $this->parseErrorMessage('Client error');
103 | throw new SumUpResponseException($message, $this->httpResponseCode);
104 | }
105 | }
106 |
107 | /**
108 | * Return error message.
109 | *
110 | * @param string $defaultMessage
111 | *
112 | * @return string
113 | */
114 | protected function parseErrorMessage($defaultMessage = '')
115 | {
116 | if (is_null($this->body)) {
117 | return $defaultMessage;
118 | }
119 |
120 | if (isset($this->body->message)) {
121 | return $this->body->message;
122 | }
123 |
124 | if (isset($this->body->error_message)) {
125 | return $this->body->error_message;
126 | }
127 |
128 | return $defaultMessage;
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/SumUp/HttpClients/SumUpCUrlClient.php:
--------------------------------------------------------------------------------
1 | baseUrl = $baseUrl;
38 | $this->customHeaders = $customHeaders;
39 | }
40 |
41 | /**
42 | * @param string $method The request method.
43 | * @param string $url The endpoint to send the request to.
44 | * @param array $body The body of the request.
45 | * @param array $headers The headers of the request.
46 | *
47 | * @return Response
48 | *
49 | * @throws SumUpConnectionException
50 | * @throws \SumUp\Exceptions\SumUpResponseException
51 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
52 | * @throws \SumUp\Exceptions\SumUpValidationException
53 | * @throws SumUpSDKException
54 | */
55 | public function send($method, $url, $body, $headers = [])
56 | {
57 | $reqHeaders = array_merge($headers, $this->customHeaders);
58 | $ch = curl_init();
59 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
60 | curl_setopt($ch, CURLOPT_URL, $this->baseUrl . $url);
61 | curl_setopt($ch, CURLOPT_HTTPHEADER, $this->formatHeaders($reqHeaders));
62 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
63 | if (!empty($body)) {
64 | $payload = json_encode($body);
65 | curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
66 | }
67 |
68 | $response = curl_exec($ch);
69 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
70 |
71 | $error = curl_error($ch);
72 | if ($error) {
73 | curl_close($ch);
74 | throw new SumUpConnectionException($error, $code);
75 | }
76 |
77 | curl_close($ch);
78 | return new Response($code, $this->parseBody($response));
79 | }
80 |
81 | /**
82 | * Format the headers to be compatible with cURL.
83 | *
84 | * @param array|null $headers
85 | *
86 | * @return array
87 | */
88 | private function formatHeaders($headers = null)
89 | {
90 | if (count($headers) == 0) {
91 | return $headers;
92 | }
93 |
94 | $keys = array_keys($headers);
95 | $formattedHeaders = [];
96 | foreach ($keys as $key) {
97 | $formattedHeaders[] = $key . ': ' . $headers[$key];
98 | }
99 | return $formattedHeaders;
100 | }
101 |
102 | /**
103 | * Returns JSON encoded the response's body if it is of JSON type.
104 | *
105 | * @param $response
106 | *
107 | * @return mixed
108 | */
109 | private function parseBody($response)
110 | {
111 | $jsonBody = json_decode($response);
112 | if (isset($jsonBody)) {
113 | return $jsonBody;
114 | }
115 | return $response;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/SumUp/HttpClients/SumUpGuzzleHttpClient.php:
--------------------------------------------------------------------------------
1 | guzzleClient = new Client(['base_uri' => $baseUrl]);
44 | $this->customHeaders = $customHeaders;
45 | }
46 |
47 | /**
48 | * @param string $method The request method.
49 | * @param string $url The endpoint to send the request to.
50 | * @param array $body The body of the request.
51 | * @param array $headers The headers of the request.
52 | *
53 | * @return Response
54 | *
55 | * @throws SumUpConnectionException
56 | * @throws SumUpServerException
57 | * @throws \SumUp\Exceptions\SumUpResponseException
58 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
59 | * @throws \SumUp\Exceptions\SumUpValidationException
60 | * @throws SumUpSDKException
61 | */
62 | public function send($method, $url, $body, $headers = [])
63 | {
64 | $options = [
65 | 'headers' => array_merge($headers, $this->customHeaders),
66 | 'json' => $body
67 | ];
68 |
69 | $request = new Request($method, $url);
70 |
71 | try {
72 | $response = $this->guzzleClient->send($request, $options);
73 | } catch (ConnectException $e) {
74 | throw new SumUpConnectionException($e->getMessage(), $e->getCode(), $e->getPrevious());
75 | } catch (ClientException $e) {
76 | $response = $e->getResponse();
77 | $body = $this->parseBody($response);
78 | return new Response($response->getStatusCode(), $body);
79 | } catch (ServerException $e) {
80 | $response = $e->getResponse();
81 | $body = $this->parseBody($response);
82 | if (isset($body) && isset($body->message)) {
83 | $message = $body->message;
84 | } else {
85 | $message = $body;
86 | }
87 | throw new SumUpServerException($message, $e->getCode(), $e->getPrevious());
88 | } catch (\GuzzleHttp\Exception\GuzzleException $e) {
89 | throw new SumUpSDKException($e->getMessage(), $e->getCode(), $e->getPrevious());
90 | } catch (\Exception $e) {
91 | throw new SumUpSDKException($e->getMessage(), $e->getCode(), $e->getPrevious());
92 | }
93 | $body = $this->parseBody($response);
94 | return new Response($response->getStatusCode(), $body);
95 | }
96 |
97 | /**
98 | * Returns JSON encoded the response's body if it is of JSON type.
99 | *
100 | * @param $response
101 | *
102 | * @return mixed
103 | */
104 | private function parseBody($response)
105 | {
106 | $jsonBody = json_decode($response->getBody());
107 | if (isset($jsonBody)) {
108 | return $jsonBody;
109 | }
110 | return $response->getBody();
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/SumUp/HttpClients/SumUpHttpClientInterface.php:
--------------------------------------------------------------------------------
1 | client = $client;
44 | $this->appConfig = $config;
45 | }
46 |
47 | /**
48 | * Returns an access token according to the grant_type.
49 | *
50 | * @return null|AccessToken
51 | *
52 | * @throws SumUpConfigurationException
53 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
54 | * @throws \SumUp\Exceptions\SumUpConnectionException
55 | * @throws \SumUp\Exceptions\SumUpResponseException
56 | * @throws \SumUp\Exceptions\SumUpSDKException
57 | */
58 | public function getToken()
59 | {
60 | if (!empty($this->appConfig->getApiKey())) {
61 | return new AccessToken(
62 | $this->appConfig->getApiKey(),
63 | 'Bearer',
64 | null,
65 | [],
66 | null
67 | );
68 | }
69 |
70 | $accessToken = null;
71 | if (!empty($this->appConfig->getAccessToken())) {
72 | $accessToken = new AccessToken(
73 | $this->appConfig->getAccessToken(),
74 | '',
75 | 0,
76 | $this->appConfig->getScopes(),
77 | $this->appConfig->getRefreshToken()
78 | );
79 | } elseif (!empty($this->appConfig->getRefreshToken())) {
80 | $accessToken = new AccessToken(
81 | '',
82 | '',
83 | 0,
84 | $this->appConfig->getScopes(),
85 | $this->appConfig->getRefreshToken()
86 | );
87 | } else {
88 | switch ($this->appConfig->getGrantType()) {
89 | case 'authorization_code':
90 | $accessToken = $this->getTokenByCode();
91 | break;
92 | case 'client_credentials':
93 | $accessToken = $this->getTokenByClientCredentials();
94 | break;
95 | case 'password':
96 | $accessToken = $this->getTokenByPassword();
97 | break;
98 | }
99 | }
100 | return $accessToken;
101 | }
102 |
103 | /**
104 | * Returns an access token for the grant type "authorization_code".
105 | *
106 | * @return AccessToken
107 | *
108 | * @throws \SumUp\Exceptions\SumUpConnectionException
109 | * @throws \SumUp\Exceptions\SumUpResponseException
110 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
111 | * @throws \SumUp\Exceptions\SumUpSDKException
112 | */
113 | public function getTokenByCode()
114 | {
115 | $payload = [
116 | 'grant_type' => 'authorization_code',
117 | 'client_id' => $this->appConfig->getAppId(),
118 | 'client_secret' => $this->appConfig->getAppSecret(),
119 | 'scope' => $this->appConfig->getFormattedScopes(),
120 | 'code' => $this->appConfig->getCode()
121 | ];
122 | $headers = Headers::getStandardHeaders();
123 | $response = $this->client->send('POST', '/token', $payload, $headers);
124 | $resBody = $response->getBody();
125 | $scopes = [];
126 | if (!empty($resBody->scope)) {
127 | $scopes = explode(' ', $resBody->scope);
128 | }
129 | return new AccessToken($resBody->access_token, $resBody->token_type, $resBody->expires_in, $scopes, $resBody->refresh_token);
130 | }
131 |
132 | /**
133 | * Returns an access token for the grant type "client_credentials".
134 | *
135 | * @return AccessToken
136 | *
137 | * @throws \SumUp\Exceptions\SumUpConnectionException
138 | * @throws \SumUp\Exceptions\SumUpResponseException
139 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
140 | * @throws \SumUp\Exceptions\SumUpSDKException
141 | */
142 | public function getTokenByClientCredentials()
143 | {
144 | $payload = [
145 | 'grant_type' => 'client_credentials',
146 | 'client_id' => $this->appConfig->getAppId(),
147 | 'client_secret' => $this->appConfig->getAppSecret(),
148 | 'scope' => $this->appConfig->getFormattedScopes()
149 | ];
150 | $headers = Headers::getStandardHeaders();
151 | $response = $this->client->send('POST', '/token', $payload, $headers);
152 | $resBody = $response->getBody();
153 | return new AccessToken($resBody->access_token, $resBody->token_type, $resBody->expires_in);
154 | }
155 |
156 | /**
157 | * Returns an access token for the grant type "password".
158 | *
159 | * @return AccessToken
160 | *
161 | * @throws SumUpConfigurationException
162 | * @throws \SumUp\Exceptions\SumUpConnectionException
163 | * @throws \SumUp\Exceptions\SumUpResponseException
164 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
165 | * @throws \SumUp\Exceptions\SumUpSDKException
166 | */
167 | public function getTokenByPassword()
168 | {
169 | if (empty($this->appConfig->getUsername())) {
170 | throw new SumUpConfigurationException(ExceptionMessages::getMissingParamMsg('username'));
171 | }
172 | if (empty($this->appConfig->getPassword())) {
173 | throw new SumUpConfigurationException(ExceptionMessages::getMissingParamMsg("password"));
174 | }
175 | $payload = [
176 | 'grant_type' => 'password',
177 | 'client_id' => $this->appConfig->getAppId(),
178 | 'client_secret' => $this->appConfig->getAppSecret(),
179 | 'scope' => $this->appConfig->getFormattedScopes(),
180 | 'username' => $this->appConfig->getUsername(),
181 | 'password' => $this->appConfig->getPassword()
182 | ];
183 | $headers = Headers::getStandardHeaders();
184 | $response = $this->client->send('POST', '/token', $payload, $headers);
185 | $resBody = $response->getBody();
186 | $scopes = [];
187 | if (!empty($resBody->scope)) {
188 | $scopes = explode(' ', $resBody->scope);
189 | }
190 | return new AccessToken($resBody->access_token, $resBody->token_type, $resBody->expires_in, $scopes, $resBody->refresh_token);
191 | }
192 |
193 | /**
194 | * Refresh access token.
195 | *
196 | * @param string $refreshToken
197 | *
198 | * @return AccessToken
199 | *
200 | * @throws SumUpArgumentException
201 | * @throws \SumUp\Exceptions\SumUpConnectionException
202 | * @throws \SumUp\Exceptions\SumUpResponseException
203 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
204 | * @throws \SumUp\Exceptions\SumUpSDKException
205 | */
206 | public function refreshToken($refreshToken)
207 | {
208 | if (empty($refreshToken)) {
209 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('refresh token'));
210 | }
211 | $payload = [
212 | 'grant_type' => 'refresh_token',
213 | 'client_id' => $this->appConfig->getAppId(),
214 | 'client_secret' => $this->appConfig->getAppSecret(),
215 | 'refresh_token' => $refreshToken,
216 | 'scope' => $this->appConfig->getFormattedScopes()
217 | ];
218 | $headers = Headers::getStandardHeaders();
219 | $response = $this->client->send('POST', '/token', $payload, $headers);
220 | $resBody = $response->getBody();
221 | $scopes = [];
222 | if (!empty($resBody->scope)) {
223 | $scopes = explode(' ', $resBody->scope);
224 | }
225 | return new AccessToken($resBody->access_token, $resBody->token_type, $resBody->expires_in, $scopes, $resBody->refresh_token);
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/src/SumUp/Services/Checkouts.php:
--------------------------------------------------------------------------------
1 | client = $client;
41 | $this->accessToken = $accessToken;
42 | }
43 |
44 | /**
45 | * Create new checkout.
46 | *
47 | * @param float $amount
48 | * @param string $currency
49 | * @param string $checkoutRef
50 | * @param string $payToEmail
51 | * @param string $description
52 | * @param null $payFromEmail
53 | * @param null $returnURL
54 | * @param null $redirectURL
55 | *
56 | * @return \SumUp\HttpClients\Response
57 | *
58 | * @throws SumUpArgumentException
59 | * @throws \SumUp\Exceptions\SumUpConnectionException
60 | * @throws \SumUp\Exceptions\SumUpResponseException
61 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
62 | * @throws \SumUp\Exceptions\SumUpSDKException
63 | */
64 | public function create($amount, $currency, $checkoutRef, $payToEmail, $description = '', $payFromEmail = null, $returnURL = null, $redirectURL = null)
65 | {
66 | if (empty($amount) || !is_numeric($amount)) {
67 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('amount'));
68 | }
69 | if (empty($currency)) {
70 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('currency'));
71 | }
72 | if (empty($checkoutRef)) {
73 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('checkout reference id'));
74 | }
75 | if (empty($payToEmail)) {
76 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('pay to email'));
77 | }
78 | $payload = [
79 | 'amount' => $amount,
80 | 'currency' => $currency,
81 | 'checkout_reference' => $checkoutRef,
82 | 'pay_to_email' => $payToEmail,
83 | 'description' => $description
84 | ];
85 | if (isset($payFromEmail)) {
86 | $payload['pay_from_email'] = $payFromEmail;
87 | }
88 | if (isset($returnURL)) {
89 | $payload['return_url'] = $returnURL;
90 | }
91 | if (isset($redirectURL)) {
92 | $payload['redirect_url'] = $redirectURL;
93 | }
94 | $path = '/v0.1/checkouts';
95 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
96 | return $this->client->send('POST', $path, $payload, $headers);
97 | }
98 |
99 | /**
100 | * Get single checkout by provided checkout ID.
101 | *
102 | * @param string $checkoutId
103 | *
104 | * @return \SumUp\HttpClients\Response
105 | *
106 | * @throws SumUpArgumentException
107 | * @throws \SumUp\Exceptions\SumUpConnectionException
108 | * @throws \SumUp\Exceptions\SumUpResponseException
109 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
110 | * @throws \SumUp\Exceptions\SumUpSDKException
111 | */
112 | public function findById($checkoutId)
113 | {
114 | if (empty($checkoutId)) {
115 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('checkout id'));
116 | }
117 | $path = '/v0.1/checkouts/' . $checkoutId;
118 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
119 | return $this->client->send('GET', $path, [], $headers);
120 | }
121 |
122 | /**
123 | * Get single checkout by provided checkout reference ID.
124 | *
125 | * @param string $referenceId
126 | *
127 | * @return \SumUp\HttpClients\Response
128 | *
129 | * @throws SumUpArgumentException
130 | * @throws \SumUp\Exceptions\SumUpConnectionException
131 | * @throws \SumUp\Exceptions\SumUpResponseException
132 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
133 | * @throws \SumUp\Exceptions\SumUpSDKException
134 | */
135 | public function findByReferenceId($referenceId)
136 | {
137 | if (empty($referenceId)) {
138 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('reference id'));
139 | }
140 | $path = '/v0.1/checkouts?checkout_reference=' . $referenceId;
141 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
142 | return $this->client->send('GET', $path, [], $headers);
143 | }
144 |
145 | /**
146 | * Delete a checkout.
147 | *
148 | * @param string $checkoutId
149 | *
150 | * @return \SumUp\HttpClients\Response
151 | *
152 | * @throws SumUpArgumentException
153 | * @throws \SumUp\Exceptions\SumUpConnectionException
154 | * @throws \SumUp\Exceptions\SumUpResponseException
155 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
156 | * @throws \SumUp\Exceptions\SumUpSDKException
157 | */
158 | public function delete($checkoutId)
159 | {
160 | if (empty($checkoutId)) {
161 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('checkout id'));
162 | }
163 | $path = '/v0.1/checkouts/' . $checkoutId;
164 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
165 | return $this->client->send('DELETE', $path, [], $headers);
166 | }
167 |
168 | /**
169 | * Pay a checkout with tokenized card.
170 | *
171 | * @param string $checkoutId
172 | * @param string $customerId
173 | * @param string $cardToken
174 | * @param int $installments
175 | *
176 | * @return \SumUp\HttpClients\Response
177 | *
178 | * @throws SumUpArgumentException
179 | * @throws \SumUp\Exceptions\SumUpConnectionException
180 | * @throws \SumUp\Exceptions\SumUpResponseException
181 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
182 | * @throws \SumUp\Exceptions\SumUpSDKException
183 | */
184 | public function pay($checkoutId, $customerId, $cardToken, $installments = 1)
185 | {
186 | if (empty($checkoutId)) {
187 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('checkout id'));
188 | }
189 | if (empty($customerId)) {
190 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id'));
191 | }
192 | if (empty($cardToken)) {
193 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('card token'));
194 | }
195 | if (empty($installments) || !is_int($installments)) {
196 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('installments'));
197 | }
198 | $payload = [
199 | 'payment_type' => 'card',
200 | 'customer_id' => $customerId,
201 | 'token' => $cardToken,
202 | 'installments' => $installments
203 | ];
204 | $path = '/v0.1/checkouts/' . $checkoutId;
205 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
206 | return $this->client->send('PUT', $path, $payload, $headers);
207 | }
208 | }
209 |
--------------------------------------------------------------------------------
/src/SumUp/Services/Custom.php:
--------------------------------------------------------------------------------
1 | client = $client;
45 | $this->accessToken = $accessToken;
46 | }
47 |
48 | /**
49 | * Make custom request.
50 | *
51 | * @param string $method
52 | * @param string $relativePath
53 | * @param array|null $payload
54 | *
55 | * @return mixed|\SumUp\HttpClients\Response
56 | *
57 | * @throws SumUpArgumentException
58 | * @throws \SumUp\Exceptions\SumUpConnectionException
59 | * @throws \SumUp\Exceptions\SumUpResponseException
60 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
61 | * @throws \SumUp\Exceptions\SumUpSDKException
62 | */
63 | public function request($method, $relativePath, $payload = null)
64 | {
65 | if (!in_array($method, $this::HTTP_METHODS)) {
66 | $message = "Not allowed method provided: $method. Allowed values: " . implode(', ', $this::HTTP_METHODS) . '.';
67 | throw new SumUpArgumentException($message);
68 | }
69 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
70 | return $this->client->send($method, $relativePath, $payload, $headers);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/SumUp/Services/Customers.php:
--------------------------------------------------------------------------------
1 | client = $client;
41 | $this->accessToken = $accessToken;
42 | }
43 |
44 | /**
45 | * Create new customer.
46 | *
47 | * @param $customerId
48 | * @param array $customerDetails
49 | * @param array $customerAddress
50 | *
51 | * @return \SumUp\HttpClients\Response
52 | *
53 | * @throws SumUpArgumentException
54 | * @throws \SumUp\Exceptions\SumUpConnectionException
55 | * @throws \SumUp\Exceptions\SumUpResponseException
56 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
57 | * @throws \SumUp\Exceptions\SumUpSDKException
58 | */
59 | public function create($customerId, array $customerDetails = [], array $customerAddress = [])
60 | {
61 | if (empty($customerId)) {
62 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id'));
63 | }
64 |
65 | $details = array_merge([
66 | 'first_name' => null,
67 | 'last_name' => null,
68 | 'email' => null,
69 | 'phone' => null
70 | ], $customerDetails);
71 | $details = array_filter($details);
72 |
73 | $address = array_merge([
74 | 'city' => null,
75 | 'country' => null,
76 | 'line1' => null,
77 | 'line2' => null,
78 | 'state' => null,
79 | 'postalCode' => null
80 | ], $customerAddress);
81 | $address = array_filter($address);
82 |
83 | if (sizeof($address) > 0) {
84 | $details['address'] = $address;
85 | }
86 |
87 | $payload = [
88 | 'customer_id' => $customerId,
89 | 'personal_details' => $details
90 | ];
91 | $path = '/v0.1/customers';
92 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
93 | return $this->client->send('POST', $path, $payload, $headers);
94 | }
95 |
96 | /**
97 | * Update existing customer.
98 | *
99 | * @param $customerId
100 | * @param array $customerDetails
101 | * @param array $customerAddress
102 | *
103 | * @return \SumUp\HttpClients\Response
104 | *
105 | * @throws SumUpArgumentException
106 | * @throws \SumUp\Exceptions\SumUpConnectionException
107 | * @throws \SumUp\Exceptions\SumUpResponseException
108 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
109 | * @throws \SumUp\Exceptions\SumUpSDKException
110 | */
111 | public function update($customerId, array $customerDetails = [], array $customerAddress = [])
112 | {
113 | if (empty($customerId)) {
114 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id'));
115 | }
116 |
117 | $details = array_merge([
118 | 'first_name' => null,
119 | 'last_name' => null,
120 | 'email' => null,
121 | 'phone' => null
122 | ], $customerDetails);
123 | $details = array_filter($details);
124 |
125 | $address = array_merge([
126 | 'city' => null,
127 | 'country' => null,
128 | 'line1' => null,
129 | 'line2' => null,
130 | 'state' => null,
131 | 'postalCode' => null
132 | ], $customerAddress);
133 | $address = array_filter($address);
134 |
135 | if (sizeof($address) > 0) {
136 | $details['address'] = $address;
137 | }
138 | $payload = [
139 | 'customer_id' => $customerId,
140 | 'personal_details' => $details
141 | ];
142 | $path = '/v0.1/customers/' . $customerId;
143 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
144 | return $this->client->send('PUT', $path, $payload, $headers);
145 | }
146 |
147 | /**
148 | * Get customer by ID.
149 | *
150 | * @param $customerId
151 | *
152 | * @return \SumUp\HttpClients\Response
153 | *
154 | * @throws SumUpArgumentException
155 | * @throws \SumUp\Exceptions\SumUpConnectionException
156 | * @throws \SumUp\Exceptions\SumUpResponseException
157 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
158 | * @throws \SumUp\Exceptions\SumUpSDKException
159 | */
160 | public function get($customerId)
161 | {
162 | if (empty($customerId)) {
163 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id'));
164 | }
165 | $path = '/v0.1/customers/' . $customerId;
166 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
167 | return $this->client->send('GET', $path, [], $headers);
168 | }
169 |
170 | /**
171 | * Get payment instruments for a customer.
172 | *
173 | * @param $customerId
174 | *
175 | * @return \SumUp\HttpClients\Response
176 | *
177 | * @throws SumUpArgumentException
178 | * @throws \SumUp\Exceptions\SumUpConnectionException
179 | * @throws \SumUp\Exceptions\SumUpResponseException
180 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
181 | * @throws \SumUp\Exceptions\SumUpSDKException
182 | */
183 | public function getPaymentInstruments($customerId)
184 | {
185 | if (empty($customerId)) {
186 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id'));
187 | }
188 | $path = '/v0.1/customers/' . $customerId . '/payment-instruments';
189 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
190 | return $this->client->send('GET', $path, [], $headers);
191 | }
192 |
193 | /**
194 | * Deactivate payment instrument for a customer.
195 | *
196 | * @param $customerId
197 | * @param $cardToken
198 | *
199 | * @return \SumUp\HttpClients\Response
200 | *
201 | * @throws SumUpArgumentException
202 | * @throws \SumUp\Exceptions\SumUpConnectionException
203 | * @throws \SumUp\Exceptions\SumUpResponseException
204 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
205 | * @throws \SumUp\Exceptions\SumUpSDKException
206 | */
207 | public function deletePaymentInstruments($customerId, $cardToken)
208 | {
209 | if (empty($customerId)) {
210 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('customer id'));
211 | }
212 | if (empty($cardToken)) {
213 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('card token'));
214 | }
215 | $path = '/v0.1/customers/' . $customerId . '/payment-instruments/' . $cardToken;
216 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
217 | return $this->client->send('DELETE', $path, [], $headers);
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/src/SumUp/Services/Merchant.php:
--------------------------------------------------------------------------------
1 | client = $client;
41 | $this->accessToken = $accessToken;
42 | }
43 |
44 | /**
45 | * Get merchant's profile.
46 | *
47 | * @return \SumUp\HttpClients\Response
48 | *
49 | * @throws \SumUp\Exceptions\SumUpConnectionException
50 | * @throws \SumUp\Exceptions\SumUpResponseException
51 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
52 | * @throws \SumUp\Exceptions\SumUpSDKException
53 | */
54 | public function getProfile()
55 | {
56 | $path = '/v0.1/me/merchant-profile';
57 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
58 | return $this->client->send('GET', $path, [], $headers);
59 | }
60 |
61 | /**
62 | * Update merchant's profile.
63 | *
64 | * @param array $data
65 | *
66 | * @return \SumUp\HttpClients\Response
67 | *
68 | * @throws SumUpArgumentException
69 | * @throws \SumUp\Exceptions\SumUpConnectionException
70 | * @throws \SumUp\Exceptions\SumUpResponseException
71 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
72 | * @throws \SumUp\Exceptions\SumUpSDKException
73 | */
74 | public function updateProfile(array $data)
75 | {
76 | if (empty($data)) {
77 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('payload data'));
78 | }
79 | $path = '/v0.1/me/merchant-profile';
80 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
81 | return $this->client->send('PUT', $path, $data, $headers);
82 | }
83 |
84 | /**
85 | * Get data for doing business as.
86 | *
87 | * @return \SumUp\HttpClients\Response
88 | *
89 | * @throws \SumUp\Exceptions\SumUpConnectionException
90 | * @throws \SumUp\Exceptions\SumUpResponseException
91 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
92 | * @throws \SumUp\Exceptions\SumUpSDKException
93 | */
94 | public function getDoingBusinessAs()
95 | {
96 | $path = '/v0.1/me/merchant-profile/doing-business-as';
97 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
98 | return $this->client->send('GET', $path, [], $headers);
99 | }
100 |
101 | /**
102 | * Update data for doing business as.
103 | *
104 | * @param array $data
105 | *
106 | * @return \SumUp\HttpClients\Response
107 | *
108 | * @throws SumUpArgumentException
109 | * @throws \SumUp\Exceptions\SumUpConnectionException
110 | * @throws \SumUp\Exceptions\SumUpResponseException
111 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
112 | * @throws \SumUp\Exceptions\SumUpSDKException
113 | */
114 | public function updateDoingBusinessAs(array $data)
115 | {
116 | if (empty($data)) {
117 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('payload data'));
118 | }
119 | $path = '/v0.1/me/merchant-profile/doing-business-as';
120 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
121 | return $this->client->send('PUT', $path, $data, $headers);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/SumUp/Services/Payouts.php:
--------------------------------------------------------------------------------
1 | client = $client;
41 | $this->accessToken = $accessToken;
42 | }
43 |
44 | /**
45 | * Get a list of payouts.
46 | *
47 | * @param string $startDate
48 | * @param string $endDate
49 | * @param int $limit
50 | * @param bool $descendingOrder
51 | * @param string $format
52 | *
53 | * @return \SumUp\HttpClients\Response
54 | *
55 | * @throws SumUpArgumentException
56 | * @throws \SumUp\Exceptions\SumUpConnectionException
57 | * @throws \SumUp\Exceptions\SumUpResponseException
58 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
59 | * @throws \SumUp\Exceptions\SumUpSDKException
60 | */
61 | public function getPayouts($startDate, $endDate, $limit = 10, $descendingOrder = true, $format = 'json')
62 | {
63 | if (empty($startDate)) {
64 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('start date'));
65 | }
66 | if (empty($endDate)) {
67 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('end date'));
68 | }
69 | if (empty($limit) || !is_int($limit)) {
70 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('limit'));
71 | }
72 | if (empty($descendingOrder)) {
73 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('order'));
74 | }
75 | if (empty($format)) {
76 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('format'));
77 | }
78 | $filters = [
79 | 'start_date' => $startDate,
80 | 'end_date' => $endDate,
81 | 'limit' => $limit,
82 | 'order' => $descendingOrder ? 'desc' : 'asc',
83 | 'format' => $format
84 | ];
85 | $queryParams = http_build_query($filters);
86 | $path = '/v0.1/me/financials/payouts?' . $queryParams;
87 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
88 | return $this->client->send('GET', $path, null, $headers);
89 | }
90 |
91 | /**
92 | * Get a list of payed out transactions.
93 | *
94 | * @param string $startDate
95 | * @param string $endDate
96 | * @param int $limit
97 | * @param bool $descendingOrder
98 | * @param string $format
99 | *
100 | * @return \SumUp\HttpClients\Response
101 | *
102 | * @throws SumUpArgumentException
103 | * @throws \SumUp\Exceptions\SumUpConnectionException
104 | * @throws \SumUp\Exceptions\SumUpResponseException
105 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
106 | * @throws \SumUp\Exceptions\SumUpSDKException
107 | */
108 | public function getTransactions($startDate, $endDate, $limit = 10, $descendingOrder = true, $format = 'json')
109 | {
110 | if (empty($startDate)) {
111 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('start date'));
112 | }
113 | if (empty($endDate)) {
114 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('end date'));
115 | }
116 | if (empty($limit) || !is_int($limit)) {
117 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('limit'));
118 | }
119 | if (empty($descendingOrder)) {
120 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('order'));
121 | }
122 | if (empty($format)) {
123 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('format'));
124 | }
125 | $filters = [
126 | 'start_date' => $startDate,
127 | 'end_date' => $endDate,
128 | 'limit' => $limit,
129 | 'order' => $descendingOrder ? 'desc' : 'asc',
130 | 'format' => $format
131 | ];
132 | $queryParams = http_build_query($filters);
133 | $path = '/v0.1/me/financials/transactions?' . $queryParams;
134 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
135 | return $this->client->send('GET', $path, null, $headers);
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/SumUp/Services/SumUpService.php:
--------------------------------------------------------------------------------
1 | client = $client;
41 | $this->accessToken = $accessToken;
42 | }
43 |
44 | /**
45 | * Get single transaction by transaction ID.
46 | *
47 | * @param $transactionId
48 | *
49 | * @return \SumUp\HttpClients\Response
50 | *
51 | * @throws SumUpArgumentException
52 | * @throws \SumUp\Exceptions\SumUpConnectionException
53 | * @throws \SumUp\Exceptions\SumUpResponseException
54 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
55 | * @throws \SumUp\Exceptions\SumUpSDKException
56 | */
57 | public function findById($transactionId)
58 | {
59 | if (empty($transactionId)) {
60 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction id'));
61 | }
62 | $path = '/v0.1/me/transactions?id=' . $transactionId;
63 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
64 | return $this->client->send('GET', $path, [], $headers);
65 | }
66 |
67 | /**
68 | * Get single transaction by internal ID.
69 | *
70 | * @param $internalId
71 | *
72 | * @return \SumUp\HttpClients\Response
73 | *
74 | * @throws SumUpArgumentException
75 | * @throws \SumUp\Exceptions\SumUpConnectionException
76 | * @throws \SumUp\Exceptions\SumUpResponseException
77 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
78 | * @throws \SumUp\Exceptions\SumUpSDKException
79 | */
80 | public function findByInternalId($internalId)
81 | {
82 | if (empty($internalId)) {
83 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('internal id'));
84 | }
85 | $path = '/v0.1/me/transactions?internal_id=' . $internalId;
86 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
87 | return $this->client->send('GET', $path, [], $headers);
88 | }
89 |
90 | /**
91 | * Get single transaction by foreign transaction id.
92 | *
93 | * @param $foreignId
94 | *
95 | * @return \SumUp\HttpClients\Response
96 | *
97 | * @throws SumUpArgumentException
98 | * @throws \SumUp\Exceptions\SumUpConnectionException
99 | * @throws \SumUp\Exceptions\SumUpResponseException
100 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
101 | * @throws \SumUp\Exceptions\SumUpSDKException
102 | */
103 | public function findByForeignId($foreignId)
104 | {
105 | if (empty($foreignId)) {
106 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('foreign transaction id'));
107 | }
108 | $path = '/v0.1/me/transactions?foreign_transaction_id=' . $foreignId;
109 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
110 | return $this->client->send('GET', $path, [], $headers);
111 | }
112 |
113 | /**
114 | * Get single transaction by transaction code.
115 | *
116 | * @param $transactionCode
117 | *
118 | * @return \SumUp\HttpClients\Response
119 | *
120 | * @throws SumUpArgumentException
121 | * @throws \SumUp\Exceptions\SumUpConnectionException
122 | * @throws \SumUp\Exceptions\SumUpResponseException
123 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
124 | * @throws \SumUp\Exceptions\SumUpSDKException
125 | */
126 | public function findByTransactionCode($transactionCode)
127 | {
128 | if (empty($transactionCode)) {
129 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction code'));
130 | }
131 | $path = '/v0.1/me/transactions?transaction_code=' . $transactionCode;
132 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
133 | return $this->client->send('GET', $path, [], $headers);
134 | }
135 |
136 | /**
137 | * Get a list of transactions.
138 | *
139 | * @param array $filters
140 | *
141 | * @return \SumUp\HttpClients\Response
142 | *
143 | * @throws \SumUp\Exceptions\SumUpConnectionException
144 | * @throws \SumUp\Exceptions\SumUpResponseException
145 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
146 | * @throws \SumUp\Exceptions\SumUpSDKException
147 | */
148 | public function getTransactionHistory($filters = [])
149 | {
150 | $filters = array_merge([
151 | 'order' => 'ascending',
152 | 'limit' => 10,
153 | 'user_id' => null,
154 | 'users' => [],
155 | 'statuses' => [],
156 | 'payment_types' => [],
157 | 'types' => [],
158 | 'changes_since' => null,
159 | 'newest_time' => null,
160 | 'newest_ref' => null,
161 | 'oldest_time' => null,
162 | 'oldest_ref' => null,
163 | ], $filters);
164 |
165 | $queryParams = http_build_query($filters);
166 | /**
167 | * Remove index from the [] because the server doesn't support it this way.
168 | */
169 | $queryParams = preg_replace('/%5B[0-9]+%5D/', '%5B%5D', $queryParams);
170 |
171 | $path = '/v0.1/me/transactions/history?' . $queryParams;
172 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
173 | return $this->client->send('GET', $path, [], $headers);
174 | }
175 |
176 | /**
177 | * Refund a transaction partially or fully.
178 | *
179 | * @param $transactionId
180 | * @param null $amount
181 | *
182 | * @return \SumUp\HttpClients\Response
183 | *
184 | * @throws SumUpArgumentException
185 | * @throws \SumUp\Exceptions\SumUpConnectionException
186 | * @throws \SumUp\Exceptions\SumUpResponseException
187 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
188 | * @throws \SumUp\Exceptions\SumUpSDKException
189 | */
190 | public function refund($transactionId, $amount = null)
191 | {
192 | if (empty($transactionId)) {
193 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction id'));
194 | }
195 | $payload = [];
196 | if (!empty($amount)) {
197 | $payload = [
198 | 'amount' => $amount
199 | ];
200 | }
201 | $path = '/v0.1/me/refund/' . $transactionId;
202 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
203 | return $this->client->send('POST', $path, $payload, $headers);
204 | }
205 |
206 | /**
207 | * Get a receipt for a transaction.
208 | *
209 | * @param $transactionId
210 | * @param $merchantId
211 | *
212 | * @return \SumUp\HttpClients\Response
213 | *
214 | * @throws SumUpArgumentException
215 | * @throws \SumUp\Exceptions\SumUpConnectionException
216 | * @throws \SumUp\Exceptions\SumUpResponseException
217 | * @throws \SumUp\Exceptions\SumUpAuthenticationException
218 | * @throws \SumUp\Exceptions\SumUpSDKException
219 | */
220 | public function getReceipt($transactionId, $merchantId)
221 | {
222 | if (empty($transactionId)) {
223 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction id'));
224 | }
225 | if (empty($merchantId)) {
226 | throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('merchant id'));
227 | }
228 | $queryParams = http_build_query(['mid' => $merchantId]);
229 | $path = '/v1.0/receipts/' . $transactionId . '?' . $queryParams;
230 | $headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
231 | return $this->client->send('GET', $path, [], $headers);
232 | }
233 | }
234 |
--------------------------------------------------------------------------------
/src/SumUp/SumUp.php:
--------------------------------------------------------------------------------
1 | appConfig = new ApplicationConfiguration($config);
55 | $this->client = HttpClientsFactory::createHttpClient($this->appConfig, $customHttpClient);
56 | $authorizationService = new Authorization($this->client, $this->appConfig);
57 | $this->accessToken = $authorizationService->getToken();
58 | }
59 |
60 | /**
61 | * Returns the access token.
62 | *
63 | * @return Authentication\AccessToken
64 | */
65 | public function getAccessToken()
66 | {
67 | return $this->accessToken;
68 | }
69 |
70 | /**
71 | * Refresh the access token.
72 | *
73 | * @param string $refreshToken
74 | *
75 | * @return Authentication\AccessToken
76 | *
77 | * @throws SumUpSDKException
78 | */
79 | public function refreshToken($refreshToken = null)
80 | {
81 | if (isset($refreshToken)) {
82 | $rToken = $refreshToken;
83 | } elseif (!isset($refreshToken) && !isset($this->accessToken)) {
84 | throw new SumUpConfigurationException('There is no refresh token');
85 | } else {
86 | $rToken = $this->accessToken->getRefreshToken();
87 | }
88 | $authorizationService = new Authorization($this->client, $this->appConfig);
89 | $this->accessToken = $authorizationService->refreshToken($rToken);
90 | return $this->accessToken;
91 | }
92 |
93 | /**
94 | * Get the service for authorization.
95 | *
96 | * @param ApplicationConfigurationInterface|null $config
97 | *
98 | * @return Authorization
99 | */
100 | public function getAuthorizationService(ApplicationConfigurationInterface $config = null)
101 | {
102 | if (empty($config)) {
103 | $cfg = $this->appConfig;
104 | } else {
105 | $cfg = $config;
106 | }
107 | return new Authorization($this->client, $cfg);
108 | }
109 |
110 | /**
111 | * Get the service for checkouts management.
112 | *
113 | * @param AccessToken|null $accessToken
114 | *
115 | * @return Checkouts
116 | */
117 | public function getCheckoutService(AccessToken $accessToken = null)
118 | {
119 | if (!empty($accessToken)) {
120 | $accToken = $accessToken;
121 | } else {
122 | $accToken = $this->accessToken;
123 | }
124 | return new Checkouts($this->client, $accToken);
125 | }
126 |
127 | /**
128 | * Get the service for customers management.
129 | *
130 | * @param AccessToken|null $accessToken
131 | *
132 | * @return Customers
133 | */
134 | public function getCustomerService(AccessToken $accessToken = null)
135 | {
136 | if (!empty($accessToken)) {
137 | $accToken = $accessToken;
138 | } else {
139 | $accToken = $this->accessToken;
140 | }
141 | return new Customers($this->client, $accToken);
142 | }
143 |
144 | /**
145 | * Get the service for transactions management.
146 | *
147 | * @param AccessToken|null $accessToken
148 | *
149 | * @return Transactions
150 | */
151 | public function getTransactionService(AccessToken $accessToken = null)
152 | {
153 | if (!empty($accessToken)) {
154 | $accToken = $accessToken;
155 | } else {
156 | $accToken = $this->accessToken;
157 | }
158 | return new Transactions($this->client, $accToken);
159 | }
160 |
161 | /**
162 | * Get the service for merchant management.
163 | *
164 | * @param AccessToken|null $accessToken
165 | *
166 | * @return Merchant
167 | */
168 | public function getMerchantService(AccessToken $accessToken = null)
169 | {
170 | if (!empty($accessToken)) {
171 | $accToken = $accessToken;
172 | } else {
173 | $accToken = $this->accessToken;
174 | }
175 | return new Merchant($this->client, $accToken);
176 | }
177 |
178 | /**
179 | * Get the service for payouts.
180 | *
181 | * @param AccessToken|null $accessToken
182 | *
183 | * @return Payouts
184 | */
185 | public function getPayoutService(AccessToken $accessToken = null)
186 | {
187 | if (!empty($accessToken)) {
188 | $accToken = $accessToken;
189 | } else {
190 | $accToken = $this->accessToken;
191 | }
192 | return new Payouts($this->client, $accToken);
193 | }
194 |
195 | /**
196 | * @param AccessToken|null $accessToken
197 | *
198 | * @return Custom
199 | */
200 | public function getCustomService(AccessToken $accessToken = null)
201 | {
202 | if (!empty($accessToken)) {
203 | $accToken = $accessToken;
204 | } else {
205 | $accToken = $this->accessToken;
206 | }
207 | return new Custom($this->client, $accToken);
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/src/SumUp/Utils/ExceptionMessages.php:
--------------------------------------------------------------------------------
1 | 'application/json'];
28 | }
29 |
30 | /**
31 | * Get the common header for Content-Type: application/x-www-form-urlencoded.
32 | *
33 | * @return array
34 | */
35 | public static function getCTForm()
36 | {
37 | return ['Content-Type' => 'application/x-www-form-urlencoded'];
38 | }
39 |
40 | /**
41 | * Get the authorization header with token.
42 | *
43 | * @param AccessToken $accessToken
44 | *
45 | * @return array
46 | */
47 | public static function getAuth(AccessToken $accessToken)
48 | {
49 | return ['Authorization' => 'Bearer ' . $accessToken->getValue()];
50 | }
51 |
52 | /**
53 | * Get custom array.
54 | *
55 | * @return array
56 | */
57 | public static function getTrk()
58 | {
59 | return ['X-SDK' => 'PHP-SDK/v' . self::getProjectVersion() . ' PHP/v' . phpversion()];
60 | }
61 |
62 | /**
63 | * Get the version of the project accroding to the composer.json
64 | *
65 | * @return string
66 | */
67 | public static function getProjectVersion()
68 | {
69 | if (is_null(self::$cacheVersion)) {
70 | $pathToComposer = realpath(dirname(__FILE__) . '/../../../composer.json');
71 | $content = file_get_contents($pathToComposer);
72 | $content = json_decode($content, true);
73 | self::$cacheVersion = $content['version'];
74 | }
75 |
76 | return self::$cacheVersion;
77 | }
78 |
79 | /**
80 | * Get standard headers needed for every request.
81 | *
82 | * @return array
83 | */
84 | public static function getStandardHeaders()
85 | {
86 | $headers = self::getCTJson();
87 | $headers += self::getTrk();
88 | return $headers;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------