Skip to content

Commit 09a3444

Browse files
authored
Merge pull request #58 from unzerdev/develop
Release 1.1.4.1
2 parents e18bf5e + 7008f90 commit 09a3444

File tree

50 files changed

+876
-95
lines changed

Some content is hidden

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

50 files changed

+876
-95
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
All notable changes to this project will be documented in this file.
33

44
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).
5+
## [1.1.4.1](https://github.com/unzerdev/php-sdk/compare/1.1.4.0..1.1.4.1)
6+
### Added
7+
* Added Apple Pay example.
8+
9+
### Changed
10+
* Adjust `cancelAmount` logic to work properly with Invoice Secured payments.
11+
* Updated jQuery and frameworks used in examples.
12+
* Fixed failing card tests.
13+
* Several minor improvements.
514

615
## [1.1.4.0](https://github.com/unzerdev/php-sdk/compare/1.1.3.0..1.1.4.0)
716
### Added

examples/Alipay/index.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
<head>
3737
<meta charset="UTF-8">
3838
<title>Unzer UI Examples</title>
39-
<script src="https://code.jquery.com/jquery-3.5.1.min.js"
40-
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
39+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
40+
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
41+
crossorigin="anonymous"></script>
4142

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

examples/Applepay/Constants.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* This file defines the constants needed for the Apple Pay example.
4+
*
5+
* Copyright (C) 2021 - 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+
* @author David Owusu <[email protected]>
22+
*
23+
* @package UnzerSDK\examples
24+
*/
25+
26+
require_once __DIR__ . '/../Constants.php';
27+
28+
define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'Applepay');
29+
define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php');

examples/Applepay/Controller.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* This is the controller for the Apple Pay example.
4+
* It is called when the pay button on the index page is clicked.
5+
*
6+
* Copyright (C) 2021 - 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+
* @author David Owusu <[email protected]>
23+
*
24+
* @package UnzerSDK\examples
25+
*/
26+
27+
/** Require the constants of this example */
28+
require_once __DIR__ . '/Constants.php';
29+
30+
/** @noinspection PhpIncludeInspection */
31+
/** Require the composer autoloader file */
32+
require_once __DIR__ . '/../../../../autoload.php';
33+
34+
use UnzerSDK\examples\ExampleDebugHandler;
35+
use UnzerSDK\Exceptions\UnzerApiException;
36+
use UnzerSDK\Unzer;
37+
38+
session_start();
39+
session_unset();
40+
41+
$clientMessage = 'Something went wrong. Please try again later.';
42+
$merchantMessage = 'Something went wrong. Please try again later.';
43+
44+
function redirect($url, $merchantMessage = '', $clientMessage = '')
45+
{
46+
$_SESSION['merchantMessage'] = $merchantMessage;
47+
$_SESSION['clientMessage'] = $clientMessage;
48+
header('Location: ' . $url);
49+
die();
50+
}
51+
52+
// These lines are just for this example
53+
$jsonData = json_decode(file_get_contents('php://input'), false);
54+
$paymentTypeId = $jsonData->typeId;
55+
$transactionType = $jsonData->transaction_type ?? 'authorize';
56+
57+
// You will need the id of the payment type created in the frontend (index.php)
58+
if (empty($paymentTypeId)) {
59+
echo json_encode(['result' => false]);
60+
return;
61+
}
62+
63+
// Catch API errors, write the message to your log and show the ClientMessage to the client.
64+
try {
65+
// Create an Unzer object using your private key and register a debug handler if you want to.
66+
$unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY);
67+
$unzer->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler());
68+
69+
switch ($transactionType) {
70+
case 'charge':
71+
$transaction = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL);
72+
break;
73+
default:
74+
$transaction = $unzer->authorize(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL);
75+
break;
76+
}
77+
78+
// You'll need to remember the paymentId for later in the ReturnController
79+
$_SESSION['PaymentId'] = $transaction->getPaymentId();
80+
$_SESSION['ShortId'] = $transaction->getShortId();
81+
82+
if ($transaction->isSuccess()) {
83+
echo json_encode(['transactionStatus' => 'success']);
84+
return;
85+
}
86+
if ($transaction->isPending()) {
87+
echo json_encode(['transactionStatus' => 'pending']);
88+
return;
89+
}
90+
} catch (UnzerApiException $e) {
91+
$_SESSION['merchantMessage'] = $e->getMerchantMessage();
92+
$_SESSION['clientMessage'] = $e->getClientMessage();
93+
} catch (RuntimeException $e) {
94+
$_SESSION['merchantMessage'] = $e->getMessage();
95+
}
96+
97+
echo json_encode(['transactionStatus' => 'error']);

0 commit comments

Comments
 (0)