Skip to content

Commit

Permalink
Stable Release (#4)
Browse files Browse the repository at this point in the history
* Minor improvements in the documentation and trk

* Improve documentation about the Response

* Improve refund transaction funcitonality

* Version bump for stable release

* Code optimization
  • Loading branch information
lyubomir-sumup authored Feb 5, 2019
1 parent 44ecfab commit 847ae00
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

This repository contains the open source PHP SDK that allows you to integrate quickly with the SumUp's ecommerce [API](https://developer.sumup.com/rest-api) endpoints. As a transport layer it support cURL or [GuzzleHttp](https://packagist.org/packages/guzzlehttp/guzzle) but they are not required if you provide your own.
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.

## Installation

Expand All @@ -12,20 +12,19 @@ The SumUp eCom PHP SDK can be installed with [Composer](https://getcomposer.org/
composer require sumup/sumup-ecom-php-sdk
```

> **Note:** This version of the SumUp SDK for PHP requires PHP 5.6 or greater.
## Basic usage

```php
try {
$sumup = new \SumUp\SumUp([
'app_id' => 'YOUR-CLIENT-ID',
'app_id' => 'YOUR-CLIENT-ID',
'app_secret' => 'YOUR-CLIENT-SECRET',
'code' => 'YOUR-AUTHORIZATION-CODE'
'code' => 'YOUR-AUTHORIZATION-CODE'
]);
$checkoutService = $sumup->getCheckoutService();
$checkoutResponse = $checkoutService->create($config);
// use the variable $checkoutResponse
$checkoutResponse = $checkoutService->create($amount, $currency, $checkoutRef, $payToEmail);
$checkoutId = $checkoutResponse->getBody()->id;
// pass the $chekoutId to the front-end to be processed
} catch (\SumUp\Exceptions\SumUpAuthenticationException $e) {
echo 'Authentication error: ' . $e->getMessage();
} catch (\SumUp\Exceptions\SumUpResponseException $e) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "SumUp eCom SDK for PHP",
"type": "library",
"license": "proprietary",
"version": "1.0.0-rc.2",
"version": "1.0.0",
"keywords": ["sumup", "sdk", "payment processing", "ecommerce", "payment", "checkout"],
"homepage": "https://developer.sumup.com",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Here is the API reference for the SumUp Ecommerce SDK for PHP.
| [\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. |
| [\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. |
| [\SumUp\Authentication\AccessToken](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/AccessToken.md) | An entity that represents an access token. |
| [\SumUp\HttpClients\Response](https://github.com/sumup/sumup-ecom-php-sdk/blob/master/docs/reference/Response.md) | The response object that every service returns. |

## Services

Expand All @@ -25,7 +26,6 @@ Here is the API reference for the SumUp Ecommerce SDK for PHP.
| Class name | Description |
|--- |--- |
| [\SumUp\HttpClients\Response]() | The response object that every service returns. |
| [\SumUp\HttpClients\SumUpCUrlClient]() | The HTTP client for managing cURL requests. |
| [\SumUp\HttpClients\SumUpGuzzleHttpClient]() | The HTTP client for managing [Guzzle HTTP](https://packagist.org/packages/guzzlehttp/guzzle) requests. |
| [\SumUp\HttpClients\HttpClientsFactory]() | The factory class that creates HTTP clients. | -->
Expand Down
23 changes: 23 additions & 0 deletions docs/reference/Response.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Response for the SumUp Ecommerce SDK for PHP

## \SumUp\HttpClients\Response

The `\SumUp\HttpClients\Response` object is the main object that is returned from every successful service call.

## Instance Methods

### getHttpResponseCode()

```php
public function getHttpResponseCode(): int
```

Returns the HTTP response code.

### getBody()

```php
public function getBody(): mixed
```

Returns different object according to the service's response.
2 changes: 1 addition & 1 deletion docs/reference/Transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Returns a `\SumUp\HttpClients\Response` or throws an exception.
Refunds a transaction partially or fully depending on the `amount`.

```php
public function refund(string $transactionId, float $amount): \SumUp\HttpClients\Response
public function refund(string $transactionId, float $amount = null): \SumUp\HttpClients\Response
```

Returns a `\SumUp\HttpClients\Response` or throws an exception.
Expand Down
14 changes: 7 additions & 7 deletions src/SumUp/Services/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function getTransactionHistory($filters = [])
* Refund a transaction partially or fully.
*
* @param $transactionId
* @param $amount
* @param null $amount
*
* @return \SumUp\HttpClients\Response
*
Expand All @@ -164,17 +164,17 @@ public function getTransactionHistory($filters = [])
* @throws \SumUp\Exceptions\SumUpAuthenticationException
* @throws \SumUp\Exceptions\SumUpSDKException
*/
public function refund($transactionId, $amount)
public function refund($transactionId, $amount = null)
{
if (empty($transactionId)) {
throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('transaction id'));
}
if (empty($amount)) {
throw new SumUpArgumentException(ExceptionMessages::getMissingParamMsg('amount'));
$payload = [];
if (!empty($amount)) {
$payload = [
'amount' => $amount
];
}
$payload = [
'amount' => $amount
];
$path = '/v0.1/me/refund/' . $transactionId;
$headers = array_merge(Headers::getStandardHeaders(), Headers::getAuth($this->accessToken));
return $this->client->send('POST', $path, $payload, $headers);
Expand Down
3 changes: 1 addition & 2 deletions src/SumUp/Utils/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public static function getAuth(AccessToken $accessToken)
*/
public static function getTrk()
{
$version = self::getProjectVersion();
return ['X-SDK' => 'PHP/v' . $version];
return ['X-SDK' => 'PHP-SDK/v' . self::getProjectVersion() . ' PHP/v' . phpversion()];
}

/**
Expand Down

0 comments on commit 847ae00

Please sign in to comment.