feat: implement Telepagos webhook handling with request validation and service integration
This commit is contained in:
@@ -57,4 +57,33 @@ class Purchase extends Model
|
||||
{
|
||||
return $this->hasMany(PurchaseItem::class, 'compra_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne<TelepagosQr, $this>
|
||||
*/
|
||||
public function telepagosQr()
|
||||
{
|
||||
return $this->hasOne(TelepagosQr::class, 'compra_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<TelepagosPayment, $this>
|
||||
*/
|
||||
public function telepagosPayments(): HasMany
|
||||
{
|
||||
return $this->hasMany(TelepagosPayment::class, 'compra_id');
|
||||
}
|
||||
|
||||
public function getTotalAmount(): float
|
||||
{
|
||||
return (float) $this->items()->sum('total');
|
||||
}
|
||||
|
||||
public function finalize(): void
|
||||
{
|
||||
$this->update([
|
||||
'status' => 'pagado', // Or the equivalent final status in your system
|
||||
'payment_status' => 'paid',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
43
app/Domains/Purchase/Models/TelepagosPayment.php
Normal file
43
app/Domains/Purchase/Models/TelepagosPayment.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Purchase\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'compra_id',
|
||||
'cuit_buyer',
|
||||
'cvu_buyer',
|
||||
'amount',
|
||||
'concept',
|
||||
'operation',
|
||||
'operation_id',
|
||||
'transaction_id',
|
||||
'qr_order_id',
|
||||
'link_id',
|
||||
])]
|
||||
class TelepagosPayment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'telepagos_payments';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'compra_id' => 'integer',
|
||||
'amount' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Purchase, $this>
|
||||
*/
|
||||
public function compra(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Purchase::class, 'compra_id');
|
||||
}
|
||||
}
|
||||
35
app/Domains/Purchase/Models/TelepagosQr.php
Normal file
35
app/Domains/Purchase/Models/TelepagosQr.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Purchase\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'compra_id',
|
||||
'qr_order_id',
|
||||
'qr_code',
|
||||
])]
|
||||
class TelepagosQr extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'telepagos_qr';
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'compra_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Purchase, $this>
|
||||
*/
|
||||
public function compra(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Purchase::class, 'compra_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user