【问题标题】:Receiving Stripe Webhooks on a wordpress website在 wordpress 网站上接收 Stripe Webhooks
【发布时间】:2017-02-22 05:29:32
【问题描述】:

我有一个托管在 GoDaddy 上的 wordpress 网站。

我是一名高级条带用户,并且已经将条带与许多 Ruby on Rails 应用程序集成,以及与 Rails 的条带 Webhook 集成。我也精通网络钩子的工作原理。 但最近我成为了一个托管在 GoDaddy 上的 wordpress 网站的所有者,在该网站上我应该收到条带支付失败的 webhook,然后根据该 webhook 事件触发一封电子邮件。 我无法从在线资源中与 wordpress 和 stripe 建立很多联系,并且需要有关如何在 wordpress 网站中接收 stripe-webhooks 的帮助,即在哪里放置代码以实现这一点等。

【问题讨论】:

    标签: wordpress webhooks stripe-connect


    【解决方案1】:

    我最近遇到了同样的问题,pippins stripe 集成插件似乎可以解决这个问题,但它有很多我不需要的额外代码,所以我删除了它并为 webhook 集成制作了一个简洁的版本:WPStripeWebhook。自述文件是不言自明的。基本上为您的事件更改includes/stripe_listener.php。根据 stackoverflow 指南,还附上自述文件:

    用法:

    1. 在 wp-content/plugins 中复制完整的文件夹 WPStripeWebhook。走 到网站管理页面。

    2. 激活 WP Stripe webhook 插件 插件部分。

    3. 在此设置后将开始显示条纹 webhook 设置部分。点击它。在页面中填充条纹 如果要测试插件,请检查测试模式选项。
    4. 在 WPStripeWebhook/includes/stripe_listener.php 中,为您的 事件类型和电子邮件或任何你想要做的回应
      一个事件。它目前会发送一封电子邮件。

    重要说明和建议 对于实时模式,像这样添加条带 webhook 端点(条带帐户 -> 设置 -> 帐户设置 -> webhook)

    https://yourdomain.com?webhook-listener=stripe

    要在您的机器上进行本地测试,您可以使用 Ultrahook。这很棒!设置您的密钥和用户名并使用以下命令在您的机器上启动 Ultrahook:

    ultrahook -k your_ultrahook_key stripe 8888

    在您的条带帐户中添加一个 webhook 端点 url,类似于:

    http://stripe.your_ultrahook_username.ultrahook.com/your_wp_website_folder_name/stripe-listener.php?webhook-listener=stripe

    它应该开始为你工作了。此外,您可能会在 Ultrahook 控制台中看到 404。忽略它。我建议也设置调试。这真的很有帮助。对于调试,将这些添加到您的 wp_config.php

    define('WP_DEBUG', true); 
    define( 'WP_DEBUG_LOG', true ); 
    define('WP_DEBUG_DISPLAY', false ); 
    @ini_set( 'display_errors', 0 ); 
    define('SCRIPT_DEBUG', true );
    

    之后,您应该会在 wp-content 文件夹中看到一个 debug.log 文件,它会显示错误和警告以及您使用 error_log() 打印的任何内容

    【讨论】:

    • 有计划为最新版本的 Stripe 更新这个吗?这看起来非常有用,但它不起作用,并且从那时起,stripe-php 发生了很大的变化。
    【解决方案2】:

    这是我的两分钱。为了后代,因为接受的答案对我没有用。

    我们可以使用WordPress REST api

    通过Extending the REST APIAdding Custom Endpoints 通过register_rest_route function

    <?php
    
    add_action( 'rest_api_init', 'wpso40015091' );
    
    function wpso40015091() {
    
        $routes = array(
            array(
                'namespace' => 'wpso40015091/listener/v1',
                'route' => 'endpoint',
    
                //www.example.com/index.php/wp-json/wpso40015091/listener/v1/endpoint
                //This is the endpoint to add in your Stripe dashboard webhook section.
                //From time to time, depending on your host, the "index.php" might be omitted.
                //You can use "get_rest_url()" to Retrieves the URL to a REST endpoint on a site.
                //https://developer.wordpress.org/reference/functions/get_rest_url/
               
    
                'args' => array(
                    'methods' => 'POST',
                    'callback' => function () {
    
                        //...
    
                    },
                    'permission_callback' => '__return_true',
                ),
                'override' => true,
            ),
        );
    
        foreach ( $routes as $route ) {
    
            register_rest_route( $route['namespace'], $route['route'], $route['args'], $route['override'] );
    
        };
    
    };
    

    回调函数是事件监听器。 Stripe 有一个内置的生成器,请参考https://stripe.com/docs/webhooks/quickstart

    【讨论】:

      猜你喜欢
      • 2013-07-31
      • 1970-01-01
      • 2020-12-14
      • 2013-01-10
      • 2017-07-13
      • 2021-03-26
      • 2014-07-08
      • 2020-03-24
      • 2018-05-02
      相关资源
      最近更新 更多