gosuccess/digistore24-ipn 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gosuccess/digistore24-ipn

Composer 安装命令:

composer require gosuccess/digistore24-ipn

包简介

Composer Library for the Digistore24 IPN.

README 文档

README

Latest Version GitHub Tests License PHP Version

A modern PHP 8.4+ library for handling Digistore24 Instant Payment Notification (IPN) webhooks. This package provides typed DTOs with Property Hooks for all possible webhook fields, signature validation, and helper utilities to make integration with Digistore24's IPN system easy and secure.

Features

  • 🚀 PHP 8.4 Property Hooks - Automatic type conversion and validation
  • 📦 Typed DTOs for all Digistore24 IPN fields with snake_case names matching DS24 API exactly
  • 🔐 Signature validation for secure webhook processing
  • 🎯 Enum support for event types and other constants
  • Zero reflection - Direct property access for maximum performance
  • 🛡️ Exception handling for invalid IPN data

Requirements

  • PHP 8.4 or higher
  • Composer

Installation

Install via Composer:

composer require gosuccess/digistore24-ipn

Usage

Receiving and Validating an IPN

<?php

use GoSuccess\Digistore24\Ipn\Notification;
use GoSuccess\Digistore24\Ipn\Response;
use GoSuccess\Digistore24\Ipn\Enum\Event;
use GoSuccess\Digistore24\Ipn\Security\Signature;
use GoSuccess\Digistore24\Ipn\Exception\FormatException;

require_once __DIR__ . '/vendor/autoload.php';

$shaPassphrase = 'your-secret-passphrase';

try {
    // Validate the signature first
    Signature::validateSignature('your-secret-passphrase', $_POST);
    
    // Create notification object from IPN data
    $notification = Notification::fromPost();

    // Access fields directly (no getter methods!)
    $event = $notification->event;
    $orderId = $notification->order_id;
    $amount = $notification->amount_brutto;
    $email = $notification->email;
    
    // Tags are automatically converted to array
    $tags = $notification->tags; // ['tag1', 'tag2', 'tag3']
    $firstTag = $notification->tags[0] ?? null;

    // Process the event
    switch ($event) {
        case Event::ON_PAYMENT:
            // Handle payment event
            
            // Create response
            $response = new Response();
            $response->headline = 'Login Details';
            $response->addLoginBlock(
                'username',
                'password',
                'https://example.com/login'
            );
            $response->addLoginBlock(
                'another_username',
                'another_password',
                'https://example.com/another-login'
            );
            $response->setAdditionalData('key1', 'value1');
            $response->setAdditionalData('License Key', '123-456-789');
            die($response->toString());
            break;
            
        case Event::ON_PAYMENT_MISSED:
            // Handle missed payment event
            break;
            
        case Event::LAST_PAID_DAY:
            // Handle last paid day event
            break;
            
        default:
            throw new FormatException('Unknown event type!');
    }
    
} catch (FormatException $e) {
    // Handle invalid signature or data
    http_response_code(400);
    error_log('IPN Error: ' . $e->getMessage());
    echo 'ERROR: ' . htmlspecialchars($e->getMessage());
    exit;
}

Property Access

All properties use snake_case names matching the Digistore24 IPN API exactly:

// Direct property access (PHP 8.4 Property Hooks)
$notification->order_id          // instead of getOrderId()
$notification->amount_brutto     // instead of getAmountBrutto()
$notification->email             // instead of getEmail()
$notification->product_name      // instead of getProductName()

// Automatic type conversion
$notification->amount_brutto     // float
$notification->buyer_id          // int
$notification->order_is_paid     // bool
$notification->order_date        // DateTimeImmutable
$notification->event             // Event enum
$notification->billing_status    // BillingStatus enum

// Tags are converted to array
$notification->tags              // ['webinar', 'premium', 'vip']
$notification->tags[0]           // 'webinar'
$notification->tags[1]           // 'premium'

Test vs. Live Orders

Digistore24 sends api_mode ('live' or 'test') so you can tell test orders apart from real ones. Use the isTestMode() helper:

if ($notification->isTestMode()) {
    // Skip fulfilment, granting access, sending emails, etc.
    echo 'OK';
    exit;
}

Unknown Fields

Digistore24 keeps adding and changing IPN fields. Any field without a declared property is kept as a raw value (no type conversion) and is accessible like a normal property — so new fields are available immediately and never lost:

$notification->some_new_field;          // raw string value, or null if absent

For static-analysis-safe access (PhpStan/Psalm can't know arbitrary field names), use getDynamicFields():

$extra = $notification->getDynamicFields();  // ['some_new_field' => '...', ...]
$value = $extra['some_new_field'] ?? null;

Unknown fields are also included in toArray() / toJson(), so serialization stays lossless.

Unknown Events

Unknown or future event values resolve to null instead of throwing, so new Digistore24 events never break your handler. Guard accordingly:

$event = $notification->event;   // null for unknown values

if ($event === null) {
    echo 'OK'; // acknowledge and ignore
    exit;
}

Migration from v1.x

Version 2.0 introduces breaking changes with PHP 8.4 Property Hooks:

Breaking Changes

  1. No getter methods - Use direct property access:

    // OLD (v1.x)
    $orderId = $ipn->getOrderId();
    $amount = $ipn->getAmountBrutto();
    
    // NEW (v2.x)
    $orderId = $notification->order_id;
    $amount = $notification->amount_brutto;
  2. snake_case property names (matching DS24 API exactly):

    // Property names match Digistore24 IPN field names
    $notification->order_id           // not $ipn->orderId
    $notification->amount_brutto      // not $ipn->amountBrutto
    $notification->email              // buyer's email address
    $notification->address_first_name // billing address first name
  3. Tags as array - No more tag1 through tag100:

    // OLD (v1.x)
    $tag1 = $ipn->getTag1();
    $tag2 = $ipn->getTag2();
    
    // NEW (v2.x)
    $tags = $notification->tags;     // ['tag1', 'tag2', 'tag3']
    $firstTag = $notification->tags[0];
    $secondTag = $notification->tags[1];
  4. Response DTO - Direct property assignment:

    // OLD (v1.x)
    $response->setHeadline('Welcome');
    
    // NEW (v2.x)
    $response->headline = 'Welcome';

See UPGRADE.md for detailed migration instructions.

Development

Development Commands

# Run tests
composer test

# Fix code style
composer cs:fix

# Static analysis
composer analyze

# Run all checks
composer test && composer cs:fix && composer analyze

Project Status

PHP: >= 8.4
Tests: PHPUnit (unit + integration) passing ✅
PHPStan: Level 9 ✅
Code Style: PSR-12 ✅

Documentation

Questions?

Error Handling

All signature and format errors throw GoSuccess\Digistore24\Ipn\Exception\FormatException.

License

MIT License - see LICENSE

gosuccess/digistore24-ipn 适用场景与选型建议

gosuccess/digistore24-ipn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 gosuccess/digistore24-ipn 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gosuccess/digistore24-ipn 我们能提供哪些服务?
定制开发 / 二次开发

基于 gosuccess/digistore24-ipn 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-30