feat(payments): expose primary transfer candidate

This commit is contained in:
2026-08-27 15:38:24 -03:00
parent 6fb60c9a73
commit 5601285369
4 changed files with 121 additions and 1 deletions

View File

@@ -445,6 +445,38 @@ class TelepagosWebhookTest extends TestCase
]);
$this->assertSame(Purchase::STATUS_PENDING_PAYMENT, $nearAmountPurchase->fresh()->status);
$this->assertSame(Purchase::STATUS_PENDING_PAYMENT, $exactAmountDifferentDniPurchase->fresh()->status);
$higherPriorityPayment = TelepagosPayment::query()->create([
'cuit_buyer' => '20123456789',
'amount' => 52,
'operation_id' => 1,
'transaction_id' => 'tx-primary-candidate',
]);
$higherPriorityPayment->candidates()->create([
'compra_id' => $nearAmountPurchase->id,
'dni_matches' => true,
'amount_matches' => true,
'payment_amount' => 52,
'purchase_amount' => 52,
'amount_difference' => 0,
'match_reason' => 'ambiguous_exact_match',
'confidence' => 'exact',
]);
app(CheckoutService::class)->submitForReview($nearAmountPurchase->fresh());
$buyer = User::query()->findOrFail($nearAmountPurchase->user_id);
$this->actingAs($buyer, 'sanctum')
->getJson("/api/tenants/candidates/compras/{$nearAmountPurchase->id}")
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW)
->assertJsonPath('data.payment_verification.status', 'candidate')
->assertJsonPath('data.payment_verification.candidate_count', 2)
->assertJsonPath('data.payment_verification.primary.reason', 'ambiguous_exact_match')
->assertJsonPath('data.payment_verification.primary.amount_difference', '0.00')
->assertJsonPath('data.payment_verification.primary.confidence', 'exact')
->assertJsonPath('data.payment_verification.reasons.0', 'ambiguous_exact_match')
->assertJsonPath('data.payment_verification.reasons.1', 'exact_dni_near_amount');
}
public function test_webhook_confirms_a_purchase_with_tickets_enabled(): void