130 lines
4.4 KiB
PHP
130 lines
4.4 KiB
PHP
<?php
|
|
$dir = dirname( __DIR__, 3 );
|
|
require_once $dir . "/admin/core/api/php/includes/init.php";
|
|
require_once dirname( __DIR__, 3 ) . "/admin/core/api/php/includes/functions.php";
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use Psr\Http\Server\MiddlewareInterface;
|
|
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
|
|
use Slim\Factory\AppFactory;
|
|
require_once dirname( __DIR__, 3 ) . "/admin/core/api/php/includes/libs/slim/vendor/autoload.php";
|
|
|
|
|
|
class JsonBodyParserMiddleware implements MiddlewareInterface
|
|
{
|
|
public function process(Request $request, RequestHandler $handler): Response
|
|
{
|
|
$contentType = $request->getHeaderLine('Content-Type');
|
|
if (strstr($contentType, 'application/json')) {
|
|
$contents = json_decode(file_get_contents('php://input'), true);
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
|
$request = $request->withParsedBody($contents);
|
|
}
|
|
}
|
|
|
|
return $handler->handle($request);
|
|
}
|
|
}
|
|
|
|
|
|
$app = AppFactory::create();
|
|
$app->addErrorMiddleware(true, true, true);
|
|
$app->add(new JsonBodyParserMiddleware());
|
|
|
|
$app->post('/v1/payments/initialize_direct_payments', function (Request $request, Response $response, $args) {
|
|
ApiCheck($request, $response, $args, function($headerCall,$options) use ($request, $response, $args){
|
|
$pay = new \AppfactoryStudio\Plugins\Payments();
|
|
$pay->initialize_direct_payments($options,function($obj) use ($request, $response, $args){
|
|
$response->getBody()->write(json_encode($obj ));
|
|
});
|
|
});
|
|
sleep(2);
|
|
return $response;
|
|
});
|
|
|
|
$app->post('/v1/payments/paypal/orders', function (Request $request, Response $response, $args) {
|
|
ApiCheck($request, $response, $args, function($headerCall,$options) use ($request, $response, $args){
|
|
$pay = new \AppfactoryStudio\Plugins\Payments();
|
|
$pay->apicall_paypal_orders($options,function($obj) use ($request, $response, $args){
|
|
$response->getBody()->write(json_encode($obj ));
|
|
});
|
|
});
|
|
sleep(2);
|
|
return $response;
|
|
});
|
|
|
|
$app->post('/v1/payments/paypal/orders/{order}/capture', function (Request $request, Response $response, $args) {
|
|
ApiCheck($request, $response, $args, function($headerCall,$options) use ($request, $response, $args){
|
|
// $pay = new \AppfactoryStudio\Plugins\Payments();
|
|
// $pay->apicall_paypal_orders($options,function($obj) use ($request, $response, $args){
|
|
// $response->getBody()->write(json_encode($obj ));
|
|
// });
|
|
$response->getBody()->write(json_encode($args ));
|
|
});
|
|
sleep(2);
|
|
return $response;
|
|
});
|
|
|
|
|
|
|
|
// Catch-all route to serve a 404 Not Found page if none of the routes match
|
|
// NOTE: make sure this route is defined last
|
|
// $app->map(['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], '/{routes:.+}', function($req, $res) {
|
|
// $handler = $this->notFoundHandler; // handle using the default Slim page not found handler
|
|
// return $handler($req, $res);
|
|
// });
|
|
|
|
|
|
$app->run();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $router = new AppfactoryStudio\Core\Router();
|
|
|
|
// $router->get('/direct_payment',[AppfactoryStudio\Plugins\Payments::class, 'get_direct_payment']);
|
|
// $router->get('/',[AppfactoryStudio\Plugins\Payments::class, 'init_home']);
|
|
|
|
|
|
// // $router->get('/direct_payments',[AppfactoryStudio\Plugins\Payments::class, 'api_direct_payment']);
|
|
// $router->post('/direct_payments',[AppfactoryStudio\Plugins\Payments::class, 'api_direct_payment']);
|
|
|
|
// $router->post('/save_handler',[AppfactoryStudio\Plugins\Payments::class, 'api_direct_payment_save_handler']);
|
|
|
|
// $router->post('/check_membership_purchase',[AppfactoryStudio\Plugins\Payments::class, 'check_membership_purchase']);
|
|
|
|
|
|
// $router->post('/stripe_create_subscription',[AppfactoryStudio\Plugins\Payments::class, 'apicall_stripe_create_subscription']);
|
|
// $router->post('/stripe_create_customer',[AppfactoryStudio\Plugins\Payments::class, 'apicall_stripe_create_customer']);
|
|
// $router->post('/stripe_check_charge',[AppfactoryStudio\Plugins\Payments::class, 'apicall_stripe_check_charge']);
|
|
|
|
|
|
// $router->post('/paypal',[AppfactoryStudio\Plugins\Payments::class, 'apicall_paypal']);
|
|
|
|
|
|
// https://api.appfactory.studio/v1/pay/direct_payment
|
|
// https://api-sandbox.appfactory.studio/v1/pay/direct_payment
|
|
|
|
// echo $router->UrlResolve("/v1/payments", $_SERVER['REQUEST_URI'], strtolower($_SERVER['REQUEST_METHOD']));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|