|
2 | 2 | title: How payments work
|
3 | 3 | ---
|
4 | 4 |
|
| 5 | +import { LinkOut, CodeBlock } from "@interledger/docs-design-system"; |
| 6 | +import { Badge, Tabs, TabItem } from '@astrojs/starlight/components'; |
| 7 | + |
5 | 8 | ## Digital wallets
|
6 | 9 |
|
7 | 10 | To receive (and send) payments, you must have an account with a compatible digital wallet. Not all digital wallets support receiving payments with Web Monetization.
|
@@ -38,4 +41,91 @@ When you include the `<link>` element on a page, you're telling your visitors' b
|
38 | 41 |
|
39 | 42 | Your visitors' Web Monetization extension acts like a messaging service. When they land on your page, their extension identifies the `<link>` element and parses your payment URL.
|
40 | 43 |
|
41 |
| -Then, a component within the extension--called the [Web Monetization agent](/experiment/link-element#web-monetization-agent)--issues a `GET` request to your payment URL. In return, it receives the information it needs to begin setting up a payment. The Web Monetization agent passes the information, along with the visitor's payment instructions, to the visitor's wallet provider. The visitor's wallet provider then sends the payment to your wallet provider who credits your account. |
| 44 | +Then, a component within the extension--called the [Web Monetization agent](/experiment/link-element#web-monetization-agent)--issues a <Badge text="GET" variant="success" size="small" /> request to your payment URL. In return, it receives the information it needs to begin setting up a payment. The Web Monetization agent passes the information, along with the visitor's payment instructions, to the visitor's wallet provider. The visitor's wallet provider then sends the payment to your wallet provider who credits your account. |
| 45 | + |
| 46 | +### A deeper dive into payments |
| 47 | + |
| 48 | +For a wallet to be compatible with Web Monetization, the provider must integrate with the <LinkOut href="https://openpayments.dev">Open Payments standard</LinkOut>. |
| 49 | + |
| 50 | +The Web Monetization agent first issues a <Badge text="GET" variant="note" size="small" /> request to the URL in your monetization `<link>` tag. The response contains information the Web Monetization agent needs for its next request. |
| 51 | + |
| 52 | +<Tabs> |
| 53 | + <TabItem label="Request"> |
| 54 | + ```http |
| 55 | + GET /alice HTTP/1.1 |
| 56 | + Accept: application/json |
| 57 | + Host: wallet.example |
| 58 | + ``` |
| 59 | + </TabItem> |
| 60 | + <TabItem label="Response"> |
| 61 | + ```http |
| 62 | + HTTP/1.1 200 Success |
| 63 | + Content-Type: application/json |
| 64 | +
|
| 65 | + { |
| 66 | + "id":"https://wallet.example/alice", |
| 67 | + "assetCode":"USD", |
| 68 | + "assetScale":2, |
| 69 | + "authServer":"https://wallet.example/auth", |
| 70 | + "resourceServer":"https://wallet.example/resource" |
| 71 | + } |
| 72 | + ``` |
| 73 | + </TabItem> |
| 74 | +</Tabs> |
| 75 | + |
| 76 | +Next, the Web Monetization agent issues a <Badge text="POST" variant="success" size="small" /> request to the `authServer` URL it received in the prior response. The purpose of this request is to get permission, in the form of an access token, for an incoming payment resource to be created on your payment account. |
| 77 | + |
| 78 | +<Tabs> |
| 79 | + <TabItem label="Request"> |
| 80 | + ```http |
| 81 | + POST /auth/ HTTP/1.1 |
| 82 | + Accept: application/json |
| 83 | + Content-Type: application/json |
| 84 | + Host: wallet.example |
| 85 | + Content-Length: 218 |
| 86 | +
|
| 87 | + { |
| 88 | + "access_token":{ |
| 89 | + "access":[ |
| 90 | + { |
| 91 | + "type":"incoming-payment", |
| 92 | + "actions":[ |
| 93 | + "create", |
| 94 | + "read" |
| 95 | + ], |
| 96 | + "identifier":"https://wallet.example/alice" |
| 97 | + } |
| 98 | + ] |
| 99 | + }, |
| 100 | + "interact":{ |
| 101 | + "finish":{ |
| 102 | + "method":"redirect" |
| 103 | + } |
| 104 | + }, |
| 105 | + "client":"https://anotherwallet.example/bob" |
| 106 | + } |
| 107 | + ``` |
| 108 | + </TabItem> |
| 109 | + <TabItem label="Response"> |
| 110 | + ```http |
| 111 | + { |
| 112 | + "access_token":{ |
| 113 | + "value":"OS9M2PMHKUR64TB8N6BW7OZB8CDFONP219RP1LT0", |
| 114 | + "manage":"https://wallet.example/auth/token/dd17a202-9982-4ed9-ae31-564947fb6379", |
| 115 | + "access":[ |
| 116 | + { |
| 117 | + "type":"incoming-payment", |
| 118 | + "actions":[ |
| 119 | + "create", |
| 120 | + "read" |
| 121 | + ], |
| 122 | + "identifier":"https://wallet.example/alice" |
| 123 | + } |
| 124 | + ] |
| 125 | + } |
| 126 | + } |
| 127 | + ``` |
| 128 | + </TabItem> |
| 129 | +</Tabs> |
| 130 | + |
| 131 | +Start at step 4: https://webmonetization.org/docs/intro/web-monetization-flow/#4---send-incoming-payment-request-to-wallet-address-receiving-account |
0 commit comments