Skip to content

Commit

Permalink
Tweaks before release
Browse files Browse the repository at this point in the history
  • Loading branch information
olssonm committed Jun 30, 2022
1 parent e4b94bd commit aece0a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

Simple and easy to use Swish-wrapper for PHP. Also includes providers and facades for easy usage with Laravel.

## Prerequisites

This packagade supports PHP ^7.4 and ^8.0, as well as Laravel 7 and up to the latest version. PHP needs to be compiled with the CURL and SSL-extensions (in an abosolute majority of cases they should be available per default.)

## Installation

```
Expand Down Expand Up @@ -106,13 +110,13 @@ $response = Swish::create(new Payment([

### Payments and Refunds

Always when using the client, use the Payment and Refund-classes even if just an ID is needed for the endpoint, i.e:
Always when using the client, use the Payment and Refund-classes even if only the ID is needed for the endpoint, i.e:

``` php
$payment = $client->get(Payment(['id' => '5D59DA1B1632424E874DDB219AD54597']));
```

### IDs/UUIDs
### Regarding IDs/UUIDs

This package uses the v2 of the Swish API where a UUID is set by the merchant. This package handles all these aspects automatically as needed, you may however choose to manually set the ID/instructionUUID (either in Swish's own format, or a default v4-format):

Expand All @@ -129,7 +133,7 @@ $payment = new Payment([
If an invalid UUID is used, a `Olssonm\Swish\Exceptions\InvalidUuidException` will be thrown.

*Note 1:* Wheter you set a default UUID or one in the Swish-format – it will <u>always</u> be formatted for Swish automatically.
*Note 2:* This package uses [Ramsey/Uuid](https://github.com/ramsey/uuid) to generate RFC4122 (v4) UUIDs on the fly. Swish accepts V1, 3, 4 and 5 UUIDs.
*Note 2:* This package uses [Ramsey/Uuid](https://github.com/ramsey/uuid) to generate RFC4122 (v4) UUIDs on the fly. Swish accepts V1, 3, 4 and 5 UUIDs if you chose to set your own UUIDs.

### Available methods

Expand Down Expand Up @@ -174,7 +178,7 @@ $paymentOrRefund = Callback::parse($content = null);
// get_class($paymentOrRefund) = \Olssonm\Swish\Payment::class or \Olssonm\Swish\Refund::class
```

The helper automatically retrieve the current HTTP-request. You may however inject your own data if needed (or if you have a Laravel request-object ready):
The helper automatically retrieve the current HTTP-request. You may however inject your own data if needed (or if you for example has a Laravel request-object ready):

```php
class SwishController
Expand Down
4 changes: 2 additions & 2 deletions src/Api/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

abstract class AbstractResource
{
protected $client;
protected Client $client;

public function __construct(Client $client)
{
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function request(string $verb, string $uri, array $headers = [], $payl
* @param string $label
* @param RequestInterface $request
* @param ResponseInterface $response
* @return RequestException
* @return void
*/
protected function triggerException(
string $class,
Expand Down
19 changes: 19 additions & 0 deletions src/Util/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,38 @@ class Uuid

public const SWISH = 'swish';

/**
* Create UUID.
*
* @param string $format
* @return string
*/
public static function make(string $format = self::SWISH): string
{
$uuid = RamseyUuid::uuid4();

return self::format($uuid, $format);
}

/**
* Validate UUID.
*
* @param string $uuid
* @return boolean
*/
public static function validate(string $uuid): bool
{
$uuid = self::format($uuid, self::DEFAULT);
return RamseyUuid::isValid($uuid);
}

/**
* Format UUIDs between Swish and "default"-formats.
*
* @param string $uuid
* @param string $format
* @return string
*/
public static function format(string $uuid, string $format = self::DEFAULT): string
{
$parts = explode('-', $uuid);
Expand Down

0 comments on commit aece0a4

Please sign in to comment.