Changes to handling of refunds in Anrok (#4556)

* Use negations, track transaction version/accounting time, use original charge accounting time in refunds

* query cache

* chore: query cache, clippy, fmt

* Fix tax drift calculation

* Fix migration

* Increase update_tax_transactions rate
This commit is contained in:
François-Xavier Talbot
2025-10-17 16:57:36 +01:00
committed by GitHub
parent b23d3e674f
commit 5db5bf4c4c
18 changed files with 530 additions and 318 deletions

View File

@@ -182,6 +182,60 @@ impl Client {
.await
}
pub async fn negate_or_create_partial_negation(
&self,
original_txn_anrok_id: String,
original_txn_version: i32,
original_txn_tax_amount_with_tax: i64,
body: &Transaction,
) -> Result<(), AnrokError> {
let refund_amount = body
.fields
.line_items
.iter()
.map(|l| l.amount_in_smallest_denominations)
.sum::<i64>();
if -refund_amount == original_txn_tax_amount_with_tax {
self.create_full_negation(
original_txn_anrok_id,
original_txn_version,
body.id.clone(),
)
.await?;
} else {
self.create_or_update_txn(body).await?;
}
Ok(())
}
pub async fn create_full_negation(
&self,
original_txn_anrok_id: String,
original_txn_version: i32,
new_txn_id: String,
) -> Result<EmptyResponse, AnrokError> {
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct NegationBody {
original_transaction_id: String,
new_transaction_id: String,
original_transaction_expected_version: i32,
}
self.make_request(
Method::POST,
"/v1/seller/transactions/createNegation",
Some(&NegationBody {
original_transaction_id: original_txn_anrok_id,
new_transaction_id: new_txn_id,
original_transaction_expected_version: original_txn_version,
}),
)
.await
}
pub async fn create_or_update_txn(
&self,
body: &Transaction,