Skip to content

Commit

Permalink
Merge pull request #151 from unzerdev/CC-400/upl_installment_example
Browse files Browse the repository at this point in the history
[CC-397] Adjust Examples to hide not supported operations.
  • Loading branch information
Ryouzanpaku authored Jul 5, 2023
2 parents 1f9358b + c0008cb commit 13134f6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
14 changes: 12 additions & 2 deletions examples/Backend/Failure.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@

<!DOCTYPE html>
<html lang="en">
<body>
<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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"/>
</head>
<body style="margin: 70px 70px 0;">
<div class="ui container segment">
<h1 id="result">Failure</h1>
<p>
There has been an error performing the transaction
Expand All @@ -47,6 +56,7 @@
echo '<p>Back to <a href="ManagePayment.php">Manage Payment</a> page.</p>';
?>
</p>
<p><a href="..">start again</a></p>
<a href=".." class="ui green button">start again</a>
</div>
</body>
</html>
18 changes: 15 additions & 3 deletions examples/Backend/ManagePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* @package UnzerSDK\examples
*/

use UnzerSDK\Resources\PaymentTypes\Paypal;

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

Expand All @@ -39,6 +41,10 @@
<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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"/>
Expand Down Expand Up @@ -67,7 +73,8 @@
echo preg_match('/[\d]{4}.[\d]{4}.[\d]{4}/', $shortId) ? $defaultTransactionMessage : $paylaterTransactionMessage;
}

echo '<h2>Charge payment</h2>
if ($payment->getAmount()->getRemaining() > 0 && $payment->getAuthorization() !== null) {
echo '<h2>Charge payment</h2>
<p>You can use the payment ID to charge the payment.</p>
<form id="payment-form" class="unzerUI form" action="' . CHARGE_PAYMENT_CONTROLLER_URL . '" method="post">
<input type="hidden" name="payment_id" value="' . $paymentId . ' ">
Expand All @@ -77,8 +84,10 @@
</div>
</div>
</form><br>';
}

echo '<h2>Cancel payment.</h2>
if ($payment->getPaymentType()->supportsDirectPaymentCancel() && !$payment->isCanceled()) {
echo '<h2>Cancel payment.</h2>
<p>You can use the payment ID to cancel the payment.</p>
<form id="payment-form" class="unzerUI form" action="' . CANCEL_PAYMENT_CONTROLLER_URL . '" method="post">
<input type="hidden" name="payment_id" value="' . $paymentId . ' ">
Expand All @@ -88,8 +97,10 @@
</div>
</div>
</form><br>';
}

echo '<h2>PayPal Express only: Finalize a transaction</h2>
if ($payment->getPaymentType() instanceof Paypal) {
echo '<h2>PayPal Express only: Finalize a transaction</h2>
<p>You can finalize a transaction in resumed state.</p>
<form id="payment-form" class="unzerUI form" action="' . UPDATE_TRANSACTION_CONTROLLER_URL . '" method="post">
<input type="hidden" name="payment_id" value="' . $paymentId . ' ">
Expand All @@ -101,6 +112,7 @@
</div>
</div>
</form><br>';
}

?>
<a href=".." class="ui green button">start again</a>
Expand Down
2 changes: 2 additions & 0 deletions examples/Failure.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"/>
</head>
Expand Down
2 changes: 2 additions & 0 deletions examples/Pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"/>
</head>
Expand Down
18 changes: 14 additions & 4 deletions examples/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
* @package UnzerSDK\examples
*/

use UnzerSDK\Unzer;

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

session_start();

Expand All @@ -38,7 +41,8 @@
<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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"/>

Expand All @@ -60,9 +64,13 @@
$paylaterTransactionMessage = '<p>Please use the "descriptor" to look for the transaction in the Unzer Pay Later Merchant Portal.</p>';
echo preg_match('/[\d]{4}.[\d]{4}.[\d]{4}/', $shortId) ? $defaultTransactionMessage : $paylaterTransactionMessage;
}
$paymentId = $_SESSION['PaymentId'] ?? null;

$isManageable = false;
if ($paymentId !== null) {
echo '<p>The PaymentId of your transaction is \'' . $paymentId . '\'.</p>';
$unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY);
$payment = $unzer->fetchPayment($paymentId);
$isManageable = $payment->getPaymentType()->supportsDirectPaymentCancel() || $payment->getAuthorization() !== null;
}

if ($paymentTypeId !== null) {
Expand All @@ -77,8 +85,10 @@
</div>
</form>';
}
$isManageable = $paymentId !== null && $isAuthorizeTransaction;
echo '<p>As a merchant you can charge or cancel the Payment here: <a href="./Backend/ManagePayment.php">Manage Payment</a></p>';

if ($isManageable) {
echo '<p>As a merchant you can charge or cancel the Payment here: <a href="./Backend/ManagePayment.php">Manage Payment</a></p>';
}
?>
<a href="." class="ui green button">start again</a>
</div>
Expand Down

0 comments on commit 13134f6

Please sign in to comment.