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

Dpd Bundle Laravel Package

ekyna/dpd-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install via Composer

    composer require ekyna/dpd-bundle
    

    (Note: The package is outdated; verify compatibility with your Laravel/EkynaCommerce version.)

  2. Enable the Bundle In config/app.php, add to providers:

    Ekyna\DpdBundle\DpdBundle::class,
    

    And to aliases:

    'Dpd' => Ekyna\DpdBundle\DpdService::class,
    
  3. Configure DPD Credentials Add to config/services.php or config/packages/ekyna_dpd.yaml:

    dpd:
        api_key: '%env(DPD_API_KEY)%'
        account_number: '%env(DPD_ACCOUNT_NUMBER)%'
        test_mode: '%env(bool:DPD_TEST_MODE)%'
    
  4. First Use Case: Create a Shipment Inject DpdService into a controller/service and use:

    $shipment = $this->dpd->createShipment([
        'sender' => ['name' => 'Sender', 'address' => '123 Sender St'],
        'recipient' => ['name' => 'Recipient', 'address' => '456 Recipient Ave'],
        'parcels' => [
            ['weight' => 1.5, 'dimensions' => ['length' => 30, 'width' => 20, 'height' => 15]],
        ],
        'service' => 'DPDStandard', // Check available services in docs
    ]);
    

Implementation Patterns

Workflow: Order-to-Shipment Integration

  1. Hook into EkynaCommerce Events Listen for ekyna_commerce.order.shipped to trigger DPD shipment creation:

    use Ekyna\CommerceBundle\Event\OrderEvent;
    
    public function onOrderShipped(OrderEvent $event) {
        $order = $event->getOrder();
        $shipmentData = $this->mapOrderToDpdShipment($order);
        $this->dpd->createShipment($shipmentData);
    }
    
  2. Batch Processing For bulk shipments (e.g., nightly exports), use:

    $shipments = $this->orderRepository->getPendingShipments();
    foreach ($shipments as $order) {
        $this->dpd->createShipment($this->mapOrderToDpdShipment($order));
    }
    
  3. Tracking Integration Store DPD tracking numbers in your order model:

    $trackingNumber = $shipment->getTrackingNumber();
    $order->setTrackingNumber($trackingNumber)->save();
    

Common Patterns

  • Service Abstraction: Wrap DpdService in a repository to handle business logic:
    class DpdShipmentService {
        public function __construct(private DpdService $dpd) {}
    
        public function createFromOrder(Order $order) {
            // Transform order data to DPD format
            $data = [...];
            return $this->dpd->createShipment($data);
        }
    }
    
  • Fallback Logic: Handle DPD API failures gracefully:
    try {
        $shipment = $this->dpd->createShipment($data);
    } catch (DpdException $e) {
        $this->logger->error('DPD API failed', ['error' => $e->getMessage()]);
        throw new OrderShipmentException('Failed to create DPD shipment');
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated Package

    • Last updated in 2019; verify compatibility with:
      • EkynaCommerceBundle version.
      • Laravel framework (if using Ekyna’s Laravel wrapper).
    • Workaround: Use the standalone ekyna/dpd library directly if the bundle is incompatible.
  2. Missing Documentation

    • No clear docs for:
      • Available service types (e.g., DPDStandard, DPDExpress).
      • Required fields for sender/recipient/parcels.
    • Tip: Inspect the standalone DPD library for reference.
  3. Test Mode Quirks

    • test_mode: true may not simulate all API responses accurately.
    • Tip: Log raw API responses for debugging:
      $this->dpd->setLogger(function ($message) {
          \Log::debug('DPD API', ['message' => $message]);
      });
      
  4. Error Handling

    • Generic DpdException may obscure issues (e.g., invalid credentials vs. rate limits).
    • Tip: Extend the exception class for granular handling:
      class DpdValidationException extends DpdException {}
      

Tips

  1. Environment Variables Use .env for sensitive data:

    DPD_API_KEY=your_api_key_here
    DPD_ACCOUNT_NUMBER=123456
    DPD_TEST_MODE=true
    
  2. Retry Logic Implement exponential backoff for transient failures:

    use Symfony\Component\Process\Exception\ProcessFailedException;
    
    try {
        $this->dpd->createShipment($data);
    } catch (ProcessFailedException $e) {
        if ($e->getCode() === 500) { // Server error
            sleep(2 ** $attempt); // Exponential backoff
            retry();
        }
    }
    
  3. Logging Enable debug logging for API calls:

    # config/packages/monolog.yaml
    handlers:
        dpd:
            type: stream
            path: "%kernel.logs_dir%/dpd.log"
            level: debug
    
  4. Extending Functionality

    • Custom Services: Override DpdService to add methods like:
      public function getAvailableServices() {
          return $this->client->get('/services'); // Hypothetical endpoint
      }
      
    • Webhooks: Listen for DPD status updates via their API (if supported).
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware