interledger / web-monetization-extension

An open-source browser extension that enables Web Monetization.
Apache License 2.0
46 stars 2 forks source link

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

Open lengyel-arpad85 opened 2 weeks ago

lengyel-arpad85 commented 2 weeks ago

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

sidvishnoi commented 2 weeks ago

I'll get to this after https://github.com/interledger/web-monetization-extension/issues/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 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

@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 commented 1 week ago

@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 commented 1 week ago

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

raducristianpopa commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

@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 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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 https://github.com/interledger/web-monetization-extension/issues/319#issuecomment-2165268478 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 commented 1 week ago

But I'm not following the trouble with cross-currency transactions (my question in https://github.com/interledger/web-monetization-extension/issues/319#issuecomment-2165268478 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 commented 1 day ago

cc @AlexLakatos