Description
We need to implement a flexible payment flow for Data Vending Machine (DVM) service providers, allowing them to optionally request payment upfront or after job completion. This implementation should follow the NIP-90 DVM flow and integrate with NIP-57 for Lightning Zaps.
Requirements
-
Service provider configuration:
- Add a configuration option for each service provider to specify their preferred payment flow:
- Upfront payment required
- Payment after job completion
- Flexible (allow both options)
-
Job request handling:
- When receiving a job request (kind: 5600), check the service provider's payment configuration.
- If upfront payment is required, send a
kind: 7000 job feedback event with status: "payment-required" before processing the job.
-
Payment flow:
- Implement NIP-57 Lightning Zaps for payment processing.
- For upfront payments:
- Include an
amount tag in the kind: 7000 job feedback event.
- Wait for payment confirmation before proceeding with job processing.
- For payment after job completion:
- Include an
amount tag in the kind: 6600 job result event.
- Optionally send a
kind: 7000 job feedback event with status: "payment-required" after delivering results.
-
Payment verification:
- Implement a system to verify Lightning Zap receipts (kind: 9735) as described in NIP-57.
- Ensure that the payment amount matches the requested amount in the job feedback or job result event.
-
Job processing:
- For upfront payments: Begin processing the job only after payment confirmation.
- For payment after job completion: Deliver results and then request payment.
-
Error handling:
- Implement proper error handling for payment-related issues (e.g., insufficient payment, payment timeout).
- Send appropriate
kind: 7000 job feedback events with status: "error" and relevant error messages.
-
Partial results and progressive payments:
- Consider implementing support for partial results and progressive payments for long-running jobs.
- Use
kind: 7000 job feedback events with status: "partial" to deliver partial results and request progressive payments.
Implementation Steps
- Update the service provider configuration schema to include payment flow preferences.
- Modify the job request handler to check payment configuration and send appropriate feedback events.
- Implement NIP-57 Lightning Zaps integration for payment processing.
- Create a payment verification system for Lightning Zap receipts.
- Update the job processing flow to accommodate both upfront and post-completion payment scenarios.
- Implement error handling for payment-related issues.
- (Optional) Develop support for partial results and progressive payments.
Testing
- Create test cases for different payment flow configurations.
- Test upfront payment scenarios, ensuring job processing only begins after payment confirmation.
- Test payment after job completion scenarios, verifying result delivery and subsequent payment request.
- Verify proper handling of payment errors and edge cases.
- Test partial results and progressive payments (if implemented).
Documentation
- Update service provider documentation to explain the new payment flow options.
- Create user documentation explaining the different payment scenarios they may encounter.
- Document the integration with NIP-57 Lightning Zaps for developers.
Related NIPs
Description
We need to implement a flexible payment flow for Data Vending Machine (DVM) service providers, allowing them to optionally request payment upfront or after job completion. This implementation should follow the NIP-90 DVM flow and integrate with NIP-57 for Lightning Zaps.
Requirements
Service provider configuration:
Job request handling:
kind: 7000job feedback event withstatus: "payment-required"before processing the job.Payment flow:
amounttag in thekind: 7000job feedback event.amounttag in thekind: 6600job result event.kind: 7000job feedback event withstatus: "payment-required"after delivering results.Payment verification:
Job processing:
Error handling:
kind: 7000job feedback events withstatus: "error"and relevant error messages.Partial results and progressive payments:
kind: 7000job feedback events withstatus: "partial"to deliver partial results and request progressive payments.Implementation Steps
Testing
Documentation
Related NIPs