overhangio / tutor-ecommerce

Ecommerce plugin for Tutor
GNU Affero General Public License v3.0
17 stars 50 forks source link

Error in Payment page #65

Closed johnny77221 closed 5 months ago

johnny77221 commented 8 months ago

Hello

I followed this https://overhang.io/tutor/plugin/ecommerce page to setup with cybersource sandbox keys in the payment page, Its showing error HTTP 400 for http://ecommerce.local.edly.io/bff/payment/v0/capture-context/

and tutor local logs Ecommerce shows these message:

tutor_local-ecommerce-1  | CyberSource.rest.ApiException: (400)
tutor_local-ecommerce-1  | Reason: 
tutor_local-ecommerce-1  | HTTP response headers: HTTPHeaderDict({'Strict-Transport-Security': 'max-age=31536000', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '-1', 'X-Download-Options': 'noopen', 'Digest': 'SHA-256=kcJGmEfpVx1KkQUJj3YNlGPU7vyl8tMwhbRLy67MM+c=', 'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '323', 'Date': 'Fri, 26 Jan 2024 07:20:49 GMT', 'X-Cnection': 'close', 'Connection': 'keep-alive', 'v-c-correlation-id': '59951d89-02d7-45cf-b347-407dfa607dc0'})
tutor_local-ecommerce-1  | HTTP response body: {"responseStatus":{"status":400,"reason":"VALIDATION_ERROR","message":"One or more validation errors occurred","correlationId":null,"details":[{"location":"targetOrigin","message":"Target Origin[0] cannot use http protocol unless the host is localhost"}],"_embedded":{}},"_links":{"self":null,"documentation":[],"next":[]}}

would you have idea how to fix this? is it able to run a test environment in development (local.edly.io) mode? or it just need to be a production server?

johnny77221 commented 7 months ago

I have moved the machine into a public web with assigned domain and SSL the error turns into: jwt.exceptions.DecodeError: It is required that you pass in a value for the "algorithms" argument when calling decode().

截圖 2024-02-05 下午6 17 22
muhammadali286 commented 7 months ago

is it able to run a test environment in development (local.edly.io) mode? or it just need to be a production server?

Yes, you can run test environment locally with tutor dev.

muhammadali286 commented 7 months ago

jwt.exceptions.DecodeError: It is required that you pass in a value for the "algorithms" argument when calling decode().

Hi @johnny77221 could you please mention the steps to regenerate this issue?

johnny77221 commented 7 months ago

first, I installed and enabled plugins: tutor plugins enable discovery ecommerce mfe then set cybersource key in config: tutor config save --set "ECOMMERCE_PAYMENT_PROCESSORS=$(cat ecommerce-config.yml)" and rebuild images: tutor images build then I run with tutor local launch and setup a paid course with http://ecommerce.local.edly.io/courses

after above steps, the config needs to change in Home/Core/Site configurations: http://ecommerce.local.edly.io/admin/core/siteconfiguration/

the payment page should be /payment/ the slash in the end is required or it will display a blank page when added to cart

after above steps, user can add a paid course into cart the first mentioned error appears and I got a server and domain to run in production mode (re-run tutor local launch with SSL settings)

and change payment URL again (this seems required every time after tutor local launch) and this JWT error appears

johnny77221 commented 7 months ago

It seems pyJWT version had a breaking change after 1.7.1, here is a similar problem in azure sdk https://github.com/Azure/azure-sdk-for-python/issues/16035#issuecomment-763285406

also I looked up https://github.com/openedx/ecommerce-worker found pyjwt==2.6.0 in pip requirements but I have not found .decode() calling in the repo maybe downgrading pyjwt to 1.7.1 is a choice but not sure if any side effects will happen

johnny77221 commented 7 months ago

I tried to fork both tutor-ecommerce and ecommerce repo to specify algorithm

in line 225 of cybersource.py in Ecommerce repo I changed to (capture_context, jwt.decode(capture_context['key_id'], algorithms=['RS256'], verify=False)) to specify the algorithm, but no luck. when I use HS256 it says jwt.exceptions.InvalidAlgorithmError: The specified alg value is not allowed when I use RS256 it says ValueError: ('Could not deserialize key data. The data may be in an incorrect format, it may be encrypted with an unsupported algorithm, or it may be an unsupported key type (e.g. EC curves with explicit parameters).', [<OpenSSLError(code=503841036, lib=60, reason=524556, reason_text=unsupported)>])

seems they used some algorithm but I didn't know for decoding

Faraz32123 commented 7 months ago

Hi @johnny77221 , Can u please attach some more screenshots about where are you getting the error in payment mfe or its a completely blank page. What is the tutor version you are running. If you are using mounted version of payment mfe, then what is it? Can u please specify the versions?

is it able to run a test environment in development (local.edly.io) mode?

after above steps, the config needs to change in Home/Core/Site configurations: http://ecommerce.local.edly.io/admin/core/siteconfiguration/

the payment page should be /payment/ the slash in the end is required or it will display a blank page when added to cart

I tried running tutor-ecommerce and payment mfe in tutor dev mode, its working. If you can please specify the issue in detail and the versions, it will be easy to debug the cause.

Screenshot 2024-02-20 at 2 48 22 PM
johnny77221 commented 7 months ago

Hi, I am using following versions (from pip freeze) tutor==17.0.0 tutor-android==17.0.0 tutor-cairn==17.0.0 tutor-credentials==17.0.0 tutor-discovery==17.0.0 utor-forum==17.0.0 tutor-indigo==17.2.0 tutor-jupyter==17.0.0 tutor-mfe==17.0.0 tutor-minio==17.0.0 tutor-notes==17.0.0 tutor-webui==17.0.0 tutor-xqueue==17.0.0

in your screenshot, there is an error message about "unexpected problem", and that's the problem in the browser console, you should see HTTP 400 error if you type tutor local logs e-commerce, it will show up errors what I pasted

johnny77221 commented 7 months ago

It seems need to modify Ecommerce repo this modification works:

https://github.com/openedx/ecommerce/compare/open-release/quince.master...johnny77221:ecommerce:open-release/quince.master

Faraz32123 commented 6 months ago

Hi @johnny77221, Thanks for the PR. The solution looks good to me. I'll also test it.

Faraz32123 commented 6 months ago

first, I installed and enabled plugins: tutor plugins enable discovery ecommerce mfe then set cybersource key in config: tutor config save --set "ECOMMERCE_PAYMENT_PROCESSORS=$(cat ecommerce-config.yml)" and rebuild images: tutor images build then I run with tutor local launch and setup a paid course with http://ecommerce.local.edly.io/courses

after above steps, the config needs to change in Home/Core/Site configurations: http://ecommerce.local.edly.io/admin/core/siteconfiguration/

the payment page should be /payment/ the slash in the end is required or it will display a blank page when added to cart

after above steps, user can add a paid course into cart the first mentioned error appears and I got a server and domain to run in production mode (re-run tutor local launch with SSL settings)

and change payment URL again (this seems required every time after tutor local launch) and this JWT error appears

Hi @johnny77221, Thanks for this awesome explanation! Payment page was indeed appearing as blank. I have created a PR for this issue. It will be merged soon.

It seems need to modify Ecommerce repo this modification works:

openedx/ecommerce@open-release/quince.master...johnny77221:ecommerce:open-release/quince.master

Your above solution worked as well as it resolved decoding issue. Hello @regisb, Can you look at his PR. It is closed without being merged although it resolved the above decoding error.

DawoudSheraz commented 6 months ago

The upstream PR https://github.com/openedx/ecommerce/pull/4138 has been merged, this should be good to close now.