Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning entire order status response in handleJuspayResponse #240

Open
wants to merge 1 commit into
base: expresscheckout-php-sdk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions expresscheckout-php-sdk/Program.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public function orderStatus() {
$requestOption = new RequestOptions();
$requestOption->withCustomerId("testing-customer-one");
$order = Order::status($params, $requestOption);
echo "id: ". $order->orderId . PHP_EOL;
echo "amount: ". $order->amount . PHP_EOL;
echo "status: " . $order->status . PHP_EOL;
echo "order env" . getenv("ORDER_ID") . PHP_EOL;
echo "order: ". json_encode($order->__get("*")) . PHP_EOL;
} catch ( JuspayException $e ) {
echo "error code" . $e->getHttpResponseCode() . PHP_EOL;
echo "error message: " . $e->getErrorMessage() . PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion expresscheckout-php-sdk/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"process-timeout":0
},
"scripts": {
"run_server": "composer install && php -S 0.0.0.0:5000 router.php",
"run_server": "composer install --no-dev && php -S 0.0.0.0:5000 router.php",
"run_app": "composer install && php Program.php"
},
"authors": [
Expand Down
28 changes: 2 additions & 26 deletions expresscheckout-php-sdk/handleJuspayResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,12 @@ function getOrder($orderId, $config) {
}
}

function orderStatusMessage ($order) {
$response = array("order_id" => $order->orderId);
switch ($order->status) {
case "CHARGED":
$response += ["message" => "order payment done successfully"];
break;
case "PENDING":
case "PENDING_VBV":
$response += ["message" => "order payment pending"];
break;
case "AUTHENTICATION_FAILED":
$response += ["message" => "authentication failed"];
break;
case "AUTHORIZATION_FAILED":
$response += ["message"=> "order payment authorization failed"];
break;
default:
$response += ["message"=> "order status " . $order->status];
}
$response += ["order_status"=> $order->status];
return $response;
}

// POST ROUTE
if (isset($_POST["order_id"])) {
try {
$orderId = $_POST["order_id"];
$order = getOrder($orderId, $config);
$response = orderStatusMessage($order);
$response = $order->__get("*");

}
catch (JuspayException $e ) {
Expand All @@ -66,12 +43,11 @@ function orderStatusMessage ($order) {
} else if (isset($_GET["order_id"])) { // GET ROUTE
$orderId = $_GET["order_id"];
$order = getOrder($orderId, $config);
$response = orderStatusMessage($order);
$response = $order->__get("*");
} else {
http_response_code(400);
$response = array('message' => 'order id not found');
}
header('Content-Type: application/json');
echo json_encode($response);
?>

4 changes: 1 addition & 3 deletions expresscheckout-php-sdk/initiateJuspayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

$config = ServerEnv::$config;

$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, true);
header('Content-Type: application/json');
$orderId = uniqid();
$amount = mt_rand(1,100);
try {
Expand All @@ -37,5 +34,6 @@
$response = array("message" => $e->getErrorMessage());
error_log($e->getErrorMessage());
}
header('Content-Type: application/json');
echo json_encode($response);
?>
26 changes: 0 additions & 26 deletions expresscheckout-php-sdk/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,5 @@
}
} else {
shell_exec("composer_installer.sh");
if (!extension_loaded("gmp")) {
$output=null;
$exitCode=null;
exec('sh ext_installer.sh gmp', $output, $exitCode);
if ($exitCode === 0) {
print_r($output);
echo PHP_EOL. "gmp extension added successfully" . PHP_EOL;
} else {
print_r($output);
echo PHP_EOL . "failed enabling gmp extension manually install from: https://www.php.net/manual/en/gmp.installation.php" . PHP_EOL;
if (!extension_loaded("bcmath")) {
$output=null;
$exitCode=null;
exec('sh package_install.sh bcmath', $output, $exitCode);
if ($exitCode === 0) {
print_r($output);
echo PHP_EOL. "bcmath extension added successfully" . PHP_EOL;
} else {
print_r($output);
echo PHP_EOL . "failed enabling bcmath extension manually install from: https://www.php.net/manual/en/bc.installation.php" . PHP_EOL;
}
}
}
} else {
echo "gmp extension enabled" . PHP_EOL;
}
}
?>