Skip to content

Commit 2854951

Browse files
authored
Merge pull request #160 from unzerdev/develop
Develop
2 parents c49dbb6 + 06c210a commit 2854951

File tree

255 files changed

+1666
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+1666
-621
lines changed

.php-cs-fixer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

33
$finder = PhpCsFixer\Finder::create()
4-
->in(__DIR__.'/src')
5-
->in(__DIR__.'/test');
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/test');
66

77
$config = new PhpCsFixer\Config();
88
return $config
99
->setUsingCache(false)
1010
->setRules(
1111
array(
12-
'@PSR2' => true,
12+
'@PSR12' => true,
1313
'no_blank_lines_after_phpdoc' => true,
1414
'phpdoc_add_missing_param_annotation' => true,
1515
'native_function_casing' => true,
@@ -21,11 +21,11 @@
2121
'multiline_whitespace_before_semicolons' => true,
2222
'no_singleline_whitespace_before_semicolons' => true,
2323
'no_spaces_around_offset' => true,
24-
'no_trailing_comma_in_singleline_array' => true,
24+
'no_trailing_comma_in_singleline' => true,
2525
'no_unused_imports' => true,
2626
'normalize_index_brace' => true,
2727
'phpdoc_align' => true,
2828
'phpdoc_separation' => true,
2929
)
3030
)
31-
->setFinder($finder);
31+
->setFinder($finder);

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres
66
to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [3.3.0](https://github.com/unzerdev/php-sdk/compare/3.2.0..3.3.0)
9+
### Added
10+
* Chargeback transaction type.
11+
* Add class `\UnzerSDK\Resources\TransactionTypes\Chargeback`.
12+
* Add methods `\UnzerSDK\Unzer::fetchChargeback` and `\UnzerSDK\Unzer::fetchChargebackById` to fetch chargeback information.
13+
* Add `\UnzerSDK\Resources\PaymentTypes\PayU` payment type.
14+
* Add example for PayU payment type.
15+
816
## [3.2.0](https://github.com/unzerdev/php-sdk/compare/3.1.0..3.2.0)
917

1018
### Added

examples/PayU/Constants.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* This file defines the constants needed for the PayU example.
5+
*
6+
* Copyright (C) 2020 - today Unzer E-Com GmbH
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*
20+
* @link https://docs.unzer.com/
21+
*
22+
* @package UnzerSDK\examples
23+
*/
24+
25+
require_once __DIR__ . '/../Constants.php';
26+
27+
define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'PayU');
28+
define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php');

examples/PayU/Controller.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* This is the controller for the PayU example.
4+
* It is called when the pay button on the index page is clicked.
5+
*
6+
* Copyright (C) 2020 - today Unzer E-Com GmbH
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*
20+
* @link https://docs.unzer.com/
21+
*
22+
* @package UnzerSDK\examples
23+
*/
24+
25+
/** Require the constants of this example */
26+
require_once __DIR__ . '/Constants.php';
27+
28+
/** @noinspection PhpIncludeInspection */
29+
/** Require the composer autoloader file */
30+
require_once __DIR__ . '/../../../../autoload.php';
31+
32+
use UnzerSDK\examples\ExampleDebugHandler;
33+
use UnzerSDK\Exceptions\UnzerApiException;
34+
use UnzerSDK\Unzer;
35+
36+
session_start();
37+
session_unset();
38+
39+
$clientMessage = 'Something went wrong. Please try again later.';
40+
$merchantMessage = 'Something went wrong. Please try again later.';
41+
42+
function redirect($url, $merchantMessage = '', $clientMessage = '')
43+
{
44+
$_SESSION['merchantMessage'] = $merchantMessage;
45+
$_SESSION['clientMessage'] = $clientMessage;
46+
header('Location: ' . $url);
47+
die();
48+
}
49+
50+
// You will need the id of the payment type created in the frontend (index.php)
51+
if (!isset($_POST['resourceId'])) {
52+
redirect(FAILURE_URL, 'Resource id is missing!', $clientMessage);
53+
}
54+
$paymentTypeId = $_POST['resourceId'];
55+
56+
// Catch API errors, write the message to your log and show the ClientMessage to the client.
57+
try {
58+
// Create an Unzer object using your private key and register a debug handler if you want to.
59+
$unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY);
60+
$unzer->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());
61+
62+
// Create a charge transaction to get the redirectUrl.
63+
$transaction = new \UnzerSDK\Resources\TransactionTypes\Charge(12.32, 'PLN', RETURN_CONTROLLER_URL);
64+
$unzer->performCharge($transaction, $paymentTypeId);
65+
66+
// You'll need to remember the paymentId for later in the ReturnController
67+
$_SESSION['PaymentId'] = $transaction->getPaymentId();
68+
$_SESSION['ShortId'] = $transaction->getShortId();
69+
70+
// Redirect to the PayU page
71+
if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) {
72+
redirect($transaction->getRedirectUrl());
73+
}
74+
75+
// Check the result message of the charge to find out what went wrong.
76+
$merchantMessage = $transaction->getMessage()->getCustomer();
77+
} catch (UnzerApiException $e) {
78+
$merchantMessage = $e->getMerchantMessage();
79+
$clientMessage = $e->getClientMessage();
80+
} catch (RuntimeException $e) {
81+
$merchantMessage = $e->getMessage();
82+
}
83+
redirect(FAILURE_URL, $merchantMessage, $clientMessage);

examples/PayU/index.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* This file provides an example implementation of the PayU payment type.
4+
*
5+
* Copyright (C) 2020 - today Unzer E-Com GmbH
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
* @link https://docs.unzer.com/
20+
*
21+
* @package UnzerSDK\examples
22+
*/
23+
24+
/** Require the constants of this example */
25+
require_once __DIR__ . '/Constants.php';
26+
27+
/** @noinspection PhpIncludeInspection */
28+
/** Require the composer autoloader file */
29+
require_once __DIR__ . '/../../../../autoload.php';
30+
?>
31+
32+
<!DOCTYPE html>
33+
<html lang="en">
34+
<head>
35+
<meta charset="UTF-8">
36+
<title>Unzer UI Examples</title>
37+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
38+
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
39+
crossorigin="anonymous"></script>
40+
41+
<link rel="stylesheet" href="https://static.unzer.com/v1/unzer.css" />
42+
<script type="text/javascript" src="https://static.unzer.com/v1/unzer.js"></script>
43+
</head>
44+
45+
<body style="margin: 70px 70px 0;">
46+
47+
<p><a href="https://docs.unzer.com/reference/test-data" target="_blank">Click here to open our test data in new tab.</a></p>
48+
49+
<form id="payment-form" class="unzerUI form" novalidate>
50+
<div class="field" id="error-holder" style="color: #9f3a38"> </div>
51+
<div class="field">
52+
<button class="unzerUI primary button fluid" id="submit-button" type="submit">Pay</button>
53+
</div>
54+
</form>
55+
56+
<script>
57+
// Create an Unzer instance with your public key
58+
let unzerInstance = new unzer('<?php echo UNZER_PAPI_PUBLIC_KEY; ?>');
59+
60+
// Create an PayU instance
61+
let payU = unzerInstance.PayU();
62+
63+
// Handle payment form submission
64+
let form = document.getElementById('payment-form');
65+
form.addEventListener('submit', function(event) {
66+
event.preventDefault();
67+
// Creating a payU resource
68+
payU.createResource()
69+
.then(function(result) {
70+
let hiddenInput = document.createElement('input');
71+
hiddenInput.setAttribute('type', 'hidden');
72+
hiddenInput.setAttribute('name', 'resourceId');
73+
hiddenInput.setAttribute('value', result.id);
74+
form.appendChild(hiddenInput);
75+
form.setAttribute('method', 'POST');
76+
form.setAttribute('action', '<?php echo CONTROLLER_URL; ?>');
77+
78+
// Submitting the form
79+
form.submit();
80+
})
81+
.catch(function(error) {
82+
$('#error-holder').html(error.message)
83+
})
84+
});
85+
</script>
86+
</body>
87+
</html>

examples/index.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,18 @@ function printMessage($type, $title, $text)
295295
Try
296296
</div>
297297
</div>
298+
<div class="card olive">
299+
<div class="content">
300+
<div class="header">
301+
PayU
302+
</div>
303+
<div class="description">
304+
</div>
305+
</div>
306+
<div id="tryPayUExample" class="ui bottom attached green button" onclick="location.href='PayU/';">
307+
Try
308+
</div>
309+
</div>
298310
<div class="card olive">
299311
<div class="content">
300312
<div class="header">

phpunit.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0"?>
2-
<phpunit backupGlobals="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
backupGlobals="false"
34
backupStaticAttributes="false"
45
bootstrap="test/bootstrap.php"
56
colors="false"
@@ -8,16 +9,17 @@
89
convertWarningsToExceptions="false"
910
processIsolation="false"
1011
stopOnFailure="false"
11-
verbose="true">
12+
verbose="true"
13+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
14+
<coverage processUncoveredFiles="true">
15+
<include>
16+
<directory suffix=".php">src/</directory>
17+
</include>
18+
</coverage>
1219
<groups>
1320
<exclude>
1421
<group>disabled</group>
1522
<group>skip</group>
1623
</exclude>
1724
</groups>
18-
<filter>
19-
<whitelist processUncoveredFilesFromWhitelist="true">
20-
<directory suffix=".php">src/</directory>
21-
</whitelist>
22-
</filter>
23-
</phpunit>
25+
</phpunit>

src/Adapter/ApplepayAdapter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/** @noinspection PhpComposerExtensionStubsInspection */
34

45
/**
@@ -22,6 +23,7 @@
2223
*
2324
* @package UnzerSDK\Adapter
2425
*/
26+
2527
namespace UnzerSDK\Adapter;
2628

2729
use UnzerSDK\Constants\ApplepayValidationDomains;

src/Adapter/CurlAdapter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/** @noinspection PhpComposerExtensionStubsInspection */
34
/**
45
* This is a wrapper for the default http adapter (CURL).
@@ -21,13 +22,15 @@
2122
*
2223
* @package UnzerSDK\Adapter
2324
*/
25+
2426
namespace UnzerSDK\Adapter;
2527

2628
use UnzerSDK\Unzer;
2729
use UnzerSDK\Services\EnvironmentService;
28-
use function extension_loaded;
2930
use UnzerSDK\Exceptions\UnzerApiException;
3031
use RuntimeException;
32+
33+
use function extension_loaded;
3134
use function in_array;
3235

3336
class CurlAdapter implements HttpAdapterInterface

src/Adapter/HttpAdapterInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*
2121
* @package UnzerSDK\Adapter
2222
*/
23+
2324
namespace UnzerSDK\Adapter;
2425

2526
use UnzerSDK\Exceptions\UnzerApiException;

0 commit comments

Comments
 (0)