Skip to content

Commit 7a40a94

Browse files
authored
Merge pull request #137 from unzerdev/develop
Develop
2 parents f8fb606 + d853171 commit 7a40a94

File tree

133 files changed

+1295
-624
lines changed

Some content is hidden

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

133 files changed

+1295
-624
lines changed

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Setup PHP
2525
uses: shivammathur/setup-php@v2
2626
with:
27-
php-version: '7.1'
27+
php-version: '7.4'
2828
- name: Setup Apple Pay test certificate
2929
run: mkdir certs
3030
- run: echo "$APPLE_PAY_MERCHANT_ID_CERT" > certs/merchant_id.pem

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
15+
php: ['7.4', '8.0', '8.1', '8.2']
1616
name: PHP ${{ matrix.php }} unit tests
1717
steps:
1818
- uses: actions/checkout@v3

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ 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.0.0](https://github.com/unzerdev/php-sdk/compare/1.2.3.0..3.0.0)
9+
10+
### Added
11+
12+
* Enable PHP version 8.2 in composer.json.
13+
* Add paypage property to `Payment` class.
14+
* Add class `\UnzerSDK\Resources\EmbeddedResources\CardTransactionData`.
15+
Set as "card" field of additionalTransactionData
16+
* Add constants `\UnzerSDK\Constants\LiabilityShiftIndicator` for valid liability shift indicator values, relevant for card payment.
17+
* Charge and authorize transactions with card can contain that indicator in Api Response. (`CardTransactionData::$liability`)
18+
19+
### Changed
20+
21+
* Switch SDK to 3-digit versioning. First digit, formerly representing API version gets omitted (1.3.0.0 -> 3.0.0).
22+
* Add Type declaration to methods where applicable.
23+
* Enable `Unzer::fetchPaymentRefund` and `Unzer::fetchPaymentReversal` to use resource ID as parameter.
24+
* Raise minimum PHP version to 7.4 in composer.json
25+
* Handling of additionalTransactionData:
26+
* `additionalTransactionData.card` from API responses will be mapped on `\UnzerSDK\Resources\EmbeddedResources\CardTransactionData` now.
27+
* Remove `paymentType` parameter of `\UnzerSDK\Traits\HasRecurrenceType::setRecurrenceType`, it will always be set for `card` field of `additionalTransactionData`.
28+
829
## [1.2.3.0](https://github.com/unzerdev/php-sdk/compare/1.2.2.0..1.2.3.0)
930

1031
### Changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
[![Latest Version on Packagist](https://img.shields.io/packagist/v/unzerdev/php-sdk.svg?style=flat-square)](https://packagist.org/packages/unzerdev/php-sdk)
2-
[![PHP 7.1](https://img.shields.io/badge/php-7.1-blue.svg)](http://www.php.net)
3-
[![PHP 7.2](https://img.shields.io/badge/php-7.2-blue.svg)](http://www.php.net)
4-
[![PHP 7.3](https://img.shields.io/badge/php-7.3-blue.svg)](http://www.php.net)
52
[![PHP 7.4](https://img.shields.io/badge/php-7.4-blue.svg)](http://www.php.net)
63
[![PHP 8.0](https://img.shields.io/badge/php-8.0-blue.svg)](http://www.php.net)
74
[![PHP 8.1](https://img.shields.io/badge/php-8.1-blue.svg)](http://www.php.net)
5+
[![PHP 8.2](https://img.shields.io/badge/php-8.2-blue.svg)](http://www.php.net)
86

97
![Logo](unzer_logo.svg)
108

@@ -57,4 +55,4 @@ For any issues or questions please get in touch with our support team.
5755
* AT: [+43 1 513 66 33 669](tel:+4315136633669)
5856

5957
### Twitter
60-
[@UnzerTech](https://twitter.com/UnzerTech)
58+
[@UnzerTech](https://twitter.com/UnzerTech)

composer.json

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"minimum-stability": "stable",
55
"license": "Apache-2.0",
66
"require": {
7-
"php": "~7.1.0|~7.2.0|~7.3.0|~7.4.0|~8.0.0|~8.1.0",
7+
"php": "~7.4.0|~8.0.0|~8.1.0|~8.2.0",
88
"ext-json": "*"
99
},
1010
"require-dev": {

examples/Constants.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
const EXAMPLE_BASE_FOLDER = UNZER_PAPI_URL . UNZER_PAPI_FOLDER;
3030
define('SUCCESS_URL', EXAMPLE_BASE_FOLDER . 'Success.php');
31+
define('CREATE_URL', EXAMPLE_BASE_FOLDER . 'Create.php');
3132
define('PENDING_URL', EXAMPLE_BASE_FOLDER . 'Pending.php');
3233
define('FAILURE_URL', EXAMPLE_BASE_FOLDER . 'Failure.php');
3334
define('RETURN_CONTROLLER_URL', EXAMPLE_BASE_FOLDER . 'ReturnController.php');

examples/Create.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 success page for the example payments.
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_once __DIR__ . '/Constants.php';
25+
26+
session_start();
27+
28+
$additionalPaymentInformation = $_SESSION['additionalPaymentInformation'] ?? null;
29+
$shortId = $_SESSION['ShortId'] ?? null;
30+
$paymentId = $_SESSION['PaymentId'] ?? null;
31+
$paymentTypeId = $_SESSION['PaymentTypeId'] ?? null;
32+
$isAuthorizeTransaction = $_SESSION['isAuthorizeTransaction'] ?? false;
33+
34+
?>
35+
36+
<!DOCTYPE html>
37+
<html lang="en">
38+
<head>
39+
<meta charset="UTF-8">
40+
<title>Unzer UI Examples</title>
41+
42+
<link rel="stylesheet" href="https://static.unzer.com/v1/unzer.css" />
43+
</head>
44+
<body>
45+
<h1 id="result">Create</h1>
46+
<p>
47+
The payment is in create state, meaning the Payment page was not used for a payment yet.<br>
48+
The payment also stays in this state when the customer clicked the "Back to merchant" button or closed the browser tab.<br>
49+
It is still active and could be used by the customer for the current payment.<br>
50+
<?php
51+
echo 'Paypage-URL: <a href="' . $_SESSION['paypageId'] . '">Payment page</a>';
52+
53+
if (!empty($additionalPaymentInformation)) {
54+
echo $additionalPaymentInformation;
55+
}
56+
57+
if ($shortId !== null) {
58+
$defaultTransactionMessage = '<p>Please look for ShortId ' . $shortId . ' in Unzer Insights to see the transaction.</p>';
59+
$paylaterTransactionMessage = '<p>Please use the "descriptor" to look for the transaction in the Unzer Pay Later Merchant Portal.</p>';
60+
echo preg_match('/[\d]{4}.[\d]{4}.[\d]{4}/', $shortId) ? $defaultTransactionMessage : $paylaterTransactionMessage;
61+
}
62+
$paymentId = $_SESSION['PaymentId'] ?? null;
63+
if ($paymentId !== null) {
64+
echo '<p>The PaymentId is \'' . $paymentId . '\'.</p>';
65+
}
66+
67+
if ($paymentTypeId !== null) {
68+
echo '<p>The TypeId for the recurring payment is \'' . $paymentTypeId . '\'. You can use it
69+
now for subsequent transactions.</p>
70+
<form id="payment-form" class="unzerUI form" action="' . RECURRING_PAYMENT_CONTROLLER_URL . '" method="post">
71+
<input type="hidden" name="payment_type_id" value="' . $paymentTypeId . ' ">
72+
<div class="fields inline">
73+
<div class="field">
74+
<button class="unzerUI primary button fluid" id="submit-button" type="submit">Charge payment type again.</button>
75+
</div>
76+
</div>
77+
</form>';
78+
}
79+
?>
80+
</p>
81+
<p><a href=".">start again</a></p>
82+
</body>
83+
</html>

examples/ReturnController.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
5454

5555
// Retrieve the paymentId you remembered within the Controller
5656
if (!isset($_SESSION['PaymentId'])) {
57-
redirect(FAILURE_URL, 'The payment id is missing.', $clientMessage);
57+
$merchantMessage = 'The payment id is missing.';
5858
}
5959
$paymentId = $_SESSION['PaymentId'];
6060

61+
$redirectUrl = FAILURE_URL;
6162
// Catch API errors, write the message to your log and show the ClientMessage to the client.
6263
try {
6364
// Create an Unzer object using your private key and register a debug handler if you want to.
@@ -77,8 +78,18 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
7778
// The payment process has been successful.
7879
// You show the success page.
7980
// Goods can be shipped.
80-
redirect(SUCCESS_URL);
81-
} elseif ($payment->isPending()) {
81+
$redirectUrl = SUCCESS_URL;
82+
}
83+
84+
if ($payment->isCreate()) {
85+
// The payment is in create state, meaning the customer clicked the "Back to Merchant" button.
86+
// The Payment page was not used for a payment yet.
87+
// It is still active and could be used by the customer for the current payment.
88+
$_SESSION['paypageId'] = $payment->getPayPage()->getRedirectUrl();
89+
$redirectUrl = CREATE_URL;
90+
}
91+
92+
if ($payment->isPending()) {
8293
if ($transaction->isSuccess() || $transaction->isResumed()) {
8394
if ($transaction instanceof Authorization) {
8495
// Payment is ready to be captured.
@@ -91,26 +102,26 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
91102
// In any case:
92103
// * You can show the success page.
93104
// * You can set order status to pending payment
94-
redirect(SUCCESS_URL);
105+
$redirectUrl = SUCCESS_URL;
95106
} elseif ($transaction->isPending()) {
107+
// In cases of a redirect to an external service (e.g. 3D secure, PayPal, etc) it sometimes takes time for
108+
// the payment to update it's status after redirect into shop.
109+
// In this case the payment and the transaction are pending at first and change to cancel or success later.
110+
111+
// Use the webhooks feature to stay informed about changes of payment and transaction (e.g. cancel, success)
112+
// then you can handle the states as shown above in transaction->isSuccess() branch.
113+
$redirectUrl = PENDING_URL;
96114

97115
// The initial transaction of invoice types will not change to success but stay pending.
98116
$paymentType = $payment->getPaymentType();
99117
if ($paymentType instanceof Prepayment || $paymentType->isInvoiceType()) {
100118
// Awaiting payment by the customer.
101119
// Goods can be shipped immediately except for Prepayment type.
102-
redirect(SUCCESS_URL);
120+
$redirectUrl = SUCCESS_URL;
103121
}
104-
105-
// In cases of a redirect to an external service (e.g. 3D secure, PayPal, etc) it sometimes takes time for
106-
// the payment to update it's status after redirect into shop.
107-
// In this case the payment and the transaction are pending at first and change to cancel or success later.
108-
109-
// Use the webhooks feature to stay informed about changes of payment and transaction (e.g. cancel, success)
110-
// then you can handle the states as shown above in transaction->isSuccess() branch.
111-
redirect(PENDING_URL);
112122
}
113123
}
124+
114125
// If the payment is neither success nor pending something went wrong.
115126
// In this case do not create the order or cancel it if you already did.
116127
// Redirect to an error page in your shop and show a message if you want.
@@ -122,11 +133,11 @@ function redirect($url, $merchantMessage = '', $clientMessage = '')
122133
$clientMessage = $transaction->getMessage()->getCustomer();
123134
}
124135
} catch (UnzerApiException $e) {
136+
// Write the merchant message to your log.
137+
// Show the client message to the customer (it is localized).
125138
$merchantMessage = $e->getMerchantMessage();
126139
$clientMessage = $e->getClientMessage();
127140
} catch (RuntimeException $e) {
128141
$merchantMessage = $e->getMessage();
129142
}
130-
// Write the merchant message to your log.
131-
// Show the client message to the customer (it is localized).
132-
redirect(FAILURE_URL, $merchantMessage, $clientMessage);
143+
redirect($redirectUrl, $merchantMessage, $clientMessage);

src/Adapter/CurlAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct()
4949
/**
5050
* {@inheritDoc}
5151
*/
52-
public function init($url, $payload = null, $httpMethod = HttpAdapterInterface::REQUEST_GET): void
52+
public function init(string $url, string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void
5353
{
5454
$timeout = EnvironmentService::getTimeout();
5555
$curlVerbose = EnvironmentService::isCurlVerbose();

src/Adapter/HttpAdapterInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ interface HttpAdapterInterface
3535
/**
3636
* Initializes the request.
3737
*
38-
* @param string $url The full url to connect to.
39-
* @param string $payload Json encoded payload string.
40-
* @param string $httpMethod The Http method to perform.
38+
* @param string $url The full url to connect to.
39+
* @param string|null $payload Json encoded payload string.
40+
* @param string $httpMethod The Http method to perform.
4141
*/
42-
public function init($url, $payload = null, $httpMethod = HttpAdapterInterface::REQUEST_GET): void;
42+
public function init(string $url, string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void;
4343

4444
/**
4545
* Executes the request and returns the response.

0 commit comments

Comments
 (0)