feat(payments): filter candidates by DNI distance
This commit is contained in:
@@ -351,6 +351,8 @@ class TelepagosWebhookTest extends TestCase
|
||||
|
||||
$nearAmountVariant = $this->createVariantForTenant('candidates', 10, '52.00', 'near');
|
||||
$exactAmountVariant = $this->createVariantForTenant('candidates', 10, '50.00', 'exact');
|
||||
$distanceTwoExactAmountVariant = $this->createVariantForTenant('candidates', 10, '50.00', 'distance-two');
|
||||
$farExactAmountVariant = $this->createVariantForTenant('candidates', 10, '50.00', 'far-exact');
|
||||
$nearAmountDifferentDniVariant = $this->createVariantForTenant('candidates', 10, '51.00', 'near-other-dni');
|
||||
$outsideRangeVariant = $this->createVariantForTenant('candidates', 10, '100.00', 'outside');
|
||||
|
||||
@@ -366,8 +368,22 @@ class TelepagosWebhookTest extends TestCase
|
||||
User::factory()->create()->id,
|
||||
$exactAmountVariant->id,
|
||||
1,
|
||||
'12345687',
|
||||
);
|
||||
$farExactAmountDifferentDniPurchase = $this->createPendingTransferPurchase(
|
||||
$tenant,
|
||||
User::factory()->create()->id,
|
||||
$farExactAmountVariant->id,
|
||||
1,
|
||||
'87654321',
|
||||
);
|
||||
$distanceTwoExactAmountPurchase = $this->createPendingTransferPurchase(
|
||||
$tenant,
|
||||
User::factory()->create()->id,
|
||||
$distanceTwoExactAmountVariant->id,
|
||||
1,
|
||||
'12345087',
|
||||
);
|
||||
$nearAmountDifferentDniPurchase = $this->createPendingTransferPurchase(
|
||||
$tenant,
|
||||
User::factory()->create()->id,
|
||||
@@ -412,11 +428,15 @@ class TelepagosWebhookTest extends TestCase
|
||||
$this->assertEqualsCanonicalizing([
|
||||
$nearAmountPurchase->id,
|
||||
$exactAmountDifferentDniPurchase->id,
|
||||
$distanceTwoExactAmountPurchase->id,
|
||||
], $payment->candidates()->pluck('compra_id')->all());
|
||||
$this->assertDatabaseHas('telepagos_payment_candidates', [
|
||||
'telepagos_payment_id' => $payment->id,
|
||||
'compra_id' => $nearAmountPurchase->id,
|
||||
'dni_matches' => true,
|
||||
'dni_distance' => 0,
|
||||
'payment_dni' => '12345678',
|
||||
'purchase_dni' => '12345678',
|
||||
'amount_matches' => false,
|
||||
'payment_amount' => 50,
|
||||
'purchase_amount' => 52,
|
||||
@@ -428,6 +448,9 @@ class TelepagosWebhookTest extends TestCase
|
||||
'telepagos_payment_id' => $payment->id,
|
||||
'compra_id' => $exactAmountDifferentDniPurchase->id,
|
||||
'dni_matches' => false,
|
||||
'dni_distance' => 1,
|
||||
'payment_dni' => '12345678',
|
||||
'purchase_dni' => '12345687',
|
||||
'amount_matches' => true,
|
||||
'payment_amount' => 50,
|
||||
'purchase_amount' => 50,
|
||||
@@ -435,6 +458,20 @@ class TelepagosWebhookTest extends TestCase
|
||||
'match_reason' => 'exact_amount_different_dni',
|
||||
'confidence' => 'medium',
|
||||
]);
|
||||
$this->assertDatabaseHas('telepagos_payment_candidates', [
|
||||
'telepagos_payment_id' => $payment->id,
|
||||
'compra_id' => $distanceTwoExactAmountPurchase->id,
|
||||
'dni_matches' => false,
|
||||
'dni_distance' => 2,
|
||||
'payment_dni' => '12345678',
|
||||
'purchase_dni' => '12345087',
|
||||
'amount_matches' => true,
|
||||
'match_reason' => 'exact_amount_different_dni',
|
||||
]);
|
||||
$this->assertDatabaseMissing('telepagos_payment_candidates', [
|
||||
'telepagos_payment_id' => $payment->id,
|
||||
'compra_id' => $farExactAmountDifferentDniPurchase->id,
|
||||
]);
|
||||
$this->assertDatabaseMissing('telepagos_payment_candidates', [
|
||||
'telepagos_payment_id' => $payment->id,
|
||||
'compra_id' => $nearAmountDifferentDniPurchase->id,
|
||||
@@ -455,6 +492,9 @@ class TelepagosWebhookTest extends TestCase
|
||||
$higherPriorityPayment->candidates()->create([
|
||||
'compra_id' => $nearAmountPurchase->id,
|
||||
'dni_matches' => true,
|
||||
'dni_distance' => 0,
|
||||
'payment_dni' => '12345678',
|
||||
'purchase_dni' => '12345678',
|
||||
'amount_matches' => true,
|
||||
'payment_amount' => 52,
|
||||
'purchase_amount' => 52,
|
||||
|
||||
Reference in New Issue
Block a user