diff --git a/Admin/Install/Application/Shop/ShopView.php b/Admin/Install/Application/Shop/ShopView.php index 8604c9b..5b19e83 100755 --- a/Admin/Install/Application/Shop/ShopView.php +++ b/Admin/Install/Application/Shop/ShopView.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Web\{APPNAME} * @copyright Dennis Eichhorn diff --git a/Admin/Install/Application/Shop/info.json b/Admin/Install/Application/Shop/info.json index 5bafc76..3be73ac 100755 --- a/Admin/Install/Application/Shop/info.json +++ b/Admin/Install/Application/Shop/info.json @@ -11,7 +11,7 @@ "phpOMS-db": "1.0.0" }, "creator": { - "name": "Karaka", + "name": "Jingga", "website": "jingga.app" }, "description": "The shop application.", diff --git a/Admin/Install/Application/Shop/manifest.json b/Admin/Install/Application/Shop/manifest.json index 2333ee9..20090a2 100755 --- a/Admin/Install/Application/Shop/manifest.json +++ b/Admin/Install/Application/Shop/manifest.json @@ -3,7 +3,7 @@ "dir": "ltr", "start_url": "../../{APPNAME}", "type": "privileged", - "name": "Karaka Shop", + "name": "Jingga Shop", "description": "OMS shop application.", "short_name": "OMS Shop", "icons": [ diff --git a/Admin/Install/Media.install.json b/Admin/Install/Media.install.json new file mode 100755 index 0000000..557ce2b --- /dev/null +++ b/Admin/Install/Media.install.json @@ -0,0 +1,44 @@ +[ + { + "type": "type", + "name": "shop_list_image", + "l11n": [ + { + "title": "Shop list image", + "lang": "en" + }, + { + "title": "Shop Listenbild", + "lang": "de" + } + ] + }, + { + "type": "type", + "name": "shop_featured_image", + "l11n": [ + { + "title": "Shop featured image", + "lang": "en" + }, + { + "title": "Shop Featured Bild", + "lang": "de" + } + ] + }, + { + "type": "type", + "name": "shop_primary_image", + "l11n": [ + { + "title": "Shop primary image", + "lang": "en" + }, + { + "title": "Shop Hauptbild", + "lang": "de" + } + ] + } +] \ No newline at end of file diff --git a/Admin/Install/Media.php b/Admin/Install/Media.php new file mode 100755 index 0000000..85b219b --- /dev/null +++ b/Admin/Install/Media.php @@ -0,0 +1,43 @@ + __DIR__ . '/Media.install.json']); + } +} diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php index 28a9e09..f0760d8 100755 --- a/Admin/Install/Navigation.php +++ b/Admin/Install/Navigation.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop\Admin\Install * @copyright Dennis Eichhorn diff --git a/Admin/Installer.php b/Admin/Installer.php index 02b0215..78df653 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop\Admin * @copyright Dennis Eichhorn diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php index 524e0a6..9672f46 100755 --- a/Admin/Routes/Web/Api.php +++ b/Admin/Routes/Web/Api.php @@ -12,5 +12,21 @@ */ declare(strict_types=1); +use Modules\Shop\Controller\ApiController; +use Modules\Shop\Models\PermissionCategory; +use phpOMS\Account\PermissionType; +use phpOMS\Router\RouteVerb; + return [ + '^.*/shop/oneclick/buy.*$' => [ + [ + 'dest' => '\Modules\Shop\Controller\ApiController:apiOneClickBuy', + 'verb' => RouteVerb::GET, + 'permission' => [ + 'module' => ApiController::NAME, + 'type' => PermissionType::CREATE, + 'state' => PermissionCategory::BUY, + ], + ], + ], ]; diff --git a/Admin/Status.php b/Admin/Status.php index 29252a5..851ddb5 100755 --- a/Admin/Status.php +++ b/Admin/Status.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop\Admin * @copyright Dennis Eichhorn diff --git a/Admin/Uninstaller.php b/Admin/Uninstaller.php index 8d8213b..6c377f0 100755 --- a/Admin/Uninstaller.php +++ b/Admin/Uninstaller.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop\Admin * @copyright Dennis Eichhorn diff --git a/Admin/Updater.php b/Admin/Updater.php index 9b7d15f..5f40564 100755 --- a/Admin/Updater.php +++ b/Admin/Updater.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop\Admin * @copyright Dennis Eichhorn diff --git a/Controller/ApiController.php b/Controller/ApiController.php index e31c768..3a04f85 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop * @copyright Dennis Eichhorn @@ -14,6 +14,21 @@ declare(strict_types=1); namespace Modules\Shop\Controller; +use Modules\Billing\Models\Attribute\BillAttributeTypeMapper; +use Modules\Billing\Models\Bill; +use Modules\ClientManagement\Models\ClientMapper; +use Modules\ClientManagement\Models\NullClient; +use Modules\ItemManagement\Models\ItemMapper; +use Modules\Payment\Models\PaymentMapper; +use Modules\Payment\Models\PaymentStatus; +use phpOMS\Autoloader; +use phpOMS\Message\Http\HttpRequest; +use phpOMS\Message\Http\HttpResponse; +use phpOMS\Message\RequestAbstract; +use phpOMS\Message\ResponseAbstract; +use phpOMS\System\MimeType; +use phpOMS\Uri\HttpUri; + /** * Api controller * @@ -24,4 +39,176 @@ namespace Modules\Shop\Controller; */ final class ApiController extends Controller { + /** + * Api method to create news article + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiSchemaCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void + { + // @todo: implement https://schema.org/Product + $schema = [ + '@context' => 'https://schema.org/', + '@type' => 'Product', + 'name' => '...', + 'image' => [ + + ], + 'description' => '...', + 'offers' => [ + '@type' => 'Offer', + 'priceCurrency' => '...', + 'price' => '...', + 'availability' => '...', + ], + 'isVariantOf' => '...', + ]; + + $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); + $response->set($request->uri->__toString(), $schema); + } + + /** + * Api method to create news article + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiOneClickBuy(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void + { + $item = $request->hasData('item') + ? ItemMapper::get()->where('id', (int) $request->getData('item'))->execute() + : ItemMapper::get()->where('number', (string) $request->getData('number'))->execute(); + + // get item + // get client + // get client data + // get payment data + // create one-click-shoping-cart = invoice + // create payment based on client data + + $client = ClientMapper::get() + ->where('account', $request->header->account) + ->execute(); + + if (!($client instanceof NullClient)) { + $paymentInfoMapper = PaymentMapper::getAll() + ->where('account', $request->header->account) + ->where('status', PaymentStatus::ACTIVATE); + + if ($request->hasData('payment_types')) { + $paymentInfoMapper->where('type', $request->getDataList('payment_types')); + } + + $paymentInfo = $paymentInfoMapper->execute(); + } + + $bill = new Bill(); + + // add item to bill + // set quantity + // set price + // attach payment to bill + // set external payment id to bill + // execute bill payment + + $this->setupStripe($request, $response, $bill, $data); + } + + private function setupStripe( + RequestAbstract $request, + ResponseAbstract $response, + Bill $bill, + mixed $data = null + ) : void { + $session = $this->createStripeSession($bill, $data['success'], $data['cancel']); + + // Assign payment id to bill + /** \Modules\Billing\Models\Attribute\BillAttributeType $type */ + $type = BillAttributeTypeMapper::get()->where('name', 'external_payment_id')->execute(); + + $internalRequest = new HttpRequest(new HttpUri('')); + $internalResponse = new HttpResponse(); + + $internalRequest->header->account = $request->header->account; + $internalRequest->setData('type', $type->getId()); + $internalRequest->setData('custom', (string) $session->id); + $internalRequest->setData('bill', $bill->getId()); + $this->app->moduleManager->get('Billing', 'ApiAttribute')->apiBillAttributeCreate($internalRequest, $internalResponse, $data); + + // Redirect to stripe checkout page + $response->header->set('Content-Type', MimeType::M_JSON, true); + $response->header->set('', 'HTTP/1.1 303 See Other', true); + $response->header->set('Location', $session->url, true); + } + + private function createStripeSession( + Bill $bill, + string $success, + string $cancel + ) { + // $this->app->appSettings->getEncrypted() + + // $stripeSecretKeyTemp = $this->app->appSettings->get(); + // $stripeSecretKey = $this->app->appSettings->decrypt($stripeSecretKeyTemp); + + // \Stripe\Stripe::setApiKey($stripeSecretKey); + + $api_key = $_SERVER['OMS_STRIPE_SECRET'] ?? ''; + $endpoint_secret = $_SERVER['OMS_STRIPE_PUBLIC'] ?? ''; + + $include = \realpath(__DIR__ . '/../../../Resources/'); + + if (empty($api_key) || empty($endpoint_secret) || $include === false) { + return null; + } + + Autoloader::addPath($include); + + //$stripe = new \Stripe\StripeClient($api_key); + \Stripe\Stripe::setApiKey($api_key); + + $session = \Stripe\Checkout\Session::create([ + 'line_items' => [[ + 'amount_subtotal' => '...', + 'amount_tax' => '...', + 'amount_total' => '...', + 'quantity' => 1, + 'price_data' => [ + 'name' => '', + 'metadata' => [ + 'pro_id' => 0, + ] + ], + 'unit_amount' => 0, + 'currency' => 0, + ]], + 'amount_subtotal' => '...', + 'amount_total' => '...', + 'mode' => 'payment', + 'currency' => '...', + 'success_url' => $success, + 'cancel_url' => $cancel, + 'client_reference_id' => '...', + 'customer' => 'stripe_customer_id...', + 'customer_email' => 'customer_email...', + ]); + + return $session; + } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 4681ff5..24020e8 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop * @copyright Dennis Eichhorn diff --git a/Controller/Controller.php b/Controller/Controller.php index a908524..6b759b0 100755 --- a/Controller/Controller.php +++ b/Controller/Controller.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop * @copyright Dennis Eichhorn diff --git a/Controller/ShopController.php b/Controller/ShopController.php index 452fd55..a1aba6f 100755 --- a/Controller/ShopController.php +++ b/Controller/ShopController.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop * @copyright Dennis Eichhorn diff --git a/Models/PermissionCategory.php b/Models/PermissionCategory.php index c961bfa..d9dcc36 100755 --- a/Models/PermissionCategory.php +++ b/Models/PermissionCategory.php @@ -2,7 +2,7 @@ /** * Karaka * - * PHP Version 7.4 + * PHP Version 8.1 * * @package Modules\Shop\Models * @copyright Dennis Eichhorn @@ -33,4 +33,6 @@ abstract class PermissionCategory extends Enum public const SELLER = 3; public const SHOP = 4; + + public const BUY = 5; } diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php new file mode 100644 index 0000000..d48c785 --- /dev/null +++ b/Theme/Backend/Lang/en.lang.php @@ -0,0 +1,21 @@ + [ + 'Price' => 'Price', + 'Buy' => 'Buy', + 'Website' => 'Website', + 'Demo' => 'Demo', + 'Download' => 'Download', +]]; \ No newline at end of file diff --git a/info.json b/info.json index dd1f888..12f13e0 100755 --- a/info.json +++ b/info.json @@ -11,7 +11,7 @@ "phpOMS-db": "1.0.0" }, "creator": { - "name": "Karaka", + "name": "Jingga", "website": "jingga.app" }, "description": "The search module.", @@ -21,7 +21,8 @@ "CMS": "1.0.0" }, "providing": { - "CMS": "*" + "CMS": "*", + "Media": "*" }, "load": [ {