@@ -126,8 +126,7 @@ class OpenCryptoPayApi {
126126 }
127127
128128 /// Notifies the provider of a locally broadcast transaction so the merchant
129- /// side can settle the payment. The `/tx/` endpoint is derived from the
130- /// payment details callback URL.
129+ /// side can settle the payment.
131130 Future <void > commitTxId ({
132131 required OpenCryptoPayCommit commit,
133132 required String txId,
@@ -161,7 +160,7 @@ class OpenCryptoPayApi {
161160 required OpenCryptoPayCommit commit,
162161 required Map <String , String > queryParameters,
163162 }) async {
164- final base = _commitEndpoint (commit.callbackUrl);
163+ final base = _commitEndpoint (commit.callbackUrl, commit.paymentId );
165164 _requireHttps (base , 'commit endpoint' );
166165 final uri = base .replace (
167166 queryParameters: {
@@ -181,15 +180,19 @@ class OpenCryptoPayApi {
181180 }
182181 }
183182
184- Uri _commitEndpoint (String callbackUrl) {
183+ Uri _commitEndpoint (String callbackUrl, String paymentId ) {
185184 final callback = Uri .parse (callbackUrl);
185+ if (paymentId.isEmpty) {
186+ throw Exception ('OpenCryptoPay: quote payment id is missing' );
187+ }
186188 final segments = callback.pathSegments.toList ();
187- final cbIndex = segments.indexOf ('cb' );
189+ final cbIndex = segments.lastIndexOf ('cb' );
188190 if (cbIndex == - 1 ) {
189191 throw Exception ('OpenCryptoPay: callback URL does not contain /cb/' );
190192 }
191- segments[cbIndex] = 'tx' ;
192- return callback.replace (pathSegments: segments);
193+ return callback.replace (
194+ pathSegments: [...segments.take (cbIndex), 'tx' , paymentId],
195+ );
193196 }
194197
195198 Uri _redactedUri (Uri uri) {
0 commit comments