Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WM dev tools - Expose some of the functionality/trigger on window.webmonetization #319

Open
3 tasks
lengyel-arpad85 opened this issue Jun 10, 2024 · 16 comments
Assignees
Labels
blocked enhancement New feature or request Web Monetization Tools in support of Web Monetization tools functionality

Comments

@lengyel-arpad85
Copy link

lengyel-arpad85 commented Jun 10, 2024

Context

In order to be able to trigger the one time payment window from webmonetization tools / elements embedded in websites we will need a function that triggers the one time payment window of the extension

Todos

  • on window.webmonetization we should have a function (ex: triggerOnetimePaymentWindow) that is callable from a button or element in a webpage, that triggers the one time payment window
  • parameter value for passing a currency amount (maybe consider having currency as well as a parameter, and possibly asset scale)
  • parameter message for passing a message from the visitor (if we support messages in one time payments)
@lengyel-arpad85 lengyel-arpad85 added enhancement New feature or request Web Monetization Tools in support of Web Monetization tools functionality labels Jun 10, 2024
@tselit tselit added this to the WM extension 1.0.0-beta milestone Jun 10, 2024
@tselit tselit changed the title Expose some of the functionality/trigger on window.webmonetization WM dev tools - Expose some of the functionality/trigger on window.webmonetization Jun 10, 2024
@sidvishnoi
Copy link
Member

sidvishnoi commented Jun 12, 2024

I'll get to this after #9, as both require the polyfill to interact with page correctly.

I think we should try to align the API similar to PaymentRequest [1] [2], maybe call it ExperimentalMonetizationRequest for now, as it's something unofficial. In future, the extension can "polyfill" the API when it's somewhat standardized but not supported in browser.

So, it could look something like:

const request = new ExperimentalMonetizationRequest(
  [
    {
      supportedMethods: ["open-payments"],
      data: { walletUrl: "https://rafiki.money/foo" }, // receiver; sender decided by browser/extension
    },
  ],
  { total: { label: "custom message", amount: { currency, value } } },
); // can throw if a "bad request"
try {
  const response = await request.show();
  // resolves after payment is "completed"
  // should include result similar to MonetizationEvent
} catch (err) {
  // decide what can throw. errors like user rejected prompt, payment failed for some reason etc.
}

For a quicker less-thoughtful version, we can add a window.__wm_extension_requestPayment(...).

@raducristianpopa
Copy link
Member

I don't think we will need to pass the wallet addresses to the extension since they are already sent to the background (even if WM is disabled).

parameter value for passing a currency amount (maybe consider having currency as well as a parameter, and possibly asset scale)

What's the use case for passing a currency amount or the asset code/scale? I'm not too keen about letting the website specify a payment amount - if that's the intent.

parameter message for passing a message from the visitor (if we support messages in one time payments)

The message parameter is set by the page?

@sidvishnoi
Copy link
Member

I'm not too keen about letting the website specify a payment amount - if that's the intent.

That's the intent here.

@lengyel-arpad85
Copy link
Author

@raducristianpopa one of the elements discussed is a widget
screen-capture (3).webm
something similar to this ^

and the idea is that the website owner could embed this into their website as a call to action, and they can configure this to show a desired amount for a one time donation
the widget functionality is not suppose to make the payment, just trigger the one time payment window of the extension, but have the amount prefilled (posibly the message as well), so the users aren't forced to fill these things twice (but have the option to change it if they want to)

@raducristianpopa
Copy link
Member

@raducristianpopa one of the elements discussed is a widget screen-capture (3).webm something similar to this ^

and the idea is that the website owner could embed this into their website as a call to action, and they can configure this to show a desired amount for a one time donation the widget functionality is not suppose to make the payment, just trigger the one time payment window of the extension, but have the amount prefilled (posibly the message as well), so the users aren't forced to fill these things twice (but have the option to change it if they want to)

The main concern about this approach is the cross-currency scenario. What happens if the configured wallet address for the widget is using ZAR as an asset and the connected wallet address is in USD? If the website owner configures the widget with 50 ZAR, the prefilled amount will be 50 (as USD).

This approach can work if we use the receiveAmount property when creating the quote - which needs to be in the receiver's asset, but the WM user will pay the amount + additional fees (50ZAR as USD + fees if they are present).

@lengyel-arpad85
Copy link
Author

ah ... I understand now
can we somehow display the currency on the widget/element from tools ... as in read it from the extension?

@raducristianpopa
Copy link
Member

raducristianpopa commented Jun 13, 2024

ah ... I understand now can we somehow display the currency on the widget/element from tools ... as in read it from the extension?

Just to make sure I am getting this right: returning the connected wallet asset information from the extension?

@lengyel-arpad85
Copy link
Author

ah ... I understand now can we somehow display the currency on the widget/element from tools ... as in read it from the extension?

Just to make sure I am getting this right: returning the connected wallet asset information from the extension?

yes, in order to display the currency in the tool/widget that the website owner expects, so visitor can see that the amount is in ZAR ... so visitor won't be so confused when the extension displays the 50ZAR as USD

@sidvishnoi
Copy link
Member

@lengyel-arpad85 Reading any details from users wallet before any payment would be a privacy leak.

@raducristianpopa Isn't cross-currency payments something we'd support eventually? How different it would be if the <link> tag provided a different currency? Is the issue with how we display prompt to extension user?

@lengyel-arpad85
Copy link
Author

lengyel-arpad85 commented Jun 13, 2024

Reading any details from users wallet before any payment would be a privacy leak.

@sidvishnoi Not the users wallet (we aren't reading anything from the user/visitor with the WM tools), but site owner, if they use any call to action, they would need to display what amount they suggest ... 5 isn't saying much compared to $5 or €5
so we won't make another option in the tool config, but rather read the actual currency that is expected / already configured for the WM ext

@sidvishnoi
Copy link
Member

Correct me if I'm wrong or missing something, if we pass a wallet URL, we can fetch it's currency, and the site owner also knows the currency. If we pass this detail to extension, we can convert the rate before showing (or show both rates to extension user). We can also require that the passed wallet URL and parameters have same currency.

The site owner can show their preferred currency in their CTA, but then extension should translate it for extension-user/site-visitor in the extension prompt. It's similar to how payments work with cards at the moment (minus currency specific conversions that some sites provide).

@lengyel-arpad85
Copy link
Author

Correct me if I'm wrong or missing something, if we pass a wallet URL, we can fetch it's currency, and the site owner also knows the currency. If we pass this detail to extension, we can convert the rate before showing (or show both rates to extension user). We can also require that the passed wallet URL and parameters have same currency.

The site owner can show their preferred currency in their CTA, but then extension should translate it for extension-user/site-visitor in the extension prompt. It's similar to how payments work with cards at the moment (minus currency specific conversions that some sites provide).

the issue is probably that I'm thinking on the WM tools side, and there's little overlap with the extension
on the tools side I only need a way to trigger the extension with some values to be prefilled, I do not need any logic / conversion and other things that the extension handles

all I'm trying to solve is instead of the visitor clicking on the extension => one time payment => window opens from the extension,
the visitor clicks my button/banner/widget => which triggers the one time payment window open and the users continue from there just as they would when they clicked the extension to open that window

for me to display an amount on the button or widget I don't need to know anything from the user, I only need to know the site owners expectation of currency ... after the one time window of the extension is triggered, you can use conversion or any other logic needed on the extension side

@raducristianpopa
Copy link
Member

raducristianpopa commented Jun 14, 2024

Correct me if I'm wrong or missing something, if we pass a wallet URL, we can fetch it's currency, and the site owner also knows the currency. If we pass this detail to extension, we can convert the rate before showing (or show both rates to extension user). We can also require that the passed wallet URL and parameters have same currency.
The site owner can show their preferred currency in their CTA, but then extension should translate it for extension-user/site-visitor in the extension prompt. It's similar to how payments work with cards at the moment (minus currency specific conversions that some sites provide).

the issue is probably that I'm thinking on the WM tools side, and there's little overlap with the extension on the tools side I only need a way to trigger the extension with some values to be prefilled, I do not need any logic / conversion and other things that the extension handles

all I'm trying to solve is instead of the visitor clicking on the extension => one time payment => window opens from the extension, the visitor clicks my button/banner/widget => which triggers the one time payment window open and the users continue from there just as they would when they clicked the extension to open that window

for me to display an amount on the button or widget I don't need to know anything from the user, I only need to know the site owners expectation of currency ... after the one time window of the extension is triggered, you can use conversion or any other logic needed on the extension side

Maybe we can find another solution for this. With the current extension, the user needs to type the amount for a OTP. Instead of letting the user type in the amount, we can have some predefined amounts (see image below)?

SETUP

If the connected wallet address is not USD, we can perform the FX for the predefined amounts when the user connects the wallet - just like we do for the rates of pay.

With an approach like this, the website owner will not be able to configure an amount when setting up the widget.

@sidvishnoi
Copy link
Member

Showing pre-filled amounts is definitely a UX improvement over user entering details (including on the connect screen).

But I'm not following the trouble with cross-currency transactions (my question in #319 (comment) still).

With an approach like this, the website owner will not be able to configure an amount when setting up the widget.

I think we'd need some product discussion whether this should supported or not. Publishers would definitely want being able to configure amount IMO. Perhaps during Thursday's WM catch-up call.

i.e. requestPayment(amount) vs requestTip() - the use case.

@raducristianpopa
Copy link
Member

raducristianpopa commented Jun 17, 2024

But I'm not following the trouble with cross-currency transactions (my question in #319 (comment) still).

Yes, cross-currency transactions will be supported out of the box.

The main problem: If we enable something like requestPayment(amount), we will need to perform FX every time we open the popup pragmatically, in order to prefill the amount input field with a value that is represented in the connected wallet asset. For this, we will need a FX service with all possible currencies (crypto as well).

@RabebOthmani
Copy link
Collaborator

cc @AlexLakatos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked enhancement New feature or request Web Monetization Tools in support of Web Monetization tools functionality
Projects
Status: Blocked
Development

No branches or pull requests

5 participants