【问题标题】:How to Integration Stripe Payment gateway in laravel?如何在 laravel 中集成 Stripe 支付网关?
【发布时间】:2016-01-04 04:37:06
【问题描述】:

我关注了this link

我按照它说的做了,但它抛出了一些错误:

routes.php 第 29 行中的 FatalErrorException: 找不到类“条纹” 第 29 行 Stripe::setApiKey('sk_test_bDgMM85Y8hWWaRRBrulWNeng');

【问题讨论】:

  • 你是否通过 composer 安装了条带?

标签: php laravel-4 laravel-5 stripe-payments


【解决方案1】:

需要检查的几件事...

  1. 您是否安装了条带依赖项? composer require stripe/stripe-php
  2. composer dump-auto了吗
  3. 您的教程链接从 Routes 文件运行条带。这是在全局命名空间中。您是从控制器还是从路由文件执行此代码?如果来自控制器,则需要在顶部添加一个 use 语句 use Stripe\Stripe;
  4. 最后,您使用的是哪个版本的https://github.com/stripe/stripe-php 包?根据自述文件,有旧版和新版。新版本多了一层嵌套,可以通过Stripe\StripeStripe\Charge访问:

旧版

Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
$charge = Stripe_Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd'));
echo $charge; 

新版本

\Stripe\Stripe::setApiKey('d8e8fca2dc0f896fd7cb4cb0031ba249');
$myCard = array('number' => '4242424242424242', 'exp_month' => 8, 'exp_year' => 2018);
$charge = \Stripe\Charge::create(array('card' => $myCard, 'amount' => 2000, 'currency' => 'usd'));
echo $charge;

【讨论】:

    【解决方案2】:

    这是我所做的事情及其工作。希望它的工作是你的案例:

      try {
            Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
    
            $customer = \Stripe\Customer::create([
              'name' => 'Jenny Rosen',
              'email' => 'jenyy@hotmail.co.us',
              'address' => [
                'line1' => '510 Townsend St',
                'postal_code' => '98140',
                'city' => 'San Francisco',
                'state' => 'CA',
                'country' => 'US',
              ],
            ]);
    
            \Stripe\Customer::createSource(
              $customer->id,
              ['source' => $request->stripeToken]
            );
    
            Stripe\Charge::create ([
                    "customer" => $customer->id,
                    "amount" => 100 * 100,
                    "currency" => "usd",
                    "description" => "Test payment from stripe.test." , 
            ]);
    
            Session::flash('success', 'Payment successful!');   
    
            } catch (\Exception $ex) {
                return $ex->getMessage().' error occured';
                Session::flash('error','Payment Failed.');
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 2015-12-30
      • 2020-10-26
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      相关资源
      最近更新 更多