Skip to content

Commit

Permalink
Simplifying code
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Martins committed Jul 9, 2024
1 parent 1879fda commit ed95202
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 275 deletions.
31 changes: 0 additions & 31 deletions samples/php8/ecom-server/KodyServiceMock/MockCancelRequest.php

This file was deleted.

18 changes: 0 additions & 18 deletions samples/php8/ecom-server/KodyServiceMock/MockCancelResponse.php

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions samples/php8/ecom-server/KodyServiceMock/MockPayRequest.php

This file was deleted.

61 changes: 0 additions & 61 deletions samples/php8/ecom-server/KodyServiceMock/MockPayResponse.php

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions samples/php8/ecom-server/KodyServiceMock/MockTerminal.php

This file was deleted.

13 changes: 0 additions & 13 deletions samples/php8/ecom-server/KodyServiceMock/MockTerminalsRequest.php

This file was deleted.

18 changes: 0 additions & 18 deletions samples/php8/ecom-server/KodyServiceMock/MockTerminalsResponse.php

This file was deleted.

6 changes: 3 additions & 3 deletions samples/php8/ecom-server/public/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function generateRandomOrderId($length = 8) {
<input type="number" id="amount" name="amount" value="<?php echo $randomAmount; ?>" required>

<label for="currency">Currency:</label>
<input type="text" id="currency" name="currency" value="GBP" class="readonly" readonly>
<input type="text" id="currency" name="currency" value="<?php echo $config['currency']; ?>" class="readonly" readonly>

<label for="order_id">Order ID:</label>
<input type="text" id="order_id" name="order_id" value="<?php echo $randomOrderId; ?>" required>
Expand All @@ -85,8 +85,8 @@ function generateRandomOrderId($length = 8) {
<h2>Developer Information</h2>
<p>This page demonstrates how to initiate a payment. The form above collects the necessary information and sends a payment request to the backend.</p>
<ul>
<li><strong>Amount:</strong> The amount to be charged, in minor units (e.g., 2000 for £20.00).</li>
<li><strong>Currency:</strong> The currency in which the payment will be made. This is fixed as GBP for this demo.</li>
<li><strong>Amount:</strong> The amount to be charged, in minor units (e.g., 2000 for 20.00).</li>
<li><strong>Currency:</strong> The currency in which the payment will be made. This is configured in code for this demo.</li>
<li><strong>Order ID:</strong> A unique identifier for the order. This can be changed to test different orders.</li>
<li><strong>Return URL:</strong> The URL to which the user will be redirected after the payment is completed. This is shown as a read-only field to demonstrate what the return URL will be.</li>
</ul>
Expand Down
12 changes: 4 additions & 8 deletions samples/php8/ecom-server/public/checkout_payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
use Grpc\ChannelCredentials;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$amount = $_POST['amount'];
$currency = $_POST['currency'];
$orderId = $_POST['order_id'];
$returnUrl = 'http://localhost:8080/checkout_return.php?order_id=$orderId';
$paymentReference = uniqid('pay_', true);

$client = new KodyEcomPaymentsServiceClient($config['hostname'], ['credentials' => ChannelCredentials::createSsl()]);
Expand All @@ -19,10 +15,10 @@
$request = new PaymentInitiationRequest();
$request->setStoreId($config['store_id']);
$request->setPaymentReference($paymentReference);
$request->setAmount($amount*100);
$request->setCurrency($currency);
$request->setOrderId($orderId);
$request->setReturnUrl($returnUrl);
$request->setAmount($_POST['amount']*100);
$request->setCurrency($_POST['currency']);
$request->setOrderId($_POST['order_id']);
$request->setReturnUrl($config['redirect_url'].'?order_id=$orderId');

list($response, $status) = $client->InitiatePayment($request, $metadata)->wait();

Expand Down
7 changes: 6 additions & 1 deletion samples/php8/ecom-server/public/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use Dotenv\Dotenv;
Expand All @@ -14,8 +15,12 @@
}
}

return [
$config = [
'hostname' => getenv('KODY_HOSTNAME') ?: 'grpc.kodypay.com',
'store_id' => getenv('KODY_STORE_ID') ?: '',
'api_key' => getenv('KODY_API_KEY') ?: '',
'currency' => getenv('KODY_STORE_CURRENCY') ?: '',
'redirect_url' => getenv('PAYMENT_REDIRECT_URL') ?: '',
];

return $config;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace KodyPayTerminalDemo;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/config.php';

// Check if form is submitted with required parameters
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['amount'], $_POST['tid'])) {
Expand Down
1 change: 0 additions & 1 deletion samples/php8/ecom-server/public/terminals_fetch.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

require __DIR__ . '/../vendor/autoload.php';
$config = require __DIR__ . '/config.php';

use Com\Kodypay\Grpc\Pay\V1\KodyPayTerminalServiceClient;
Expand Down

0 comments on commit ed95202

Please sign in to comment.