From 80215ad97ac4e8b795efd58226a7c50f1a19f3dc Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Mon, 5 Feb 2024 17:25:24 +0100 Subject: [PATCH 1/3] [CC-724] Add googlepay example --- examples/Googlepay/Constants.php | 9 ++ examples/Googlepay/Controller.php | 95 +++++++++++++++ examples/Googlepay/index.php | 193 ++++++++++++++++++++++++++++++ examples/index.php | 12 ++ 4 files changed, 309 insertions(+) create mode 100644 examples/Googlepay/Constants.php create mode 100644 examples/Googlepay/Controller.php create mode 100644 examples/Googlepay/index.php diff --git a/examples/Googlepay/Constants.php b/examples/Googlepay/Constants.php new file mode 100644 index 00000000..863a4e4f --- /dev/null +++ b/examples/Googlepay/Constants.php @@ -0,0 +1,9 @@ +typeId; +$transactionType = $jsonData->transaction_type ?? 'authorize'; + +// You will need the id of the payment type created in the frontend (index.php) +if (empty($paymentTypeId)) { + echo json_encode(['result' => false]); + return; +} + +$transactionResult = [ + TRANSACTION_STATUS_KEY => 'error', + REDIRECT_URL_KEY => '' +]; + +// 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()); + + if ($transactionType === 'charge') { + $charge = new \UnzerSDK\Resources\TransactionTypes\Charge(12.32, 'EUR', RETURN_CONTROLLER_URL); + $transaction = $unzer->performCharge($charge, $paymentTypeId); + } else { + $authorize = new \UnzerSDK\Resources\TransactionTypes\Authorization(12.32, 'EUR', RETURN_CONTROLLER_URL); + $transaction = $unzer->performAuthorization($authorize, $paymentTypeId); + } + + // You'll need to remember the paymentId for later in the ReturnController + $_SESSION['PaymentId'] = $transaction->getPaymentId(); + $_SESSION['ShortId'] = $transaction->getShortId(); + + $redirectUrl = $transaction->getRedirectUrl(); + + if (!empty($redirectUrl)) { + $transactionResult[REDIRECT_URL_KEY] = $redirectUrl; + } + + if ($transaction->isSuccess()) { + $transactionResult[TRANSACTION_STATUS_KEY] = 'success'; + echo json_encode($transactionResult); + return; + } + if ($transaction->isPending()) { + $transactionResult[TRANSACTION_STATUS_KEY] = 'pending'; + + echo json_encode($transactionResult); + return; + } +} catch (UnzerApiException $e) { + $_SESSION['merchantMessage'] = $e->getMerchantMessage(); + $_SESSION['clientMessage'] = $e->getClientMessage(); +} catch (RuntimeException $e) { + $_SESSION['merchantMessage'] = $e->getMessage(); +} + +echo json_encode($transactionResult); diff --git a/examples/Googlepay/index.php b/examples/Googlepay/index.php new file mode 100644 index 00000000..b878cb08 --- /dev/null +++ b/examples/Googlepay/index.php @@ -0,0 +1,193 @@ + + + + + + + Unzer UI Examples + + + + + + + + + + +

Click here to open our test data in new tab.
+

+ +
+ +
+ +
+
+ + +
+
+
+
+ + +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+ + + +
+
+ + + + + diff --git a/examples/index.php b/examples/index.php index 44dcadb2..05a0c51a 100755 --- a/examples/index.php +++ b/examples/index.php @@ -155,6 +155,18 @@ function printMessage($type, $title, $text) Try +
+
+
+ Google Pay +
+
+
+
+
+ Try +
+
From 1036be9e346805534891548197422846b5513878 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Tue, 6 Feb 2024 14:03:04 +0100 Subject: [PATCH 2/3] [CC-724] Add config to set channel for googlepay used in UI. --- examples/Googlepay/index.php | 2 +- examples/_enableExamples.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/Googlepay/index.php b/examples/Googlepay/index.php index b878cb08..8ddae4d9 100644 --- a/examples/Googlepay/index.php +++ b/examples/Googlepay/index.php @@ -74,7 +74,7 @@