-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from unzerdev/develop
1.1.4.0 release
- Loading branch information
Showing
31 changed files
with
804 additions
and
66 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
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
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,95 @@ | ||
<?php | ||
|
||
/* | ||
* Controller for subsequent transactions. | ||
* | ||
* Copyright (C) 2021 - 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/ | ||
* | ||
* @author David Owusu <development@unzer.com> | ||
* | ||
* @package UnzerSDK | ||
* | ||
*/ | ||
|
||
/** Require the constants of this example */ | ||
require_once __DIR__ . '/Constants.php'; | ||
|
||
/** Require the composer autoloader file */ | ||
/** @noinspection PhpIncludeInspection */ | ||
require_once __DIR__ . '/../../../../autoload.php'; | ||
|
||
use UnzerSDK\examples\ExampleDebugHandler; | ||
use UnzerSDK\Exceptions\UnzerApiException; | ||
use UnzerSDK\Resources\CustomerFactory; | ||
use UnzerSDK\Unzer; | ||
|
||
session_start(); | ||
|
||
$clientMessage = 'Something went wrong. Please try again later.'; | ||
$merchantMessage = 'Something went wrong. Please try again later.'; | ||
$debugHandler = new ExampleDebugHandler(); | ||
|
||
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['payment_type_id'])) { | ||
redirect(FAILURE_URL, 'Resource id is missing!', $clientMessage); | ||
} | ||
$paymentTypeId = $_POST['payment_type_id']; | ||
|
||
// Reuse the recurrence type of the recurring transaction, if set. | ||
$recurrenceTyp = $_SESSION['recurrenceType'] ?? null; | ||
|
||
// 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($debugHandler); | ||
|
||
$customer = CustomerFactory::createCustomer('Max', 'Mustermann'); | ||
$customer->setEmail('test@test.com'); | ||
|
||
$transaction = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, true, null, null, $recurrenceTyp); | ||
|
||
// You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) | ||
$_SESSION['PaymentTypeId'] = $paymentTypeId; | ||
$_SESSION['ShortId'] = $transaction->getShortId(); | ||
|
||
// Redirect to the failure page or to success depending on the state of the transaction | ||
$redirect = !empty($transaction->getRedirectUrl()); | ||
if (!$redirect && $transaction->isSuccess()) { | ||
redirect(SUCCESS_URL); | ||
} elseif ($redirect && $transaction->isPending()) { | ||
redirect(FAILURE_URL, 'Transaction initiated by merchant should not redirect to 3ds Page. The customer needs to | ||
do the 3ds authentication first for that payment type.'); | ||
} | ||
|
||
// Check the result message of the transaction 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); |
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
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
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
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,38 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the different recurrence types. | ||
* | ||
* Copyright (C) 2021 - 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/ | ||
* | ||
* @author David Owusu <development@unzer.com> | ||
* | ||
* @package UnzerSDK\Constants | ||
*/ | ||
namespace UnzerSDK\Constants; | ||
|
||
class RecurrenceTypes | ||
{ | ||
/** @var string Recurring with a defined interval and a defined amount.*/ | ||
public const SCHEDULED = 'scheduled'; | ||
|
||
/** @var string Recurring with a undefined interval and/or an undefined amount.*/ | ||
public const UNSCHEDULED = 'unscheduled'; | ||
|
||
/** @var string If the payment type should be used again for future transactions.*/ | ||
public const ONE_CLICK = 'oneclick'; | ||
} |
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
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
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
Oops, something went wrong.