php - Stripe 连接收费返回错误 (PHP)

标签 php stripe-connect

我正在开发一个使用 Stripe 支付网关的 Web 应用程序。我需要从每笔交易中向我的 Stripe 账户收取 5 美元,并将其余部分转入供应商的 Stripe 账户。

我执行了以下步骤。

1).连接我共享此网址的用户
https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_5slZHMozXs9B7rrgh6MDIFcdTvYqSdfz&scope=read_write

2).设置指向我的应用程序的重定向 url 并执行以下代码来处理请求

if (isset($_GET['code'])) { // Redirect w/ code
          $code = $_GET['code'];

          $token_request_body = array(
            'grant_type' => 'authorization_code',
            'client_id' => 'ca_5slZHMozXs9B7rrgh6MDIFcdTvYqSdfz',
            'code' => $code,
            'client_secret' => 'sk_test_WcXfM3Tsb0IlkSKmbZTYnq5d'
          );

          $req = curl_init("https://connect.stripe.com/oauth/token");
          curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($req, CURLOPT_POST, true );
          curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));
          curl_setopt($req, CURLOPT_SSL_VERIFYPEER, FALSE);
          //curl_setopt($req, CURLOPT_CAINFO, "assets/cacert.pem");

          // TODO: Additional error handling
          $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
          $resp = json_decode(curl_exec($req), true);
          curl_close($req);

          echo $resp['access_token'];
                echo "<br/>";
          echo  $resp['stripe_publishable_key'];
                echo "<br/>";
          echo $resp['stripe_user_id'];

        } else if (isset($_GET['error'])) { // Error
          echo $_GET['error_description'];
        } else { // Show OAuth link
          $authorize_request_body = array(
            'response_type' => 'code',
            'scope' => 'read_write',
            'client_id' => 'ca_5slZHMozXs9B7rrgh6MDIFcdTvYqSdfz'
          );

          $url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
          echo "<a href='$url'>Connect with Stripe</a>";
        }  

我收到以下回复

sk_test_iLSNjRezyNiOiRpQk83UwQ6q
pk_test_0WXzhiA6xehlaZnmPZqP5VBi
acct_15iIu1I4jMsDTdhX

2).然后我在 html 文件中使用以下代码来获取信用卡详细信息。将可发布 key 按上面的方式返回可发布 key 。

<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
              data-key="pk_test_0WXzhiA6xehlaZnmPZqP5VBi"
              data-email= "<?php echo $usremail; ?>"
              data-amount="<?php echo $valCoursefee*100; ?>" data-description="Pay & Enroll">
            </script>  

3).然后我执行了以下编码以接收 token 并从卡中收费。上面使用的 Stripe-Account 参数返回了 stripe_user_id

// Get the credit card details submitted by the form
        $token = $_POST['stripeToken'];
        // Stripe_Stripe::setApiKey("sk_test_WcXfM3Tsb0IlkSKmbZTYnq5d");
        // Create the charge on Stripe's servers - this will charge the user's card
        $charge = Stripe_Charge::create(
          array(
            "amount" => 1000, // amount in cents
            "currency" => "usd",
            "source" => $token,
            "description" => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5c1d0c6c1d8f5d0cdd4d8c5d9d09bd6dad8" rel="noreferrer noopener nofollow">[email protected]</a>",
            "application_fee" => 5 // amount in cents
          ),
          array("Stripe-Account" => "acct_15iIu1I4jMsDTdhX")
        );

但它返回我以下错误

Fatal error: Uncaught exception 'Stripe_InvalidRequestError' with message 'There is no token with ID tok_15lW5jI4jMsDTdhXhG9vfnjk.' in C:\wamp2\www\NEW\application\libraries\payment_gateway\lib\Stripe\ApiRequestor.php on line 147

如果我在这里做错了事,你能给我建议吗

最佳答案

直接在连接的帐户上处理费用需要身份验证,最好通过提供平台帐户的 key 来实现。

因此,如果您想向卡收取 5 美元的申请费,那么您必须通过 Strip API 验证您的网络应用程序。返回 token ,然后您必须将该 token 传递给签账卡。也许这个链接会对您有更多帮助。 https://stripe.com/docs/connect/payments-fees

关于php - Stripe 连接收费返回错误 (PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29325664/

相关文章:

php - Laravel 5.1 指定当前页面进行分页

laravel - 如何将收费金额从一个连接的 Stripe 账户转移到另一个连接的 Stripe 账户

php - 在列 MySQL 中搜索数字

javascript - 如何删除融合 Angular 仪表图表中的背景颜色

php - 多个网站可以使用相同的主页和相同的数据库,但不需要更改url?

php - 使用排名列显示孙子数量

stripe-payments - Stripe 费用计算

stripe-payments - 可以查询Stripe管理帐户的余额吗?

ruby-on-rails - strip 连接身份验证失败 - invalid_client : No such API key: Bearer

oauth - 如何知道用户是否与我的 Stripe Connect 应用程序断开连接?