Skip to content

Develop #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c28da64
[CC-406] Add chargeback transaction.
Ryouzanpaku Aug 10, 2023
d614cf7
[CC-406] Update changelog and version.
Ryouzanpaku Aug 10, 2023
7bbbf24
[CC-406] Set Payment:addChargeback visibility to private.
Ryouzanpaku Aug 11, 2023
dd21121
[CC-510] Add PayU type
Ryouzanpaku Aug 11, 2023
33b31ad
[CC-510] run cs-fixer.
Ryouzanpaku Aug 11, 2023
8bd7eef
[CC-406] Add payU to changelog.
Ryouzanpaku Aug 14, 2023
148eada
[CC-516] Add payU example.
Ryouzanpaku Aug 14, 2023
2cbd7b5
Merge pull request #154 from unzerdev/CC-510/payu
Ryouzanpaku Aug 15, 2023
2b05730
Merge branch 'develop' into CC-406/add_chargeback_transaction
Ryouzanpaku Aug 15, 2023
a93578b
Merge pull request #153 from unzerdev/CC-406/add_chargeback_transaction
Ryouzanpaku Aug 15, 2023
a51a948
[CC-516] Merge branch 'develop' into CC-516/payu-example
Ryouzanpaku Aug 15, 2023
fd4116d
[CC-516] update changelog.
Ryouzanpaku Aug 15, 2023
1b5747b
[CC-516] Fix url for unzer.js.
Ryouzanpaku Aug 16, 2023
dff0873
Merge pull request #155 from unzerdev/CC-516/payu-example
Ryouzanpaku Aug 16, 2023
962c47c
[CC-406] fix getChargeback method, causing issues when fetching charg…
Ryouzanpaku Aug 17, 2023
ab16f77
[CC-406] refactor chargeback test.
Ryouzanpaku Aug 17, 2023
5d6b6de
Merge pull request #156 from unzerdev/CC-406/add_chargeback_transaction
Ryouzanpaku Aug 17, 2023
4983c92
[CC-541] Remove code-folds (#157)
GreatG0ose Aug 24, 2023
cba2517
run cs-fixer.
Ryouzanpaku Aug 24, 2023
0a760db
Switch to `PSR12` ruleset for cs-fixer since `PSR2` is deprecated.
Ryouzanpaku Aug 24, 2023
91b1355
update deprecated cs-fixer config name.
Ryouzanpaku Aug 24, 2023
675fb1d
cs fix.
Ryouzanpaku Aug 24, 2023
a549b37
Merge pull request #158 from unzerdev/CC-541/cs-fixer
Ryouzanpaku Aug 24, 2023
1fcd480
[CC-540] Update keypair usage for integration tests.
Ryouzanpaku Aug 31, 2023
100074d
[CC-540] Replace deprecated phpunit method.
Ryouzanpaku Aug 31, 2023
7346fa7
[CC-540] Migrate phpunit config.
Ryouzanpaku Aug 31, 2023
06c210a
Merge pull request #159 from unzerdev/CC-540/testkeypair_update
Ryouzanpaku Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

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

$config = new PhpCsFixer\Config();
return $config
->setUsingCache(false)
->setRules(
array(
'@PSR2' => true,
'@PSR12' => true,
'no_blank_lines_after_phpdoc' => true,
'phpdoc_add_missing_param_annotation' => true,
'native_function_casing' => true,
Expand All @@ -21,11 +21,11 @@
'multiline_whitespace_before_semicolons' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_comma_in_singleline' => true,
'no_unused_imports' => true,
'normalize_index_brace' => true,
'phpdoc_align' => true,
'phpdoc_separation' => true,
)
)
->setFinder($finder);
->setFinder($finder);
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres
to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.3.0](https://github.com/unzerdev/php-sdk/compare/3.2.0..3.3.0)
### Added
* Chargeback transaction type.
* Add class `\UnzerSDK\Resources\TransactionTypes\Chargeback`.
* Add methods `\UnzerSDK\Unzer::fetchChargeback` and `\UnzerSDK\Unzer::fetchChargebackById` to fetch chargeback information.
* Add `\UnzerSDK\Resources\PaymentTypes\PayU` payment type.
* Add example for PayU payment type.

## [3.2.0](https://github.com/unzerdev/php-sdk/compare/3.1.0..3.2.0)

### Added
Expand Down
28 changes: 28 additions & 0 deletions examples/PayU/Constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* This file defines the constants needed for the PayU example.
*
* Copyright (C) 2020 - today Unzer E-Com GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://docs.unzer.com/
*
* @package UnzerSDK\examples
*/

require_once __DIR__ . '/../Constants.php';

define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'PayU');
define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php');
83 changes: 83 additions & 0 deletions examples/PayU/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* This is the controller for the PayU example.
* It is called when the pay button on the index page is clicked.
*
* Copyright (C) 2020 - today Unzer E-Com GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://docs.unzer.com/
*
* @package UnzerSDK\examples
*/

/** Require the constants of this example */
require_once __DIR__ . '/Constants.php';

/** @noinspection PhpIncludeInspection */
/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';

use UnzerSDK\examples\ExampleDebugHandler;
use UnzerSDK\Exceptions\UnzerApiException;
use UnzerSDK\Unzer;

session_start();
session_unset();

$clientMessage = 'Something went wrong. Please try again later.';
$merchantMessage = 'Something went wrong. Please try again later.';

function redirect($url, $merchantMessage = '', $clientMessage = '')
{
$_SESSION['merchantMessage'] = $merchantMessage;
$_SESSION['clientMessage'] = $clientMessage;
header('Location: ' . $url);
die();
}

// You will need the id of the payment type created in the frontend (index.php)
if (!isset($_POST['resourceId'])) {
redirect(FAILURE_URL, 'Resource id is missing!', $clientMessage);
}
$paymentTypeId = $_POST['resourceId'];

// Catch API errors, write the message to your log and show the ClientMessage to the client.
try {
// Create an Unzer object using your private key and register a debug handler if you want to.
$unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY);
$unzer->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());

// Create a charge transaction to get the redirectUrl.
$transaction = new \UnzerSDK\Resources\TransactionTypes\Charge(12.32, 'PLN', RETURN_CONTROLLER_URL);
$unzer->performCharge($transaction, $paymentTypeId);

// You'll need to remember the paymentId for later in the ReturnController
$_SESSION['PaymentId'] = $transaction->getPaymentId();
$_SESSION['ShortId'] = $transaction->getShortId();

// Redirect to the PayU page
if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) {
redirect($transaction->getRedirectUrl());
}

// Check the result message of the charge to find out what went wrong.
$merchantMessage = $transaction->getMessage()->getCustomer();
} catch (UnzerApiException $e) {
$merchantMessage = $e->getMerchantMessage();
$clientMessage = $e->getClientMessage();
} catch (RuntimeException $e) {
$merchantMessage = $e->getMessage();
}
redirect(FAILURE_URL, $merchantMessage, $clientMessage);
87 changes: 87 additions & 0 deletions examples/PayU/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* This file provides an example implementation of the PayU payment type.
*
* Copyright (C) 2020 - today Unzer E-Com GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://docs.unzer.com/
*
* @package UnzerSDK\examples
*/

/** Require the constants of this example */
require_once __DIR__ . '/Constants.php';

/** @noinspection PhpIncludeInspection */
/** Require the composer autoloader file */
require_once __DIR__ . '/../../../../autoload.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Unzer UI Examples</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://static.unzer.com/v1/unzer.css" />
<script type="text/javascript" src="https://static.unzer.com/v1/unzer.js"></script>
</head>

<body style="margin: 70px 70px 0;">

<p><a href="https://docs.unzer.com/reference/test-data" target="_blank">Click here to open our test data in new tab.</a></p>

<form id="payment-form" class="unzerUI form" novalidate>
<div class="field" id="error-holder" style="color: #9f3a38"> </div>
<div class="field">
<button class="unzerUI primary button fluid" id="submit-button" type="submit">Pay</button>
</div>
</form>

<script>
// Create an Unzer instance with your public key
let unzerInstance = new unzer('<?php echo UNZER_PAPI_PUBLIC_KEY; ?>');

// Create an PayU instance
let payU = unzerInstance.PayU();

// Handle payment form submission
let form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
// Creating a payU resource
payU.createResource()
.then(function(result) {
let hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'resourceId');
hiddenInput.setAttribute('value', result.id);
form.appendChild(hiddenInput);
form.setAttribute('method', 'POST');
form.setAttribute('action', '<?php echo CONTROLLER_URL; ?>');

// Submitting the form
form.submit();
})
.catch(function(error) {
$('#error-holder').html(error.message)
})
});
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ function printMessage($type, $title, $text)
Try
</div>
</div>
<div class="card olive">
<div class="content">
<div class="header">
PayU
</div>
<div class="description">
</div>
</div>
<div id="tryPayUExample" class="ui bottom attached green button" onclick="location.href='PayU/';">
Try
</div>
</div>
<div class="card olive">
<div class="content">
<div class="header">
Expand Down
18 changes: 10 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="test/bootstrap.php"
colors="false"
Expand All @@ -8,16 +9,17 @@
convertWarningsToExceptions="false"
processIsolation="false"
stopOnFailure="false"
verbose="true">
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<groups>
<exclude>
<group>disabled</group>
<group>skip</group>
</exclude>
</groups>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
2 changes: 2 additions & 0 deletions src/Adapter/ApplepayAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/** @noinspection PhpComposerExtensionStubsInspection */

/**
Expand All @@ -22,6 +23,7 @@
*
* @package UnzerSDK\Adapter
*/

namespace UnzerSDK\Adapter;

use UnzerSDK\Constants\ApplepayValidationDomains;
Expand Down
5 changes: 4 additions & 1 deletion src/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/** @noinspection PhpComposerExtensionStubsInspection */
/**
* This is a wrapper for the default http adapter (CURL).
Expand All @@ -21,13 +22,15 @@
*
* @package UnzerSDK\Adapter
*/

namespace UnzerSDK\Adapter;

use UnzerSDK\Unzer;
use UnzerSDK\Services\EnvironmentService;
use function extension_loaded;
use UnzerSDK\Exceptions\UnzerApiException;
use RuntimeException;

use function extension_loaded;
use function in_array;

class CurlAdapter implements HttpAdapterInterface
Expand Down
1 change: 1 addition & 0 deletions src/Adapter/HttpAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @package UnzerSDK\Adapter
*/

namespace UnzerSDK\Adapter;

use UnzerSDK\Exceptions\UnzerApiException;
Expand Down
1 change: 1 addition & 0 deletions src/Constants/AdditionalAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
* @package UnzerSDK\Constants
*/

namespace UnzerSDK\Constants;

class AdditionalAttributes
Expand Down
1 change: 1 addition & 0 deletions src/Constants/AdditionalTransactionDataKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @package UnzerSDK\Constants
*/

namespace UnzerSDK\Constants;

class AdditionalTransactionDataKeys
Expand Down
1 change: 1 addition & 0 deletions src/Constants/ApiResponseCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @package UnzerSDK\Constants
*/

namespace UnzerSDK\Constants;

class ApiResponseCodes
Expand Down
1 change: 1 addition & 0 deletions src/Constants/ApplepayValidationDomains.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @package UnzerSDK\Constants
*/

namespace UnzerSDK\Constants;

class ApplepayValidationDomains
Expand Down
1 change: 1 addition & 0 deletions src/Constants/BasketItemTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @package UnzerSDK\Constants
*/

namespace UnzerSDK\Constants;

class BasketItemTypes
Expand Down
1 change: 1 addition & 0 deletions src/Constants/CancelReasonCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* @package UnzerSDK\Constants
*/

namespace UnzerSDK\Constants;

class CancelReasonCodes
Expand Down
Loading