diff --git a/samples/php8/ecom-server/KodyServiceMock/MockCancelRequest.php b/samples/php8/ecom-server/KodyServiceMock/MockCancelRequest.php deleted file mode 100644 index 83a6110..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockCancelRequest.php +++ /dev/null @@ -1,31 +0,0 @@ -store_id = $store_id; - } - - public function setAmount($amount) - { - $this->amount = $amount; - } - - public function setTerminalId($terminal_id) - { - $this->terminal_id = $terminal_id; - } - - public function setOrderId($order_id) - { - $this->order_id = $order_id; - } -} diff --git a/samples/php8/ecom-server/KodyServiceMock/MockCancelResponse.php b/samples/php8/ecom-server/KodyServiceMock/MockCancelResponse.php deleted file mode 100644 index 2f83e52..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockCancelResponse.php +++ /dev/null @@ -1,18 +0,0 @@ -status = $status; - } - - public function getStatus() - { - return $this->status; - } -} diff --git a/samples/php8/ecom-server/KodyServiceMock/MockKodyPayTerminalServiceClient.php b/samples/php8/ecom-server/KodyServiceMock/MockKodyPayTerminalServiceClient.php deleted file mode 100644 index cb67a2d..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockKodyPayTerminalServiceClient.php +++ /dev/null @@ -1,47 +0,0 @@ -setTerminalId('MOCK_TERMINAL_1')->setOnline(true); - $response->setTerminals([$terminal]); - return [$response, null]; - } - - public function Pay($request, $metadata = [], $options = []) - { - // Mock response stream with a generator - return new class { - public function responses() - { - yield (new PayResponse())->setStatus(PaymentStatus::PENDING)->setOrderId('MOCK_ORDER_ID'); - yield (new PayResponse())->setStatus(PaymentStatus::SUCCESS); - } - }; - } - - public function Cancel($request, $metadata = [], $options = []) - { - $response = new CancelResponse(); - $response->setStatus(PaymentStatus::CANCELLED); - return [$response, null]; - } - - public function PaymentDetails($request, $metadata = [], $options = []) - { - $response = new PayResponse(); - $response->setStatus(PaymentStatus::SUCCESS) - ->setOrderId($request->getOrderId()) - ->setDateCreated((new \Google\Protobuf\Timestamp())->setSeconds(time())) - ->setDatePaid((new \Google\Protobuf\Timestamp())->setSeconds(time() + 600)) - ->setFailureReason('') - ->setExtPaymentRef('MOCK_EXT_REF') - ->setReceiptJson(json_encode(['items' => [['name' => 'Mock Item', 'price' => 1000]]])); - return [$response, null]; - } -} diff --git a/samples/php8/ecom-server/KodyServiceMock/MockPayRequest.php b/samples/php8/ecom-server/KodyServiceMock/MockPayRequest.php deleted file mode 100644 index b75f96b..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockPayRequest.php +++ /dev/null @@ -1,25 +0,0 @@ -store_id = $store_id; - } - - public function setAmount($amount) - { - $this->amount = $amount; - } - - public function setTerminalId($terminal_id) - { - $this->terminal_id = $terminal_id; - } -} diff --git a/samples/php8/ecom-server/KodyServiceMock/MockPayResponse.php b/samples/php8/ecom-server/KodyServiceMock/MockPayResponse.php deleted file mode 100644 index c1980d3..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockPayResponse.php +++ /dev/null @@ -1,61 +0,0 @@ -status = $status; - } - - public function getStatus() - { - return $this->status; - } - - public function setOrderId($order_id) - { - $this->order_id = $order_id; - } - - public function getOrderId() - { - return $this->order_id; - } - - public function setDateCreated(Timestamp $date_created) - { - $this->date_created = $date_created; - } - - public function setDatePaid(Timestamp $date_paid) - { - $this->date_paid = $date_paid; - } - - public function setFailureReason($failure_reason) - { - $this->failure_reason = $failure_reason; - } - - public function setReceiptJson($receipt_json) - { - $this->receipt_json = $receipt_json; - } - - public function setExtPaymentRef($ext_payment_ref) - { - $this->ext_payment_ref = $ext_payment_ref; - } -} diff --git a/samples/php8/ecom-server/KodyServiceMock/MockPaymentDetailsRequest.php b/samples/php8/ecom-server/KodyServiceMock/MockPaymentDetailsRequest.php deleted file mode 100644 index aec5d9d..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockPaymentDetailsRequest.php +++ /dev/null @@ -1,19 +0,0 @@ -store_id = $store_id; - } - - public function setOrderId($order_id) - { - $this->order_id = $order_id; - } -} diff --git a/samples/php8/ecom-server/KodyServiceMock/MockTerminal.php b/samples/php8/ecom-server/KodyServiceMock/MockTerminal.php deleted file mode 100644 index 0efc042..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockTerminal.php +++ /dev/null @@ -1,29 +0,0 @@ -terminal_id = $terminal_id; - } - - public function setOnline($online) - { - $this->online = $online; - } - - public function getTerminalId() - { - return $this->terminal_id; - } - - public function isOnline() - { - return $this->online; - } -} diff --git a/samples/php8/ecom-server/KodyServiceMock/MockTerminalsRequest.php b/samples/php8/ecom-server/KodyServiceMock/MockTerminalsRequest.php deleted file mode 100644 index 87f51d6..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockTerminalsRequest.php +++ /dev/null @@ -1,13 +0,0 @@ -store_id = $store_id; - } -} diff --git a/samples/php8/ecom-server/KodyServiceMock/MockTerminalsResponse.php b/samples/php8/ecom-server/KodyServiceMock/MockTerminalsResponse.php deleted file mode 100644 index 78ffc44..0000000 --- a/samples/php8/ecom-server/KodyServiceMock/MockTerminalsResponse.php +++ /dev/null @@ -1,18 +0,0 @@ -terminals = $terminals; - } - - public function getTerminals() - { - return $this->terminals; - } -} diff --git a/samples/php8/ecom-server/public/checkout.php b/samples/php8/ecom-server/public/checkout.php index 36e3fb3..1565621 100644 --- a/samples/php8/ecom-server/public/checkout.php +++ b/samples/php8/ecom-server/public/checkout.php @@ -68,7 +68,7 @@ function generateRandomOrderId($length = 8) { - + @@ -85,8 +85,8 @@ function generateRandomOrderId($length = 8) {

Developer Information

This page demonstrates how to initiate a payment. The form above collects the necessary information and sends a payment request to the backend.

diff --git a/samples/php8/ecom-server/public/checkout_payment.php b/samples/php8/ecom-server/public/checkout_payment.php index 33e0f58..265d46c 100644 --- a/samples/php8/ecom-server/public/checkout_payment.php +++ b/samples/php8/ecom-server/public/checkout_payment.php @@ -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()]); @@ -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(); diff --git a/samples/php8/ecom-server/public/config.php b/samples/php8/ecom-server/public/config.php index bf8755a..432baf4 100644 --- a/samples/php8/ecom-server/public/config.php +++ b/samples/php8/ecom-server/public/config.php @@ -1,4 +1,5 @@ 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; diff --git a/samples/php8/ecom-server/public/terminal_submit_payment.php b/samples/php8/ecom-server/public/terminal_submit_payment.php index f2dfaa2..8bba89e 100644 --- a/samples/php8/ecom-server/public/terminal_submit_payment.php +++ b/samples/php8/ecom-server/public/terminal_submit_payment.php @@ -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'])) { diff --git a/samples/php8/ecom-server/public/terminals_fetch.php b/samples/php8/ecom-server/public/terminals_fetch.php index f854ccc..bd04f4f 100644 --- a/samples/php8/ecom-server/public/terminals_fetch.php +++ b/samples/php8/ecom-server/public/terminals_fetch.php @@ -1,6 +1,5 @@