【问题标题】:Stripe Class 'Stripe\Charge条纹类'条纹\电荷
【发布时间】:2016-05-19 10:55:29
【问题描述】:

我想实现一个 Stripe 支付表单,但我收到一个致命错误 Class 'Stripe\Charge.课程在那里(见我的文件夹树),我试过了:

$charge =  \Stripe\Charge::create(array(

$charge =  \Charge::create(array(

但两者都没有工作。 我的php代码:

require_once('Stripe/lib/Stripe.php');
\Stripe\Stripe::setApiKey("my_key"); //Replace with your Secret Key

$charge =  \Stripe\Charge::create(array(
    "amount" => 1500,
    "currency" => "usd",
    "card" => $_POST['stripeToken'],
    "description" => "Charge for Facebook Login code."
));

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

    您使用的是旧版 (1.x) 的 Stripe PHP 库。在那个版本中,所有的类都被命名为Stripe_Class

    2.0.0 版本中,语法被更改为使用命名空间,现在所有类都命名为\Stripe\Class

    如果可能,我建议您升级到最新版本 (3.13.0)。你可以在这里找到它:https://github.com/stripe/stripe-php/releases。 Stripe 文档和 API 参考中的所有示例都使用了较新的语法。

    【讨论】:

      【解决方案2】:

      你可以使用

      use \Stripe\Stripe;
      \Stripe\Stripe::setApiKey("my_key");
       public function chargeCard($token)
       {
          try
          {
              $charge=\Stripe\Charge::create(array(
                  "amount" => 200,//Amount in cent.(100 cent equal to $1.00).it is smallest currency unit
                  "currency" => "usd",//united state dollar .but we can use different countries currency code
                  "source" => $token, // obtained createtoken function
                  "description" => "Charge for testing"//desc of payment purpose,Automatic receipt emails will include the description of the charge(s)
                )
                );
            }
            catch(\Stripe\Card $e){
              echo $e->getMessage();
            }
        }
      

      【讨论】:

        【解决方案3】:

        这对我有用:

        $customer = Stripe_Customer::create(array(
              'email' => 'customer-email',
              'source'  => 'stripe_token'
          ));
        
          $charge = Stripe_Charge::create(array(
            "amount" => $order_amount, // amount in cents
            "customer"=>$customer->id,
            "currency" => "usd",
            "description" => "payinguser@example.com"
          ));
        

        【讨论】:

          猜你喜欢
          • 2019-04-03
          • 1970-01-01
          • 2016-11-15
          • 1970-01-01
          • 2023-03-05
          • 2011-05-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多