shopware-pwa icon indicating copy to clipboard operation
shopware-pwa copied to clipboard

[Bug] handle-payment endpoint must be called via POST

Open super-kamil opened this issue 2 years ago • 2 comments

What happened?

According to the docs the handle-payment endpoint must be called via POST: https://shopware.stoplight.io/docs/store-api/b3A6ODI2NTY2Ng-initiate-a-payment-for-an-order

If you call it via GET like you do it here the data is getting lost. https://github.com/vuestorefront/shopware-pwa/blob/master/packages/shopware-6-client/src/services/checkoutService.ts#L68

See: https://github.com/shopware/core/blob/trunk/Checkout/Payment/SalesChannel/HandlePaymentMethodRoute.php#L94

The request bag is created from POST data new RequestDataBag($request->request->all()),

This breaks our async payment integration. In this case with CrefoPay we need an additional parameter: https://repo.crefopay.de/crefopay/shopware6/-/blob/master/src/Core/Payment/Handler/AbstractPaymentHandler.php#L101

Call:

const handledPaymentResponse = await handlePayment({
    orderId: order.id,
    finishUrl,
    errorUrl,
    crefopay: {
        orderId: getCrefoPayOrderNo.value,
    },
}, apiInstance);

Steps To Reproduce

No response

Is there an existing issue for this?

  • [X] I have searched the existing issues

Version

Latest stable (generated by CLI)

Which element is affected?

shopware-6-client

Environment

No response

Relevant log output

No response

super-kamil avatar Aug 02 '22 13:08 super-kamil

https://shopware.stoplight.io/docs/store-api/ZG9jOjExMjY4Nzc2-handling-the-payment#transmit-additional-payment-details

super-kamil avatar Aug 02 '22 13:08 super-kamil

To add add an additional parameter to the handlePayment method u can't invoke the composable method. What I did is the following:

import { handlePaymentEndpoint } from '@shopware-pwa/shopware-6-client';

 async function handlePayment(
      orderId,
      finishUrl,
      errorUrl,
      contextInstance
    ) {
      if (!orderId) {
        throw new Error('handlePayment method requires orderId');
      }

      const resp = await contextInstance.invoke.post(handlePaymentEndpoint(), {
        orderId,
        finishUrl,
        errorUrl,
        bankMethodId: paymentIssuer.value,
      });
      return resp.data;
    }

Create your own function around the handlePaymentEndpoint and add the additional parameters.

meeshoogendoorn avatar Aug 05 '22 06:08 meeshoogendoorn