adyen/php-webhook-module

Adyen支付集成使用的Webhook模块

1.0.0 2024-04-08 11:45 UTC

README

用于处理通知Webhook的Adyen库。

安装

您可以使用Composer。如果您还没有安装Composer,请按照安装说明进行操作。

composer require adyen/php-webhook-module

在您的PHP脚本中,请确保包含自动加载器

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

或者,您可以从GitHub下载发布版本

使用

验证传入的Webhook请求

// Setup NotificationReceiver with dependency injection or create an instance as follows
$notificationReceiver = new \Adyen\Webhook\Receiver\NotificationReceiver(new \Adyen\Webhook\Receiver\HmacSignature);

// Authorize notification
if (!$notificationReceiver->isAuthenticated(
    $request['notificationItems'][0]['NotificationRequestItem'],
    YOUR_MERCHANT_ACCOUNT,
    YOUR_NOTIFICATION_USERNAME,
    YOUR_NOTIFICATION_PASSWORD
)) {
    throw new AuthenticationException();
}

// Process each notification item
foreach ($request['notificationItems'] as $notificationItem) {
    // validate the notification
    if ($notificationReceiver->validateHmac($notificationItem, YOUR_HMAC_KEY)) {
       // save notification to your database
       $this->databaseService->saveNotification($notificationItem); 
    }
}

return new JsonResponse('[accepted]');

处理通知以获取新的支付状态

$notificationItem = \Adyen\Webhook\Notification::createItem([
    'eventCode' => $notification['eventCode'],
    'success' => $notification['success']
]);

$processor = \Adyen\Webhook\Processor\ProcessorFactory::create(
    $notificationItem,
    $currentPaymentState,
    $this->logger
);

$newState = $processor->process();

注意:将$currentPaymentState设置为\Adyen\Webhook\PaymentStates中的某个值

文档

访问我们的文档页面,了解更多关于处理通知的信息。

贡献

我们鼓励您为此存储库做出贡献,以便每个人都能从新功能、错误修复和其他改进中受益。请查看我们的贡献指南,了解如何提交拉取请求。

支持

如果您有功能请求,或发现了错误或技术问题,请在此创建问题。对于其他问题,请联系我们的支持团队

许可证

此存储库可在MIT许可证下使用。