Skip to content

[good first issue] MPP client: implement pay() + pay_and_retry() for full HTTP-402 flow #8

@abhicris

Description

@abhicris

Context

src/mpp/mod.rs currently implements step 1 of the MPP / HTTP-402 flow: MppClient::request(url) hits a URL and returns either Success(body) or PaymentRequired(options). The trailing TODOs (pay(), session(), pay_and_retry()) are what close the loop — they turn a half-answer into a real autonomous-payment path. Implementing the 402 → pay → retry dance end-to-end on a mock server is a perfect newcomer ticket.

Scope

  • In src/mpp/mod.rs, implement:
    • MppClient::pay(&self, options: &PaymentOptions, wallet: &Wallet) -> Result<PaymentReceipt> — for now, support only method_type == "tempo" (simplest: POST to a payment endpoint encoded in details). Other methods return ArkaError::Mpp("unsupported").
    • MppClient::pay_and_retry(&self, url: &str, wallet: &Wallet) -> Result<String> — calls request, if PaymentRequired then pay, then re-requests with the receipt attached as an X-MPP-Receipt header, returning the body.
  • Spin up a mock server test with wiremock (add as dev-dep) that:
    1. First call to /data returns 402 with a PaymentOptions JSON body.
    2. POST to /pay returns a PaymentReceipt JSON.
    3. Second call to /data with header X-MPP-Receipt: <tx_hash> returns 200 with a payload.
      Assert pay_and_retry returns that payload.
  • Remove the matching // TODO: comments.

Acceptance criteria

  • cargo test mpp passes including the new wiremock test.
  • cargo clippy clean.
  • New method has rustdoc explaining the 402-retry state machine.
  • Unsupported payment methods return a typed error, not a panic.

Reference: the MppClient::request method already shows how reqwest + serde_json are used in the crate; PR #4 sets the CI conventions.

Estimated effort

S (3–5 hours)

kcolbchain / Abhishek Krishna

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions