# Pay machine-payment merchants

Use a shared payment token to pay merchants that accept machine payments over HTTP 402.

Accepting [machine payments](https://docs.stripe.com/payments/machine.md) requires a [shared payment token](https://docs.stripe.com/agentic-commerce/concepts/shared-payment-tokens.md) instead of a card number. Use this flow when a request returns HTTP 402 with a `WWW-Authenticate` header.

## Before you begin

Before you begin, make sure that:

- You’ve [set up OAuth](https://docs.stripe.com/agentic-commerce/link-cli/oauth.md), including the `payment_methods.agentic` scope.
- You’re familiar with [retrieving payment credentials with spend requests](https://docs.stripe.com/agentic-commerce/link-cli/use-link-wallet-pay-online.md).

## Decode the payment challenge

Decode the `WWW-Authenticate` header to get the `network_id` you need for the spend request:

```bash
link-cli mpp decode \
  --challenge 'Payment id="ch_001", realm="merchant.example", method="stripe", intent="charge", request="..."'
```

## Create a shared payment token request

Create a spend request for a shared payment token, passing the `network_id` from the previous step:

```bash
link-cli spend-request create \
  --credential-type shared_payment_token \
  --network-id NETWORK_ID \
  --amount 100 \
  --context "Contributing to a climate project through the merchant's machine payment endpoint, requested by the customer."
```

Present the `approval_url` to the customer, then poll until the request is approved. For the full set of statuses and next actions, see [Retrieve payment credentials with spend requests](https://docs.stripe.com/agentic-commerce/link-cli/use-link-wallet-pay-online.md#spend-request-statuses).

## Complete the payment

After the customer approves the request, complete the payment:

```bash
link-cli mpp pay https://climate.stripe.dev/api/contribute \
  --spend-request-id lsrq_abc123 \
  --method POST \
  --data '{"amount":100}'
```

The shared payment token is one-time-use. If the payment fails, create a new spend request rather than retrying with the same token.

## See also

- [Retrieve payment credentials with spend requests](https://docs.stripe.com/agentic-commerce/link-cli/use-link-wallet-pay-online.md)
- [Machine payments](https://docs.stripe.com/payments/machine.md)
