-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
m.vela
committed
Jan 15, 2020
1 parent
f0a5f30
commit b0b003b
Showing
363 changed files
with
34,212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
// Copy this file to .env.php and edit the credentials | ||
// to be able to run the API tests. | ||
return [ | ||
'username' => '', | ||
'password' => '', | ||
'businessId' => '', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright 2018-2019 Payvision B.V. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
# Payvision PHP SDK | ||
|
||
> Codebase for Payvision PHP SDK | ||
This is the official PHP SDK for the Payvision payment platform (<https://www.payvision.com>). | ||
It can be used to make use of the following features of the Payvision API: | ||
|
||
- Payments | ||
- Make payment requests | ||
- Make capture requests | ||
- Make cancel requests | ||
- Make refund requests | ||
- Get transaction status updates | ||
- Paymentlink | ||
- Make new paymentlink | ||
- Get status of existing paymentlink | ||
- Cancel existing paymentlink | ||
- Checkout | ||
- Initialize new checkout | ||
- Get checkout status | ||
- Webhooks | ||
- Convert RAW webhook data to the proper objects | ||
|
||
## Install | ||
|
||
This package can be installed using Composer: | ||
|
||
composer require payvision/payvision-sdk-php | ||
|
||
## Usage | ||
|
||
### Initialize the API | ||
|
||
To initialize the API Connection, refer to the following code snippet: | ||
|
||
use Payvision\SDK\Infrastructure\ApiConnection; | ||
|
||
$apiConnection = new ApiConnection( | ||
'username', | ||
'password', | ||
ApiConnection::URI_TEST, // =URL to connect to, optional | ||
false // debug mode, see debugging | ||
); | ||
|
||
#### Debugging the API | ||
|
||
The API uses the [Guzzle HTTP Client](http://docs.guzzlephp.org/en/stable/). | ||
The debug-property is passed through to the Guzzle Client. See | ||
<http://docs.guzzlephp.org/en/stable/request-options.html#debug> for more | ||
information about debugging. | ||
|
||
### Creating a payment request | ||
|
||
The PHP SDK is a direct reflection of how the JSON structure of the requests | ||
and responses are typically built for the Payvision API. | ||
|
||
For example, a typical payment request to the Payvision API would require | ||
a JSON body like this: | ||
|
||
{ | ||
"header" : { | ||
"businessId" : "{businessId}" | ||
}, | ||
"action" : "authorize", | ||
"body" : { | ||
"card" : { | ||
"holderName" : "John Doe", | ||
"number" : "4111111111111111", | ||
"expiryMonth" : "03", | ||
"expiryYear" : "2020" | ||
}, | ||
"transaction" : { | ||
"amount" : "1.00", | ||
"brandId" : "1010", | ||
"trackingCode" : "7F4BFD5D-55E4-4775-81F7-0784188876C7", | ||
"currencyCode" : "EUR" | ||
} | ||
} | ||
} | ||
|
||
To create this identical request using the PHP SDK, you can use one of | ||
the composite builders: | ||
|
||
use Payvision\SDK\Domain\Payments\Service\Builder\Composite\Payment\Request as PaymentRequestBuilder; | ||
use Payvision\SDK\Domain\Payments\ValueObject\Payment\Request as PaymentRequest; | ||
|
||
/** @var $paymentRequestBuilder PaymentRequestBuilder */ | ||
$paymentRequestBuilder->header()->setBusinessId('{businessId}'); | ||
$paymentRequestBuilder->body()->card() | ||
->setHolderName('John Doe') | ||
->setNumber('4111111111111111') | ||
->setExpiryMonth(3) | ||
->setExpiryYear(2020) | ||
$paymentRequestBuilder->body()->transaction() | ||
->setAmount(1.00) | ||
->setBrandId(1010) | ||
->setTrackingCode('7F4BFD5D-55E4-4775-81F7-0784188876C7') | ||
->setCurrencyCode('EUR'); | ||
$paymentRequestBuilder->setAction(PaymentRequest::ACTION_AUTHORIZE); | ||
$requestObject = $paymentRequestBuilder->build(); | ||
|
||
At this point, you have a PHP representation of the JSON object that is to | ||
be sent to the API, but it is not yet the actual request. For example: we | ||
still need to know the URL where it needs to be sent to, and what kind of | ||
response we can expect from the API. | ||
|
||
To do this we need to transform our payment request to an API request: | ||
|
||
use Payvision\SDK\Application\Payments\Service\RequestBuilder; | ||
$apiRequest = RequestBuilder::newPayment($requestObject); | ||
|
||
Now we have an API Request that we can execute using our API Connection: | ||
|
||
$apiResponse = $apiConnection->execute($apiRequest); | ||
|
||
### Handling the responses | ||
|
||
The `$apiResponse` in the above example is an object of the type that is | ||
defined in the request. To know what kind of type this is, you can use | ||
`$apiRequest->getResponseObjectByStatusCode(200)`. | ||
|
||
If the API returns a non-2XX status, an exception is thrown of the type | ||
`Payvision\SDK\Exception\Api\ErrorResponse`. This exception has the | ||
error object with more information about what went wrong: | ||
|
||
try { | ||
$apiResponse = $apiConnection->execute($apiRequest); | ||
} catch (ErrorResponse $errorResponseException) { | ||
/** \Payvision\SDK\Domain\Payments\ValueObject\Payment\Response $apiResponse */ | ||
$errorResponse = $errorResponseException->getErrorResponse(); | ||
} | ||
|
||
## Webhooks | ||
|
||
Webhooks can also be handled by the SDK. In order to do so you need the | ||
following input data: | ||
|
||
- The Event Signature (also known as a Json Web Token (JWT). This is sent in the header) | ||
- The secret that is used to sign the JWT | ||
- The body of the webhook (as string). | ||
|
||
You can pass this data to the `EventBuilder` service of the webhook: | ||
|
||
use Payvision\SDK\Application\Reflection\JsonToObject; | ||
use Payvision\SDK\Application\Webhook\Service\EventBuilder; | ||
use Payvision\SDK\Domain\Webhook\Service\Validator; | ||
|
||
$eventBuilderService = new EventBuilder( | ||
new Validator(), | ||
new JsonToObject() | ||
); | ||
|
||
$event = $eventBuilderService->generateEvent( | ||
'event signature', | ||
'secret', | ||
'json body' | ||
); | ||
|
||
Since the payload of the webhook event can be a variety of objects, the | ||
`Event::getPayload()` cannot be type-hinted. So you might want to do some | ||
extra checks on this: | ||
|
||
$payload = $event->getPayload(); | ||
if ($payload instanceof \Payvision\SDK\Domain\Payments\ValueObject\Response\Request) { | ||
... | ||
} | ||
|
||
If you don't want this (because it might miss auto-completion in your IDE because of this), you | ||
can also use `EventBuilder::generateDecoratedEvent()` to get a `EventDecorator` | ||
that provides extra functionality so you don't have to guess what the | ||
payload is: | ||
|
||
$decoratedEvent = $eventBuilderService->generateDecoratedEvent( | ||
'event signature', | ||
'secret', | ||
'json body' | ||
); | ||
|
||
if ($decoratedEvent->getPayloadType() === \Payvision\SDK\Domain\Webhook\Service\EventDecorator::TYPE_PAYMENT) { | ||
$payload = $decoratedEvent->getPaymentResponse(); | ||
} | ||
|
||
The decorator also has some additional checks to make sure that the payload is known. | ||
|
||
## Developer information | ||
|
||
If you want to analyze or improve this SDK, it's good to read the following | ||
information, targeted at developers: | ||
|
||
### Architecture | ||
|
||
The SDK is setup in a Domain Driven way. At the core are Value Objects, | ||
which are the stateless, immutable building blocks that are used in the API. | ||
Value Objects can have other value objects as child-properties. | ||
|
||
Top-level Value Objects (like a Payment Request) are converted to API | ||
request objects, which are send to the API, which in turn returns a | ||
response object. Logic goes from bottom to top, dependencies go from top | ||
to bottom: | ||
|
||
+-------------------+ | ||
| Value Object | Example: Transaction, Bank, Card, etc. | ||
| | These can be built manually, or by using the (composite) builders | ||
+-------------------+ | ||
↓ | ||
Request Builder Builds request out of aggregate using reflection. | ||
↓ | ||
+-------------------+ | ||
| Request | | ||
+-------------------+ | ||
↓ | ||
API Client Does the request to the external API | ||
↓ | ||
Response Builder Generates a response object out of the API response data using reflection. | ||
↓ | ||
+-------------------+ | ||
| Response | Example: PaymentResponse | ||
+-------------------+ | ||
|
||
### Troubleshooting | ||
|
||
See Troubleshooting.md | ||
|
||
### Contributing | ||
|
||
If you have an issue or a feature request, feel free to create an issue. | ||
If you want to contribute to this code, you can send a pull request. | ||
|
||
## License | ||
|
||
See LICENSE.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Troubleshooting | ||
|
||
## Connectivity | ||
|
||
### Error: wrong signature type | ||
|
||
Full error message: `error:1414D172:SSL routines:tls12_check_peer_sigalg:wrong signature type` | ||
|
||
This error is thown when there is a connectivity issue with the Payvision payment servers. | ||
Due to compatibility reasons the servers currently only support openssl security level 1. | ||
|
||
Some newer systems (like Debian Buster) increased their default security level to level 2, which makes it impossible to connect. | ||
See: https://wiki.debian.org/ContinuousIntegration/TriagingTips/openssl-1.1.1 | ||
|
||
As a temporary workaround, the security level on a Debian Buster system can be lowered by updating a line in the `/etc/ssl/openssl.cnf` file. | ||
Change the line | ||
|
||
CipherString = DEFAULT@SECLEVEL=2 | ||
|
||
to | ||
|
||
CipherString = DEFAULT@SECLEVEL=1 | ||
|
||
Revert the change once the Payvision servers are openssl level 2 compatible. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "payvision/payvision-sdk-php", | ||
"description": "Payvision PHP SDK", | ||
"type": "library", | ||
"version": "4.0.0", | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.0.13|^7.1", | ||
"ext-simplexml": "*", | ||
"ext-json": "*", | ||
"ext-curl": "*", | ||
"guzzlehttp/guzzle": "^6.3", | ||
"firebase/php-jwt": "^5.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Payvision\\SDK\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Payvision\\SDK\\Test\\": "tests/Test" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^6.5" | ||
} | ||
} |
Oops, something went wrong.