Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Courier Fraud Checker Bd Laravel Package

shahariar-ahmad/courier-fraud-checker-bd

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require shahariar-ahmad/courier-fraud-checker-bd
    

    Add the service provider to config/app.php (Laravel 5.4+ auto-discovers it).

  2. Configure credentials: Add to .env:

    PATHAO_USER=your_pathao_email
    PATHAO_PASSWORD=your_pathao_password
    STEADFAST_USER=your_steadfast_email
    STEADFAST_PASSWORD=your_steadfast_password
    
  3. First use case: Check a customer’s fraud risk during order placement:

    $fraudRisk = CourierFraudCheckerBd::check($customerPhone);
    $isHighRisk = $fraudRisk['pathao']['cancel'] / ($fraudRisk['pathao']['total'] ?? 1) > 0.5;
    

Implementation Patterns

Workflow Integration

  1. Order Validation Middleware:

    // app/Http/Middleware/CheckFraudRisk.php
    public function handle($request, Closure $next) {
        $phone = $request->user()->phone;
        $risk = CourierFraudCheckerBd::check($phone);
        if ($this->isHighRisk($risk)) {
            return redirect()->route('fraud-review');
        }
        return $next($request);
    }
    
  2. Customer Model Observer:

    // app/Observers/CustomerObserver.php
    public function saved(Customer $customer) {
        if ($customer->is_first_order) {
            $risk = CourierFraudCheckerBd::check($customer->phone);
            $customer->update(['fraud_risk_score' => $this->calculateScore($risk)]);
        }
    }
    
  3. Batch Processing:

    // Process 100 customers in bulk (avoid rate limits)
    $phones = Customer::whereNull('fraud_risk_score')->limit(100)->pluck('phone');
    foreach ($phones as $phone) {
        $risk = CourierFraudCheckerBd::check($phone);
        // Update DB
    }
    

API Integration Tips

  • Rate Limiting: Cache results for 1 hour to avoid hitting API limits:
    $risk = Cache::remember("fraud_risk_{$phone}", now()->addHours(1), function() use ($phone) {
        return CourierFraudCheckerBd::check($phone);
    });
    
  • Async Processing: Use Laravel Queues for non-critical checks:
    CheckFraudJob::dispatch($customer->phone);
    

Gotchas and Tips

Pitfalls

  1. API Credentials:

    • Never hardcode credentials. Use Laravel’s .env and validate them in config/courier.php:
      'require_credentials' => env('COURIER_CHECK_ENABLED', true),
      
    • If PATHAO_USER is empty, the package silently skips Pathao checks.
  2. Phone Validation:

    • The package assumes valid BD numbers (e.g., 018xx). Add validation:
      use ShahariarAhmad\CourierFraudCheckerBd\Helpers\PhoneValidator;
      if (!PhoneValidator::isValidBdNumber($phone)) {
          throw new \InvalidArgumentException("Invalid phone number");
      }
      
  3. Rate Limits:

    • Couriers may block your IP if you exceed 50 requests/minute. Implement exponential backoff:
      try {
          $result = CourierFraudCheckerBd::check($phone);
      } catch (\ShahariarAhmad\CourierFraudCheckerBd\Exceptions\RateLimitException $e) {
          sleep(10); // Retry after 10 seconds
          retry();
      }
      

Debugging

  • Enable Logging: Add to config/courier.php:

    'debug' => env('COURIER_DEBUG', false),
    

    Logs API responses to storage/logs/courier_debug.log.

  • Mock Responses: For testing, override the API client:

    // tests/TestCase.php
    protected function getPackageProviders($app) {
        return [
            \ShahariarAhmad\CourierFraudCheckerBd\CourierFraudCheckerBdServiceProvider::class,
            \ShahariarAhmad\CourierFraudCheckerBd\Testing\CourierFraudCheckerBdTestServiceProvider::class,
        ];
    }
    

Extension Points

  1. Custom Risk Rules: Override the default risk calculation in app/Providers/CourierFraudCheckerBdServiceProvider.php:

    public function boot() {
        CourierFraudCheckerBd::extend(function ($risk) {
            $risk['custom_score'] = $this->calculateCustomScore($risk);
            return $risk;
        });
    }
    
  2. Add New Couriers: Extend the CourierChecker interface:

    class NewCourierChecker implements CourierChecker {
        public function check($phone) { /* ... */ }
    }
    

    Register it in the service provider’s register() method.

  3. Webhook Integration: Listen for courier webhooks to update fraud scores in real-time:

    Route::post('/courier/webhook', function (Request $request) {
        $data = $request->validate(['courier' => 'required', 'order_id' => 'required', 'status' => 'required']);
        // Update DB and recalculate risk
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle