-
Notifications
You must be signed in to change notification settings - Fork 9
Critical Bug: HTTP PUT Requests Fail Due to Incorrect Connection Configuration #280
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Issue Summary
A critical bug exists in the ApiV3.kt file that prevents HTTP PUT requests from working correctly. The updateMerchantReferenceV3 method, which is essential for updating merchant references after checkout completion, will fail because the underlying HTTP connection is misconfigured.
Root Cause Analysis
In /afterpay/src/main/kotlin/com/afterpay/android/internal/ApiV3.kt, the configure method incorrectly sets up HTTP PUT requests:
HttpVerb.PUT -> {
connection.doInput = true
connection.doOutput = false // TODO: What? <-- THIS IS THE BUG
}The doOutput property is set to false for PUT requests, but it should be true because:
- HTTP PUT requires a request body - The method needs to send JSON payload to update merchant reference
- Java HttpURLConnection documentation states that
doOutputmust betruefor methods that send request bodies - The existing code writes to the output stream - Both
request()andrequestUnit()methods attempt to write payload toconnection.outputStream, which will fail ifdoOutputis false
Impact Assessment
Affected Functionality
Afterpay.updateMerchantReferenceV3()- BROKENAfterpay.updateMerchantReferenceV3Async()- BROKEN
Business Impact
- Merchants cannot update order references after checkout completion
- Integration flows that depend on merchant reference updates will fail
- This affects the core V3 checkout functionality documented in the README
Technical Impact
IOExceptionwill be thrown when attempting to getoutputStreamon a connection withdoOutput = false- Silent failures in production environments
- No error handling for this specific configuration issue
Evidence
- TODO comment indicates awareness: The "TODO: What?" comment shows the developer was uncertain about this configuration
- Missing test coverage: No unit tests exist for
ApiV3or theupdateMerchantReferenceV3method - Inconsistent configuration: POST requests correctly set
doOutput = true, but PUT does not
Proposed Solution
Change the PUT request configuration to match POST requests:
HttpVerb.PUT -> {
connection.doInput = true
connection.doOutput = true // FIX: Enable output for request body
}Testing Strategy
Since this functionality lacks test coverage, the following test scenarios should be added:
-
Unit tests for ApiV3.kt
- Test HTTP PUT request configuration
- Test request body serialization for PUT requests
- Test error handling for PUT requests
-
Integration tests for updateMerchantReferenceV3
- Test successful merchant reference update
- Test error scenarios (network failure, invalid tokens, etc.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working