【问题标题】:How to access the response/redirect after stripe payment?条带付款后如何访问响应/重定向?
【发布时间】:2017-03-28 20:13:42
【问题描述】:

我试图在我的网站上销售视频,使用 wordpress 托管。我已经设置了一个 Stripe 帐户,并一直在我的网站上使用“WP Simple Pay Lite for Stripe”插件。

我面临的问题是,当我收到条带付款时,我手动向客户发送他们购买的视频。我想知道是否有人对我如何在付款后通过向客户发送产品来自动化流程有任何建议。

对于这个“WP Simple Pay Lite for Stripe”插件,有一个成功的支付 URL 重定向功能。我以前用的那个。我怎么注意到您可以从开发者工具中查看成功的付款重定向。

<input type="hidden" name="sc-redirect" value="https://wpsimplepay.com/demo-success-page/">

【问题讨论】:

  • 你想隐藏这个成功的url吗??

标签: wordpress stripe-payments


【解决方案1】:

在与您相似的this topic 中,作者建议使用sc_after_charge 挂钩。所以你的代码将是:

add_action( 'sc_after_charge', 'sc_after_charge_example' );
function sc_after_charge_example( $charge_response ) {
    if ( $charge_response->paid ) {
        $url = 'https://wpsimplepay.com/demo-success-page/';

        wp_redirect( $url );
        exit;
    }
}

我不确定响应类型是否为 JSON,但在 Stripe Docs 中它是 JSON。

【讨论】:

    【解决方案2】:

    在短代码中添加 success_redirect_url="https://wpsimplepay.com/demo-success-page" 作为属性

    [stripe name="My Store" description="My Product" amount="1999" success_redirect_url="https://wpsimplepay.com/demo-success-page"]
    

    来源:https://wpsimplepay.com/docs/shortcodes/stripe-checkout/

    【讨论】:

      【解决方案3】:

      正如 Stanimir Stoyanov 所说,您可以使用 sc_after_charge,但他的代码不起作用,因为 sc_after_charge 返回 Charge 对象,而不是 JSON。

      /**
       * Sends video url to customer when payment is successful
       * @param $response \Stripe\Charge
       */
      function send_video_if_payment_successful( $response ) {
          if ( $response->paid ) {
              // Maybe check amount and or description to ensure it's same product
              $file = 'http://url_to/file_to_attach.mp4'; // Video url
              $subject = 'Find your video here - My store'; // Email subject
              $msg = '
              Thanks for buying...
              yada yada yada...
              Please find attached video.'; // Email message
      
              $attachments = array( $file ); // Add attachment
      
              $headers = 'From: My store <myname@example.com>' . "\r\n"; // Set yourself in From header
      
              wp_mail( $response->receipt_email, $subject, $msg, $headers, $attachments ); // Send the mail
          }
      }
      add_action( 'sc_after_charge', 'send_video_if_payment_successful' );
      

      这里我们首先检查支付是否成功,如果是,我们将文件通过电子邮件发送给用户:)

      如果您打算销售多种产品...您可以设置适当的描述并发送不同的文件以供$response-&gt;description访问的不同描述

      【讨论】:

      • 这样我们也不会将网址暴露给我们网站上的视频... ;)
      【解决方案4】:

      请使用woocommerce下载产品

      https://docs.woocommerce.com/document/digitaldownloadable-product-handling/

      检查一下,希望对你有帮助

      【讨论】:

        猜你喜欢
        • 2022-07-21
        • 1970-01-01
        • 2020-02-05
        • 2013-05-26
        • 2018-12-06
        • 2012-12-31
        • 1970-01-01
        • 2014-03-27
        • 2019-02-22
        相关资源
        最近更新 更多