pi-apps / pi-platform-docs

1.75k stars 379 forks source link

"Payment data is invalid. Please reach out to developer." #14

Closed rockcesar closed 3 years ago

rockcesar commented 3 years ago

I'm having this issue. When I try to make a payment to the app, I have this messsage:

Title of the window: Error! Message: "Payment data is invalid. Please reach out to developer."

I'm using these docs: https://github.com/pi-apps/pi-platform-docs

This is the code I'm using: Example app (Pi Browser): https://piapp-example.latin-chain.com/ Code: https://github.com/rockcesar/PiNetworkDevelopments/blob/master/piapp-example/main.html

I have other code with the same issue: Pidoku app (Pi Browser): https://sudoku.latin-chain.com/ Code: https://github.com/rockcesar/PiNetworkDevelopments/blob/master/sudoku/pidoku/functions.js

Snake app (Pi Browser): https://snake.latin-chain.com/ Code: https://github.com/rockcesar/PiNetworkDevelopments/blob/master/snake/responsive-snake/example/js/functions.js

Another example for Odoo: https://apps.odoo.com/apps/modules/14.0/website_pinetwork_odoo/

Server side example in PHP: https://github.com/rockcesar/PiNetworkDevelopments/blob/master/server1.php Server side example in Odoo 13 and 14 (Python3): https://github.com/rockcesar/PiNetworkDevelopments/blob/master/website_pinetwork_odoo/controllers/main.py

Image of error: pi_dev

Sten435 commented 3 years ago

I have a simmular error, when i exec the payment function i dont get a response and the server just gives me a timeout after 6000ms

Sten435 commented 3 years ago

https://user-images.githubusercontent.com/44066744/123875336-c831c400-d939-11eb-9bd7-f826adf7501e.mp4

rockcesar commented 3 years ago

I have a simmular error, when i exec the payment function i dont get a response and the server just gives me a timeout after 6000ms

Share the specific code where you are defining the Pi.createPayment, to see if we can help.

EstherSarianSow commented 3 years ago

Can someone teach me about this app and how to pay

0205miss commented 3 years ago

Your input data is wrong for creating payment Change the amount data to number

0205miss commented 3 years ago

I have a simmular error, when i exec the payment function i dont get a response and the server just gives me a timeout after 6000ms

You need to post message to pi server to check the create payment. See the platform sdk to know how it post

Ibdende commented 3 years ago

Can someone teach me about this app and how to pay

SuperHax commented 3 years ago

I have a simmular error, when i exec the payment function i dont get a response and the server just gives me a timeout after 6000ms

Share the specific code where you are defining the Pi.createPayment, to see if we can help.

i got the same problem,how to fix this

aurelienshz commented 3 years ago

Hi @rockcesar ! Thanks for the detailed issue, and thanks for providing code examples. It makes it so much easier to help you.

From the code example you provided, it looks like you're passing an empty object as the payment's metadata here. That's why you're getting a validation error. Metadata is mandatory, because it enables the developer to know what the user was paying for, even if the payment failed to register on the developer's side (this is similar to the memo, but the memo is more of a user-facing description, whereas the metadata can be processed programmatically).

Since it looks like your app is simply receiving donations, you could put something to record this fact in the metadata - e.g {paymentType: "donation"}.

This is all up to your own internal business logic, but you just need to pass something in the payment's metadata object.

I do agree that this error was very obscure, and that it would have been much better if you had received a message like "metadata can't be empty". I've created a new issue with our internal issue tracker on the SDK side to record the fact that we should return a clearer error message.

rockcesar commented 3 years ago

Hello, @aurelienshz , thanks by detailed answer. I changed the code as you said, and it changed its behavior, but now I'm having the same issue than @Sten435

https://github.com/pi-apps/pi-platform-docs/issues/14#issuecomment-870958269

rockcesar commented 3 years ago

I updated the code in github, you can check the current code.

https://github.com/pi-apps/pi-platform-docs/issues/14#issue-933049175

0205miss commented 3 years ago

I updated the code in github, you can check the current code.

https://github.com/pi-apps/pi-platform-docs/issues/14#issue-933049175

You should do the ServerApproval by using platform SDK

rockcesar commented 3 years ago

I updated the code in github, you can check the current code. #14 (comment)

You should do the ServerApproval by using platform SDK

@aszasz1234 Do you have an example?.

rockcesar commented 3 years ago

Done, it is working, I sent the ServerApproval and ServerComplete.

@SuperHax @Sten435 @aurelienshz @aszasz1234

Check an example here:

Example app (Pi Browser): https://piapp-example.web.app/ Code: https://github.com/rockcesar/PiNetworkDevelopments/blob/master/PiDevelopment_test1/public/index.html

dannybutterfield1880 commented 3 years ago

Wait... You have merged the server side and client code? The approve and complete calls should not come from the client side as it includes the apiKey. This logic should be split. I am going to release a detailed guide later also using firebase functions but I have made it isomorphic with node, express and axios for the requests on the server side and react and axios on the client side

dannybutterfield1880 commented 3 years ago

@rockcesar sorry I'll explain if you send the API call from the client then the API key you are sending is exposed in the client network requests that why that request must be sent from the server and not the the browser

dannybutterfield1880 commented 3 years ago

@rockcesar that's not how it works.

IMG_20210701_190857.jpg

dannybutterfield1880 commented 3 years ago

@rockcesar what do you mean? Yes it will work but people will easily be able to see your API key if they know how too by inspecting the POST request. Therefore it's not viable. The server side code needs to run off a server and the client side on the client side it can't be combined

dannybutterfield1880 commented 3 years ago

No worries

dannybutterfield1880 commented 3 years ago

Nice šŸ‘ isomorphic JavaScript is completely different

dannybutterfield1880 commented 3 years ago

I'm not even trying to argue with you. I was simply trying to help! I suppose yeah your running PHP it is all running server side I understand that.

dannybutterfield1880 commented 3 years ago

Ohh ok, its dangerous running that code client side but whatever you won't listen

dannybutterfield1880 commented 3 years ago

This isn't correct though my friend

dannybutterfield1880 commented 3 years ago

I'm currently with my kids. Once they go to bed I'm going write up a guide on how to do the server side part of the payment process

dannybutterfield1880 commented 3 years ago

Ok I'm not arguing with you. That's fine but read the documentation first properly

dannybutterfield1880 commented 3 years ago

Lol your just being ridiculous now

dannybutterfield1880 commented 3 years ago

šŸ™„šŸ˜‚

dannybutterfield1880 commented 3 years ago

I would rather use the pi platform docs here thanks mate

chipmoon27 commented 3 years ago

Please guys lets stick to proper decorum here lets stay respectful, and on topic, with that said all aspects of the documentation should be adhered to for safety of the community.

Sten435 commented 3 years ago

I agree with @chipmoon27 there is no reason to debait on what is the best way to post an http request with an API key.

If you want to do it on the front-end and you know the risks and are fine with them then why not.

If you want to use it with a server to not expose your API key thats a bit safer but its personal prefferancess.

I and the rest here dont want a debait fight over chat.

Your both realy experianced and have your own thoughts about certain items...

Greetings Stan P

dannybutterfield1880 commented 3 years ago

@Sten435 I appreciate people knowing the risk and not caring. That's purely their choice, however the documentation states that the API key definitely should not be used client side. I was just trying to warn him that Core Team will probably not allow that and any developers doing that will be penalised.

Sten435 commented 3 years ago

@Sten435 I appreciate people knowing the risk and not caring. That's purely their choice, however the documentation states that the API key definitely should not be used client side. I was just trying to warn him that Core Team will probably not allow that and any developers doing that will be penalised.

Yea, i agree with you.

I think serverside is bether for safety and becuse of the docu.

Greetings Stan P

dannybutterfield1880 commented 3 years ago

Or just completely hide it in your server side like this server-side This example is using firebase cloud functions for the "server-side"

rockcesar commented 3 years ago

Ok, I did the server side.

You can watch an example of PHP here:

https://github.com/rockcesar/PiNetworkDevelopments/blob/master/server1.php

dannybutterfield1880 commented 3 years ago

@rockcesar that is awesome, a lot safer now šŸ‘. Are you able to call the /approve and /complete API endpoints? I'm currently receiving 500 errors from the pi servers.

rockcesar commented 3 years ago

@dannybutterfield1880 Yes, I got the same response, because I was sending this in the header. But I solved, in the header of the /approve and /complete call, only send Authorization: Key ...

In /complete, you have to send also the txid in the body.

rockcesar commented 3 years ago

I was sending in the header that the request was json, but it seems, it doesn't needs.

dannybutterfield1880 commented 3 years ago

@rockcesar @rockcesar I wasn't passing txid to the body šŸ™„šŸ¤¦šŸ¼ā€ā™‚ļøI knew I needed to just missed it while writing the code lol sorted now. Nice one šŸ‘

rockcesar commented 3 years ago

@dannybutterfield1880 cool!

Muhamadhendiabdilah commented 3 years ago

Adakah Apk yang bisa menjadikan pi uang nyat

rockcesar commented 3 years ago

Adakah Apk yang bisa menjadikan pi uang nyat

Not yet. But join Pi, soon will be in phase 3.

rockcesar commented 3 years ago

Ok, it was solved. I guess it can be closed.