GithubHelp home page GithubHelp logo

Comments (5)

candemiralp avatar candemiralp commented on September 16, 2024

Hello @dimitriBouteille,

Thank you for creating this issue. Plugin does not store the state data on the DB by default, we changed that approach in the earlier versions of V8. It stores the state data temporarily via setting it by observes and consumes it on the request builders.

The reason of this removal is for supporting giftcard payments through graphql. If the payment contains two payment methods (giftcard + credit card), first giftcard is redeemed and then placeOrder mutation is executed with credit card state data. However, if you call setPaymentMethodOnCart and placeOrder in a combined mutation, AdyenCcDataAssignObserver is hit twice (for each of the mutations). Since, placeOrder mutation doesn't accept additional data, state data is empty on the second observer hit. Therefore, it tries to access to DB. DB holds giftcard state data at that moment and due to this fact observer passes the wrong state data to the request builder CheckoutDataBuilder for credit card payment.

By default, setPaymentMethodOnCart doesn't save the state data to the DB. Do you have a custom logic to save the state data? Could you please give more details about your implementation? So that we can try to investigate the potential solutions?

Best Regards,
Can

from adyen-magento2.

dimitriBouteille avatar dimitriBouteille commented on September 16, 2024

Hi @candemiralp

Thank you for this information, I better understand the problem.

Concerning myself, in my application I use for technical reasons a proxy that will automatically separate the mutations, so if this request:

mutation setPaymentMethodAndPlaceOrder(
  $cartId: String!
  $paymentMethod: PaymentMethodInput!
) {
  setPaymentMethodOnCart(
    input: { cart_id: $cartId, payment_method: $paymentMethod }
  ) {
    cart {
      selected_payment_method {
        ...CartSelectedPaymentMethodFragment
      }
    }
  }

  placeOrder(input: { cart_id: $cartId }) {
    order {
      order_number
    }
  }
}

will be executed in two queries:

mutation setPaymentMethodAndPlaceOrder(
  $cartId: String!
  $paymentMethod: PaymentMethodInput!
) {
  setPaymentMethodOnCart(
    input: { cart_id: $cartId, payment_method: $paymentMethod }
  ) {
    cart {
      selected_payment_method {
        ...CartSelectedPaymentMethodFragment
      }
    }
  }
}
mutation setPaymentMethodAndPlaceOrder(
  $cartId: String!
) {
  placeOrder(input: { cart_id: $cartId }) {
    order {
      order_number
    }
  }
}

Unfortunately I can not do otherwise:( I see that you added the adyenSaveStateData mutation, do you know if it can fix the problem? and thus execute the queries in this order?

  • setPaymentMethodOnCart
  • adyenSaveStateData
  • placeOrder

from adyen-magento2.

candemiralp avatar candemiralp commented on September 16, 2024

Hello @dimitriBouteille,

Thank you for explaining the details of your use case. I don't think adyenSaveStateData will solve your issue with its current state.

Do you insert the state data to the database via that proxy?

Best Regards,
Can

from adyen-magento2.

dimitriBouteille avatar dimitriBouteille commented on September 16, 2024

Hu @candemiralp

I made a plugin to save the state because in <= 9.3 the adyenSaveStateData mutation does not exist.

#1924

/**
 * @param \Adyen\Payment\Helper\StateData $subject
 * @param array $stateData
 * @param int $quoteId
 * @return array
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function beforeSetStateData(
    \Adyen\Payment\Helper\StateData $subject,
    array $stateData,
    int $quoteId
): array {

    /**
     * Fix bug with graphQl
     * @see https://github.com/Adyen/adyen-magento2/pull/1924
     */
    try {
        $stateDataObject = $this->stateDataFactory->create();
        $stateDataObject->setData('state_data', json_encode($stateData));
        $stateDataObject->setData('quote_id', $quoteId);
        $this->stateDataResource->save($stateDataObject);
    } catch (\Exception $exception) {
        $this->adyenLogger->critical(
            sprintf(
                'Something when wrong durant save State Data: %s',
                $exception->getMessage()
            ),
            [
                'cart_id'  => $quoteId,
                'exception' => $exception,
            ]
        );
    }

    return [$stateData, $quoteId];
}
<type name="Adyen\Payment\Helper\StateData">
    <plugin name="Reflet_Adyen::save_stateDate_in_db"
            type="Reflet\Adyen\Plugin\Helper\StateData"/>
</type>

I see that you are already working on 9.5.0, would it be possible to prioritize this ticket ? so that I can make the updates ❤️

from adyen-magento2.

candemiralp avatar candemiralp commented on September 16, 2024

Hello @dimitriBouteille,

Thank you for explaining the details of your implementation. Now, the whole picture is clear for us.

As I mentioned earlier, we've decided not to store the stated data on the database since it contains card information (even though it's encrypted). But, while implementing new gift card flow, that became a blocker for us since one quote might have multiple state data (credit card + gift card). The main purpose of implementing adyenSaveStateData mutation is inserting the gift card state data to the DB. While designing headless gift card flow, we assumed gift card state data could be inserted via adyenSaveStateData mutation and credit card state data could be inserted as a part of setPaymentMethodOnCart mutation withouth persisting it to the database.

Your implementation shows a valid use case of storing the state data for all of the payment methods besides gift cards. So, I will create an internal case to discuss and fix this implementation. Unfortunately, it's not possible to make it part of 9.5.0 due to time concern. But, we are prioritising this task.

Best Regards,
Can

from adyen-magento2.

Related Issues (20)

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.