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

Support for url-encoded | additional fields on qrcode #673

Open
dcolley opened this issue Jun 12, 2022 · 0 comments
Open

Support for url-encoded | additional fields on qrcode #673

dcolley opened this issue Jun 12, 2022 · 0 comments

Comments

@dcolley
Copy link

dcolley commented Jun 12, 2022

We are implementing "Pay with Polkadot" Point-of-Sale feature here:
https://github.com/metaspan/metapay

The solution is opensource and can be self-hosted by any vendor / merchant.

Use cases

  1. Point-of-sale / Kiosk: generate QRcode with all relevant data - user scans with wallet and approves payment
    substrate://<address>:<genesisHash>:amount=1&reference=ref123
    The POS module can watch the address for any payment with reference, and mark the payment as complete.

  2. Webshop: Send a link to user to request payment
    https://pay.metaspan.io/paymentRequest/<address>:<genesisHash>?amount=1&reference=ref123 (to be implemented shortly ;)
    The browser will display a QRcode for wallet to scan
    Also, if available, will connect to polkadot.js (in the browser)
    An optional callback will notify the webshop that payment is done / error.

Broadly, it will embrace similar work already done at Solana Pay
https://github.com/solana-labs/solana-pay/blob/master/SPEC.md

Fearless Wallet should support additional fields via URL encoding in the comment

Current support - a QR code with:
substrate:<walletid>:<genesisHash>[:<comment>] - is supported

We need support for:
substrate:[//]<walletid>:<genesisHash>:[?]<url-encoded-fields>

Options for detecting additional fields

const parts = decodedQRString.split(':')
const protocol    = parts[0]
const address     = parts[1]
const genesisHash = parts[2]
const comment     = parts[3]

// Option 1
if (address.startsWith('//')) {}

// Option 2
if (comment && comment.startsWith('?')) {}

Example handler:

const parts = decodedQRString.split(':')
const protocol = parts[0]
if (protocol === 'substrate') {
  const address = parts[1]
  const comment = parts[3]
  if (address.startsWith('//') || ( comment && comment.startsWith('?') ) ) {
    // we have URL-encoded `comment` field
    /*
      [?]amount=<amount>
      &reference=<reference>
      &label=<label>
      &message=<message>
      &memo=<memo>
    */
  } else {
    // simple QR format
  }
} else {
  console.error('Invalid protocol')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant