updated plan, and oxapay integration

This commit is contained in:
Gitea
2025-06-21 04:09:08 +05:30
parent 930144f8f8
commit 30bd0c2712
14 changed files with 360 additions and 3 deletions

View File

@@ -46,6 +46,7 @@ class PlanResource extends Resource
TextInput::make('product_id')->required(),
TextInput::make('pricing_id')->required(),
TextInput::make('shoppy_product_id')->nullable(),
TextInput::make('oxapay_link')->nullable(),
TextInput::make('price')->numeric()->required(),
TextInput::make('mailbox_limit')->numeric()->required(),
Select::make('monthly_billing')->options([
@@ -60,6 +61,10 @@ class PlanResource extends Resource
1 => 'Activate',
0 => 'Disable',
])->required(),
Select::make('accept_oxapay')->options([
1 => 'Activate',
0 => 'Disable',
])->required(),
KeyValue::make('details')
->label('Plan Details (Optional)')
->keyPlaceholder('Name')

View File

@@ -0,0 +1,111 @@
<?php
namespace App\Http\Controllers;
use App\NotifyMe;
use Carbon\Carbon;
use Illuminate\Http\Request;
class WebhookController extends Controller
{
use NotifyMe;
public function oxapay(Request $request)
{
// Get the request data
$postData = $request->getContent();
$data = json_decode($postData, true);
// Validate request data
if (!$data || !isset($data['type']) || !in_array($data['type'], ['invoice', 'payment_link', 'payout'])) {
\Log::warning('Invalid Oxapay webhook data', ['data' => $data]);
return response('Invalid data.type', 400);
}
// Determine API secret key based on type
$apiSecretKey = $data['type'] === 'invoice'
? config('services.oxapay.merchant_api_key')
: config('services.oxapay.payout_api_key');
// Validate HMAC signature
$hmacHeader = $request->header('HMAC');
$calculatedHmac = hash_hmac('sha512', $postData, $apiSecretKey);
if (hash_equals($calculatedHmac, $hmacHeader)) {
// HMAC signature is valid
try {
if ($data['type'] === 'invoice' || $data['type'] === 'payment_link') {
// Process invoice payment data
$email = $data['email'] ?? 'Unknown';
$amount = $data['amount'] ?? 'Unknown';
$currency = $data['currency'] ?? 'Unknown';
$trackId = $data['track_id'] ?? 'Unknown';
$orderId = $data['order_id'] ?? 'N/A';
$date = isset($data['date']) ? Carbon::createFromTimestamp($data['date'])->toDateTimeString() : now()->toDateTimeString();
\Log::info('Received Oxapay invoice payment callback', [
'track_id' => $trackId,
'email' => $email,
'amount' => $amount,
'currency' => $currency,
'order_id' => $orderId,
'date' => $date,
]);
$message = "✅ Oxapay Invoice Payment Success\n" .
"Track ID: {$trackId}\n" .
"Email: {$email}\n" .
"Amount: {$amount} {$currency}\n" .
"Order ID: {$orderId}\n" .
"Time: {$date}";
self::sendTelegramNotification($message);
} elseif ($data['type'] === 'payout') {
// Process payout data
$trackId = $data['track_id'] ?? 'Unknown';
$amount = $data['amount'] ?? 'Unknown';
$currency = $data['currency'] ?? 'Unknown';
$network = $data['network'] ?? 'Unknown';
$address = $data['address'] ?? 'Unknown';
$txHash = $data['tx_hash'] ?? 'Unknown';
$description = $data['description'] ?? 'N/A';
$date = isset($data['date']) ? Carbon::createFromTimestamp($data['date'])->toDateTimeString() : now()->toDateTimeString();
\Log::info('Received Oxapay payout callback', [
'track_id' => $trackId,
'status' => $data['status'] ?? 'Unknown',
'amount' => $amount,
'currency' => $currency,
'network' => $network,
'address' => $address,
'tx_hash' => $txHash,
'description' => $description,
'date' => $date,
]);
$message = "📤 Oxapay Payout Confirmed\n" .
"Track ID: {$trackId}\n" .
"Amount: {$amount} {$currency}\n" .
"Network: {$network}\n" .
"Address: {$address}\n" .
"Transaction Hash: {$txHash}\n" .
"Description: {$description}\n" .
"Date: {$date}";
self::sendTelegramNotification($message);
}
return response('OK', 200);
} catch (\Exception $e) {
\Log::error('Oxapay webhook processing error', ['error' => $e->getMessage(), 'data' => $data]);
self::sendTelegramNotification("
Failed to process Oxapay webhook\n
Type: {$data['type']}\n
Email/Track ID: " . ($data['type'] === 'invoice' ? ($data['email'] ?? 'Unknown') : ($data['track_id'] ?? 'Unknown')) . "\n
Error: {$e->getMessage()}
");
return response('Processing error', 400);
}
} else {
\Log::warning('Invalid Oxapay HMAC signature', ['hmac_header' => $hmacHeader, 'calculated_hmac' => $calculatedHmac]);
return response('Invalid HMAC signature', 400);
}
}
}

View File

@@ -14,6 +14,8 @@ class Plan extends Model
'shoppy_product_id',
'accept_stripe',
'accept_shoppy',
'oxapay_link',
'accept_oxapay',
'price',
'mailbox_limit',
'monthly_billing',

View File

@@ -12,11 +12,12 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Str;
use Laravel\Cashier\Billable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable implements FilamentUser, MustVerifyEmail
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, Billable;
use HasFactory, Notifiable, Billable, HasApiTokens;
/**
* The attributes that are mass assignable.