-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add Tempo relay support #16
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
Merged
bensandler-stripe
merged 6 commits into
stripe:main
from
parvahuja:parv/tempo-relay-support
Aug 7, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cbbf26a
feat: add Tempo relay support
parvahuja 984c828
fix: harden relay credential lifecycle
parvahuja 2639669
refactor: apply relay review cleanups
parvahuja 0a7f028
fix: require relay example secret
parvahuja 9853254
fix: refine relay compatibility
parvahuja 3477f0b
test: clarify verifiable method fixture
parvahuja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Tempo relay charge | ||
|
|
||
| This example runs a Java HTTP endpoint that issues a route-bound Moderato pathUSD charge, | ||
| validates the credential through Tempo API, and asks the relay to finalize it. | ||
|
|
||
| ```sh | ||
| export TEMPO_API_KEY=tempo:sk:... | ||
| export MPP_RECIPIENT=0xYourRecipientAddress | ||
| export MPP_SECRET_KEY=$(openssl rand -base64 32) | ||
| ./gradlew runTempoRelayExample | ||
| ``` | ||
|
|
||
| The API key stays in the server process and needs the `mpp:write` scope. | ||
|
|
||
| | Route | Description | | ||
| | --- | --- | | ||
| | `GET /api/health` | Free health check | | ||
| | `GET /api/photo` | `0.01` pathUSD relay-backed charge | | ||
|
|
||
| The paid flow is: | ||
|
|
||
| 1. The server returns a `tempo/charge` challenge. | ||
| 2. The payer signs a pull transaction and retries with an MPP credential. | ||
| 3. The Java SDK calls `POST /v1/mpp/validate`, then `POST /v1/mpp/broadcast`. | ||
| 4. The relay receipt is returned in `Payment-Receipt`. |
97 changes: 97 additions & 0 deletions
97
examples/tempo-relay/src/main/java/com/stripe/mpp/examples/TempoRelayServer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.stripe.mpp.examples; | ||
|
|
||
| import com.stripe.mpp.Challenge; | ||
| import com.stripe.mpp.Json; | ||
| import com.stripe.mpp.Mpp; | ||
| import com.stripe.mpp.error.PaymentException; | ||
| import com.stripe.mpp.methods.tempo.TempoDefaults; | ||
| import com.stripe.mpp.methods.tempo.TempoMethod; | ||
| import com.stripe.mpp.server.ChargeRequest; | ||
| import com.stripe.mpp.server.MppHandler; | ||
| import com.stripe.mpp.server.VerifyResult; | ||
| import com.sun.net.httpserver.HttpExchange; | ||
| import com.sun.net.httpserver.HttpServer; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.InetSocketAddress; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Map; | ||
|
|
||
| /** Minimal HTTP server that accepts a Moderato pathUSD charge through Tempo API's relay. */ | ||
| public final class TempoRelayServer { | ||
| private TempoRelayServer() {} | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| String apiKey = required("TEMPO_API_KEY"); | ||
| String recipient = required("MPP_RECIPIENT"); | ||
| String secretKey = required("MPP_SECRET_KEY"); | ||
| int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080")); | ||
|
|
||
| TempoMethod tempo = TempoMethod.of().testnet().relay(apiKey).build(); | ||
| MppHandler payments = Mpp.create(tempo, "localhost:" + port, secretKey); | ||
| HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", port), 0); | ||
|
|
||
| server.createContext("/api/health", exchange -> { | ||
| if (!"GET".equals(exchange.getRequestMethod())) { | ||
| send(exchange, 405, Map.of("error", "method not allowed")); | ||
| return; | ||
| } | ||
| send(exchange, 200, Map.of("status", "ok")); | ||
| }); | ||
| server.createContext("/api/photo", exchange -> { | ||
| if (!"GET".equals(exchange.getRequestMethod())) { | ||
| send(exchange, 405, Map.of("error", "method not allowed")); | ||
| return; | ||
| } | ||
|
|
||
| ChargeRequest charge = ChargeRequest.of( | ||
| tempo.chargeIntent(), "0.01", TempoDefaults.TESTNET_PATH_USD, recipient | ||
| ).description("Relay-backed Java example") | ||
| .meta(Map.of("route", "/api/photo")); | ||
| try { | ||
| VerifyResult result = payments.charge( | ||
| exchange.getRequestHeaders().getFirst("Authorization"), charge | ||
| ); | ||
| if (result instanceof VerifyResult.Challenged) { | ||
| exchange.getResponseHeaders().add( | ||
| "WWW-Authenticate", | ||
|
parvahuja marked this conversation as resolved.
|
||
| ((VerifyResult.Challenged) result).challenge().toWwwAuthenticate() | ||
| ); | ||
| send(exchange, 402, Map.of("error", "payment required")); | ||
| return; | ||
| } | ||
|
|
||
| VerifyResult.Verified verified = (VerifyResult.Verified) result; | ||
| exchange.getResponseHeaders().set( | ||
| "Payment-Receipt", verified.receipt().toPaymentReceipt() | ||
| ); | ||
| send(exchange, 200, Map.of("ok", true, "message", "relay payment accepted")); | ||
| } catch (PaymentException error) { | ||
| Challenge retry = payments.challenge(charge); | ||
| exchange.getResponseHeaders().add("WWW-Authenticate", retry.toWwwAuthenticate()); | ||
| exchange.getResponseHeaders().set("Content-Type", "application/problem+json"); | ||
| send(exchange, error.getHttpStatus(), error.toProblemDetails(retry.id())); | ||
| } | ||
| }); | ||
|
|
||
| server.start(); | ||
| System.out.println("Tempo relay example listening on http://127.0.0.1:" + port); | ||
| } | ||
|
|
||
| private static String required(String name) { | ||
| String value = System.getenv(name); | ||
| if (value == null || value.isBlank()) throw new IllegalArgumentException("Set " + name); | ||
| return value; | ||
| } | ||
|
|
||
| private static void send(HttpExchange exchange, int status, Map<String, Object> body) | ||
| throws IOException { | ||
| byte[] bytes = Json.compact(body).getBytes(StandardCharsets.UTF_8); | ||
| if (exchange.getResponseHeaders().getFirst("Content-Type") == null) { | ||
| exchange.getResponseHeaders().set("Content-Type", "application/json"); | ||
| } | ||
| exchange.sendResponseHeaders(status, bytes.length); | ||
| exchange.getResponseBody().write(bytes); | ||
| exchange.close(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I like this