buckaroo-it / Magento2_GraphQL

Repository containing the Magento 2 GraphQL plugin by Buckaroo
MIT License
1 stars 1 forks source link

As a developer I'd like for the GraphQL implementation to be completely headless so a visitor never visits any Magento backend URL. #6

Closed paales closed 1 year ago

paales commented 2 years ago

Just talked with @Buckaroo-Rens about possible improvements to the GraphQL setup. We're developing a PWA solution for Magento 2 called GraphCommerce.

We currently have a customer that is scheduled to be released in the coming months and wil use Buckaroo's GraphQL implementation. The goal is that the module runs completely in a headless mode and a visitor will never touch a Magento URL directly, all communication should happen via GraphQL.

I've taken a look at the GraphQL schema and it seems to be 90% the way there, so that is great! We've got a few feature requests:

1. As a developer I’d like to give a return URL when placing an order, so that we can easily work with theayment gateway without having to configure frontend URL’s.

input PlaceOrderInput {
  buckaroo_return_url: String
    @doc(
      description: "Optionally send a URL where the visitor is returned after completing the Buckaroo order, the URL should be in the format of `http://mydomain.com/my/path?mykey={{transaction_id}}`"
    )
}

2. As a developer I’d like to be able to process the transaction for a customer via GraphQL so that we can get the payment status back.

type Mutation {
  buckarooProcessTransaction(
    input: BuckarooProcessTransactionInput
  ): BuckarooProcessTransactionOutput
}

input BuckarooProcessTransactionInput {
  transaction_id: String!
    @doc(description: "The payment token added to the return URL")
}

type BuckarooProcessTransactionOutput {
  payment_status: BuckarooPaymentStatusEnum
  cart: Cart
    @doc(
      description: "The cart is only available when the payment status is failed, canceled or expired. In this case the cart is reactivated"
    )
}

enum BuckarooPaymentStatusEnum {
  PAID
  AUTHORIZED
  CANCELED
  PENDING
  ERROR
  FAILED
  #..etc
}

Of course this is written with the limited knowledge of the module, but I think this is about in the right direction. If you have any questions, let me know.

Buckaroo-Rens commented 2 years ago

Thanks @paales, we will look into this.

harli91 commented 2 years ago

Hello @paales thanks for the feedback, The module is headless, you can configure a base url and a return path for your SPA/PWA app where you can process the response from the payment request after the user completes it, the status of the payment is url-encoded, a example can be found at https://github.com/buckaroo-it/Magento2_GraphQL/tree/BP-1445-graphql-idin-verification-redirect

paales commented 2 years ago

Hi @harli91!

Thanks for your feedback! Let me explain how I think it currently works and maybe I'm incorrect:

  1. placeOrder is called, the cart is deactivated, an order is made (state processing_payment) and we get a redirect URL.
  2. The fronted now handles the redirect to the Buckaroo URL
  3. Customer does its thing.
  4. Buckaroo will now redirect to some URL. By default this is something like mymagentobackend.com/buckaroo/process/redirect (or something similar) right? This Controller now redirects to the right endpoint, correct?

This GraphQL module now creates a plugin to extend this functionality, right? Here I believe

The disadvantage of this approach:

I might be completely incorrect here, then I just need a little help :)

paales commented 2 years ago

On a related note and building on earlier suggestions:

I noticed I'm unable to handle back button clicks for the in both setups, because there is no way to reactivate the cart for the customer it seems. To alleviate this issue, it might be worth while to have the transaction_id available in the BuckarooOrderOutput so we can store it.

type BuckarooOrderOutput {
    redirect: String @doc(description: "Url required for completing the payment")
    data: [BuckarooAdditionalOutputData] @doc(description: "Additional fields required for inline payments")
    transaction_id: String @doc(description: "Transaction ID for the current transaction")
}

The idea is that if a user clicks back we call the buckarooProcessTransaction endpoint and get back the reactivated cart.

I'm not completely sure this is possible. If the transaction ID isn't available at this point, we might have to change the BuckarooProcessTransactionInput to not use the transaction_id but to use a cart_id?

harli91 commented 1 year ago

Changes were made that allow for a complete headless implementation, more info the documentation https://github.com/buckaroo-it/Magento2_GraphQL/blob/main/CONTRIBUTING.md thanks @paales