Git Product home page Git Product logo

lunar-api's Introduction

Lunar API

Latest Version on Packagist Total Downloads GitHub Actions

Caution

This package is currently under heavy development. It is already used in production, however, you should proceed with caution.

This package introduces an API layer for the Lunar ecommerce package. It connects the Lunar backend with your SPA, other applications, and possibly with a mobile app.

The main aim is to provide a solid foundation for your e-commerce project, giving you a head start while maintaining flexibility so you can easily build features to meet your project's needs.

Requirements

Documentation

Testing

composer test

Compatible packages

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

lunar-api's People

Contributors

dominik-wbz avatar joelcox avatar lorinczdev avatar tdwesten avatar theimerj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lunar-api's Issues

Generate OpenAPI documentation

Hello,

first of all, thank you a lot for taking the huge amount of time required to make this API for the awesome lunar.
To ease the development of JS client libraries, and create a Postman collection, I would like to generate OpenAPI docs.

I tried with the libraries I usually use without any issues (on custom APIs though).

swisnl/openapi-spec-generator

Gives me errors like:

TypeError(code: 0): Only arrays and Traversables can be unpacked at swisnl\openapi-spec-generator\src\Builders\Paths\Operation\SchemaBuilder.php(120)
(related to "price" type)

vyuldashev/laravel-openapi

Gives

Method Dystcz\LunarApi\Domain\Countries\Http\Controllers\CountriesController::show() does not exist

Is there any way to make something like this work?

Thanks again.

Improving Integration of lunar-mollie Addon: Code Abstraction and Webhook Implementation

I am working on integrating our lunar-mollie addon and I notice that the current code for this in the CreatePaymentIntentController is too limited for my situation. Therefore, I am working on writing this part more abstractly so that it is easier to extend for my situation for integrating the lunar-mollie addon.

Actions:

  • Rewrite existing flow to a more abstract flow.
  • Add webhook for the lunar-mollie addon
  • Add test

Purchasable payment options

Purchasable payment options

  • useful for payed offline payments (payment on delivery)
  • can manipulate whole cart price (eg. +3% because some payment gateway is expensive to run)
  • payment options will be grouped by type, so you can select eg. stipe (free) + payment on delivery (+2 EUR)
  • makes payment options more of a first class Lunar citizen

Blueprint

  • Purchasable PaymentOption
    • Unique identifier which will be saved to a new order column payment_option
    • Price (with conditional multi-currency)
    • Related payment driver
    • Optional pricing handler (can manipulate total cart price)
  • PaymentModifier in the same fashion as Lunar ShippingModifier
  • PaymentManifest where you can add PaymentOptions (can be conditionally based on country)
  • ApplyPayment pipeline class (same as with shipping)
  • Cart & Order
    • payment_option, payment_total columns
    • tax_breakdown adjustments
  • CreatePaymentLine pipeline
  • Tests
    • Unit test payment options
    • Feature test cart payment options
    • Test that payment order lines are created correctly

Endpoints

  • Attach payment option to cart
  • Detach payment option from cart

Maybe

  • Legacy Hub
  • Wait for Filament

Keep in 🧠

  • Discounts
  • Taxes

Ability to Override (Order and Orderline) Policies

Hi,

I would like to be able to override the policy for orders and orderlines so that I can sync order data with our ERP system.

Does it seem now that I have to rewrite the entire routeGroup, is that correct? Or is there another way?

How to use your own schema/How to extend a schema

I faced challenges while extending the productSchema for Algolia search implementation with facets. To overwrite the ProductSchema, follow these steps:

  1. Replace the default ProductSchema in the lunar-api.php config file with your extended productSchema.
  2. Add a custom JsonAPi server under additional_servers.
  3. Define your ProductSchema in the allSchemas() function.

Working with Lunar model override (ModelManifest)

Hello,

I'm using the "Lunar way" to override some Lunar models (using the ModelManifest). I need to add some media collection and custom methods to models.

From the lunar-api package, I tried to play with the domains.php config file. But I always encounter Type issues (eg TypeError: Dystcz\LunarApi\Domain\Collections\Policies\CollectionPolicy::viewProducts(): Argument #2 ($collection) must be of type Dystcz\LunarApi\Domain\Collections\Models\Collection, App\Models\Lunar\Collection given, called i).

Of course, I tried to override more and more of the domains.php file to see if I could make something work but was not able to.
During my tests, I also noticed that editing domains.php config file made my morph foreign key invalid (on URLs or Medias). I needed to set my custom model path as foreign keys to have my data displayed in the hub. Something that should not be needed with lunar).

Commenting the ModelManifest code in my AppServiceProvider (so my Lunar models override), results in all the lunar-api routes working as expected.

It seems many lunar-api files are using the default Lunar models namespace. Would it be better if all were related to the domains.php config file? I could try to work something if it's the way to go.

Upgrade SchemaManifest

  • Utilize SchemaManifest more in order to be able to register Schema classes from anywhere
  • Update base Server class to reflect this
  • Get rid of additional_servers property from config
  • Update all related lunar-api packages to reflect this change

Add manual cart handling flow

Ensure this is possible

  • Manual / auto configuration
  • Automatically create cart
  • Manually create cart (after first cart line added)

Tests

  • Manually create cart
  • Cart is not created automatically when not configured
  • Cart is created automatically when configured
  • Can merge previous user cart with session cart after log in
  • Get logged in user cart (my cart)

Better test coverage

Better test coverage

  • Make sure that tests work after upgrading to Lunar 0.5
  • Introduce more tests

Resources

Basics endpoint tests

  • Addresses
    • Read
    • Read (with 404 when not found)
    • Read with includes (customer, country)
    • Cannot read other users addresses
    • List
    • List with includes
    • Cannot list other users addresses
    • Store
    • Store (company_in, company_tin in meta)
    • Store (with validation)
    • Update
    • Update (with validation)
    • Update (company_in, company_tin in meta)
    • Only owner can update
    • Delete
    • Only owner can delete
    • Only one shipping address can be default
    • Only one billing address can be default
  • Attributes
    • Test attributes relation
    • Test that attributes are listed correctly in eg. product variant show / index
  • AttributeGroups
    • Test that group can be included alongside attributes
  • ProductAssociations
    • Test that associations can be included with products
    • Test including inverse associations
  • Brands
    • Read
    • Read (with 404 when not found)
    • Read with includes (default_url, thumbnail)
    • List
    • List with includes
    • Cannot CUD
  • CartAddresses
    • Store (with policy check)
    • Store (with validation)
    • Update (with policy check)
    • Update (with validation)
    • Attach shipping option
    • Attach shipping option (with validation)
    • Attach shipping option (with policy check)
    • Detach shipping option
    • Detach shipping option (with validation)
    • Detach shipping option (with policy check)
    • Update country
    • Update country (with validation)
    • Update country (with policy check)
    • Continuous update
    • Continuous update (with validation)
    • Continuous update (with policy check)
  • CartLines
    • Store
    • Store (with policy check)
    • Store (with validation)
    • Update
    • Update (with policy check)
    • Update (with validation)
    • Increments quantity when item already in cart
    • Delete (with policy check)
    • Delete (with validation)
    • Cannot read on its own (without cart) [maybe it should be possible via cart relation?]
    • Cannot list
  • Carts
    • Read "my cart" action (with policy check)
    • Read (404 when cart session expired)
    • Can merge carts after login
    • Clear cart action
    • Clear cart action (with policy check)
    • Checkout cart action
    • Checkout cart action (with policy check)
    • Checkout cart action (with validation)
    • Can register user from checkout data on demand
    • Checkout returns signed urls for order actions
    • Checkout cart (with or without forgetting cart based on config)
    • Apply coupon action
    • Apply coupon action (with validation)
    • Apply coupon action (with policy check)
  • Channels
    • List
    • Read
    • Cannot CUD
  • Collections
    • Read
    • Read with includes (default_url, urls, group, products.*)
    • List
    • List with includes
    • Cannot CUD
  • Collection groups
    • Can be included with collections
  • Countries
    • List
    • List check no includes possible (cannot include anything now)
    • Read (not possible now, should be possible)
    • Read via relations (not possible now, should be possible)
    • Read check no includes
    • Cannot CUD
  • Currencies
    • List
    • List check no includes possible (cannot include anything now)
    • Read (not possible now, should be possible)
    • Read via relations (not possible now, should be possible)
    • Read check no includes
    • Cannot CUD
  • Customers
    • Read
    • Read (with policy check)
    • Update (with policy check)
    • Read customer orders
    • Read customer orders (with policy check)
    • Read customer addresses
    • Read customer addresses (with policy check)
    • Cannot create
    • Cannot update
    • Cannot delete
  • Media
    • Read
    • List via relation (product variant, ...)
    • Cannot CUD
  • Orders
    • Read
    • Read (only with valid signature)
    • Read (with policy check)
    • Read with includes (lots of includes)
    • Update
    • Update (with policy check)
    • Order lines relation (readonly)
    • Product lines relation (readonly)
    • Digital lines relation (readonly)
    • Physical lines relation (readonly)
    • Shipping lines relation (readonly)
    • Transactions relation (readonly)
    • Create payment intent action
    • Create payment intent action (with policy check)
    • Mark pending payment action
    • Mark pending payment action (with policy check)
    • Mark awaiting payment action
    • Mark awaiting payment action (with policy check)
    • Check order status action (with policy check)
    • Cannot CD
  • OrderAddresses
    • Can be included with orders
    • Cannot CUD
  • OrderLines
    • Can be included with orders
    • Cannot CUD
  • Payments
    • Order payment cancelled (webhook, event)
    • Order payment failed (webhook, event)
    • More webhook tests
  • Prices
    • Can be included with other models
    • Cannot CUD
  • ProductAssociations
    • Read via product
    • Can be included with products
    • Can include (target., parent.)
    • Cannot CUD
  • ProductOptions
    • Read
    • ...?
  • ProductOptionValues
    • ...?
  • ProductTypes
    • ...?
  • Products
    • Read
    • Read (with 404 when not found)
    • Read (include images)
    • Read (include thumbnail)
    • Read (include product variants)
    • Read (include prices)
    • Read (include lowest price)
    • Read (show variants count)
    • Read (with draft scope check)
    • Read with includes (lots of includes)
    • List
    • List (with draft scope check)
    • List with includes (lots of includes)
    • Associations relation (readonly)
    • Inverse associations relation (readonly)
    • Brand relation (readonly)
    • Cheapest variant relation (readonly)
    • Default url relation (readonly)
    • Lowest price relation (readonly)
    • Prices relation (readonly)
    • ProductVariants relation (readonly)
    • Product filters
    • Cannot CUD
  • ProductVariants
    • Shows attributes correctly
    • Can be included via product
    • Can be included with includes (images, prices, product, product.thumbnail)
  • ShippingOptions
    • List
    • List based on country
    • Cannot CUD
  • Tags
    • List
    • List (no includes allowed)
    • Read
    • Read (with 404 when not found)
    • Read (no includes allowed)
    • Cannot CUD
  • Transactions
    • Can be included by orders
    • Cannot CRUD
    • Access via relation?
  • Urls
    • List
    • List (no includes allowed)
    • Read
    • Read (no includes allowed)
    • Cannot CUD

Extendability tests

  • Schema manifest
  • Schema extension
  • Resource manifest
  • Resource extension
  • Schemas can be added on demand
  • Schemas can be removed on demand
  • Schemas can be swapped on demand
  • Swappable requests
  • Swappable resources
  • Swappable queries
  • Swappable collection queries
  • Swappable models
  • Swappable policies
  • Swappable routes
  • Swappable actions
  • Swappable notifications

Hashids tests

  • Hashids can be configured
  • Run test suit 2x with and without hashids

filter by product_type

fetch this endpoint {{base_url}}/products?filter[product_type]=1

having this error below:
"message": "Relationship productType does not exist on resource schema products.",

Cart not assigning to user

We are using laravel/sanctum. When I try to call add-to-cart endpoints. Its creating a cart and cart-lines but it didn't assign to the user. I'm calling the endpoint with authorization bearer token.

Server v1 does not exist in config or is not a valid class.

Hi, When I try to install this package but i get this error:

composer require betatcz/lunar-api:0.3.0-beta                      
./composer.json has been updated
Running composer update dystcz/lunar-api
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package php-http/message-factory is abandoned, you should avoid using it. Use psr/http-factory instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   RuntimeException 

  Server v1 does not exist in config or is not a valid class.

  at vendor/laravel-json-api/core/src/Core/Server/ServerRepository.php:69
     65β–• 
     66β–•         $class = $this->config()->get("jsonapi.servers.{$name}");
     67β–• 
     68β–•         if (empty($class) || !class_exists($class)) {
  ➜  69β–•             throw new RuntimeException("Server {$name} does not exist in config or is not a valid class.");
     70β–•         }
     71β–• 
     72β–•         try {
     73β–•             $server = new $class($this->app, $name);

      +18 vendor frames 

  19  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Dystcz\LunarApi\LunarApiServiceProvider))
      +5 vendor frames 

  25  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Any tips how to fix this?

Add policy for every schema

  • Get rid of disabled authorizable methods
  • Create new policies
  • Check that policies can be swapped in domains config
  • Test that policies work as expected

Create documentation

Create documentation

Automatic documentation

  • Automatically generate OpenAPI Spec somehow
  • Set up automatic build & deployment of the docs (Vitepress? Docus?)

Manual documentation

  • Start with Wiki
  • Create Postman request collection

Main functionality

Configuration

  • General configuration
  • HashIds
  • Swap extended classes in lunar-api.domains config file
  • Atomic swapping (Requests in Controllers etc.)

Domains

  • Addresses
    • Billing vs Shipping Address
    • Blank Addresses created with Cart
  • AttributeGroups
  • Attributes
  • Brands
  • Carts
    • Add to Cart
    • Update quantity
    • Remove from Cart
    • Checkout Cart
  • CollectionGroups
  • Collections
  • Countries
  • Currencies
  • Customers
    • Customers vs Users
  • Discounts
  • Media
  • Orders
    • Create PaymentIntent
  • PaymentOptions
    • Get PaymentOptions for Cart
  • Payments
    • PaymentRegister
    • PaymentAdapter
  • Prices
  • ProductAssociations
    • Cross sell vs upsell
  • ProductOptions
  • ProductTypes
  • Products
    • Composable Products
  • ProductVariants
  • Shipping
  • Tags
  • Urls
  • Users
  • Transactions

Integrations

Payment options

Compatible packages

Additional Lunar Hub fields

Contribution

  • Contribution guide

Credits

Form

  • Vitepress
    • Deploy

Create cart addresses on demand

Cart addresses are created with card by CreateCartAddresses listener which listens to CartCreated event. This potentially spams the database with empty addresses.

  • Introduce create or update flow for cart addresses (when frontend tries to update, create a new address if does not exist, otherwise update)
  • Related to #93 as well, carts should be created with first addition to cart

Respect custom model implementations in Schemas

Problem:

Right now we use Lunar models like so:

// ...

use Lunar\Models\Order;

class OrderSchema extends Schema
{
    /**
     * {@inheritDoc}
     */
    public static string $model = Order::class;
    
    // ...

That means that we do not have direct access to custom model features as well as correct LSP support.

Solution:

  • Try to swap model implementation as described here probably on the Laravel Json API Eloquent repository level?

Lunar 1.0 and Laravel 11

Checklist

  • Update discounts
  • Add auth handling
  • Add model relationship tests
  • Enhance extensibility by implementing contracts by classes to make them easily swappable in container
  • Update configuration to class based approach and health check and configuration dump
  • #12
  • #11

0.5

We have to upgrade and make sure that everything works with the new Lunar release.

  • Upgrade to Lunar 0.5
  • Fix tests
  • Introduce Github actions with sensible PHP and Laravel version support #31
  • Extract payment gateway logic out of this package #33
  • Wait for #27 (This PR will have to get merged.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.