dta38159 2015-03-29 04:40
浏览 56
已采纳

条纹连接充电费返回错误(PHP)

I am developing a web application which is using stripe payment gateway. I need to charge $5 from every transaction to my stripe account and transfer the rest for the supplier's stripe account.

I did following steps.

1). to connect users I shared this url
https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_5slZHMozXs9B7rrgh6MDIFcdTvYqSdfz&scope=read_write

2). Set up redirect url to my application and did following codes to handle request

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>";
        }  

I received following response

sk_test_iLSNjRezyNiOiRpQk83UwQ6q
pk_test_0WXzhiA6xehlaZnmPZqP5VBi
acct_15iIu1I4jMsDTdhX

2). Then I used following code in the html file to grab credit card details.put publishable key as above returned publishable 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). Then I did following coding to recieve the token and charge from the card.Used above returned stripe_user_id for Stripe-Account parameter

// 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" => "testm@example.com",
            "application_fee" => 5 // amount in cents
          ),
          array("Stripe-Account" => "acct_15iIu1I4jMsDTdhX")
        );

But it returns me following error

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

Can you please advice me if I am doing wrong thing here

  • 写回答

4条回答 默认 最新

  • dpcnm2132 2015-04-02 07:14
    关注

    I resolved this error by putting access token directly.

    // 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" => "testm@example.com",
            "application_fee" => 5 // amount in cents
          ),
           ACCESS_TOKEN
        );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序