首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sandbox Paypal Checkout (PHP,Laravel)

Sandbox Paypal Checkout (PHP,Laravel)
EN

Stack Overflow用户
提问于 2019-05-03 02:03:07
回答 1查看 368关注 0票数 0

我正在尝试实现Paypal的结账到我的Laravel Api (连接到一个离子应用程序),它卡住了,当我在应用程序中按下结帐按钮时,它会在登录屏幕中转到Paypal(到目前为止还好)。我发现它很奇怪,因为它不让我用我的沙箱帐户登录,甚至不允许我用我的真实帐户登录,错误是一样的:“你的一些信息不正确。请重试。”通过打开开发人员工具,这些是我得到的错误(见屏幕截图)。我真的找不到我在哪里犯了错。也许你能帮我。下面是截图和代码,使结账到贝宝。如果我应该在这里添加任何额外的信息,请让我知道!非常感谢!

错误1:

,调查其中一个控制台错误:

代码语言:javascript
复制
Route::middleware('auth:api')->post('/paypal', function (Request $request) {
    $user = $request->user();
    $data = $request->all();
    $list_products_id = $data;

    $products = [];
    $total = 0;

    $titles = '';

    foreach($list_products_id as $key => $value) {
        $product = Product::find($value);
        if($product){
            $products[$key] = $product;
            $total += $product->price;
            $titles .= $product->title." ";
        } 
    }

    if($total){

        $paypal = config('app.paypal', "sandbox");

       if($paypal == "sandbox"){
            $userProvider = 'In my app I have the sandbox business credentials here';
            $pwdProvider = 'In my app I have the sandbox business credentials here';
            $signProvider = 'In my app I have the sandbox business credentials here';
            $url = 'https://api-3t.sandbox.paypal.com/nvp';
            $url2 = 'https://www.sandbox.paypal.com/cgi-bin/webscr?%s';

       } else {
            $userProvider = '';
            $pwdProvider = '';
            $signProvider = '';   
            $url = 'https://api-3t.paypal.com/nvp';
            $url2 = 'https://www.paypal.com/cgi-bin/webscr?%s';
       }

       $data = [];
       $data['USER'] = $userProvider;
       $data['PWD'] = $pwdProvider;
       $data['SIGNATURE'] = $signProvider;
       $data['METHOD'] = 'SetExpressCheckout';
       $data['VERSION'] = '108';
       $data['LOCALECODE'] = 'en_US';

       $data['L_PAYMENTREQUEST_0_NAME0'] = "Products Orders";
       $data['L_PAYMENTREQUEST_0_DESC0'] = $titles;

       $data['PAYMENTREQUEST_0_AMT'] = number_format($total, 2).'';

       $data['PAYMENTREQUEST_0_CURRENCYCODE'] = 'EUR';
       $data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale';

       $data['L_PAYMENTREQUEST_0_QTY0'] = '1'; //number of the same product the user is ordering
       $data['L_PAYMENTREQUEST_0_AMT0'] = number_format($total, 2).'';

       $data['L_BILLINGAGREEMENTDESCRIPTION0'] = $titles;

       $data['CANCELURL'] = url('/');
       $data['RETURNURL'] = url('/');

      // curl

      $data = http_build_query($data);

      $curl = curl_init();
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($curl, CURLOPT_POST, true);
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

      $response =  curl_exec($curl);
      curl_close($curl);

      $nvp = array();

      if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
          foreach ($matches['name'] as $offset => $name) {
              $nvp[$name] = urldecode($matches['value'][$offset]);
          }
      }

      if(isset($nvp['ACK']) && $nvp['ACK'] == "Success" ){
        $query = array(
                'cmd'    => '_express-checkout',
                'token'  => $nvp['TOKEN']
            );

            $redirectURL = sprintf($url2, http_build_query($query));

            return ['date'=>$redirectURL];
      }else{
        return ['status'=>'error purchasing! - 1'];

      }

    }

    echo "total: " . $total;
    return ['status'=>'error purchasing! - 2'];
});
EN

回答 1

Stack Overflow用户

发布于 2019-05-03 23:35:20

所以我在我的沙盒帐户上重置了密码,它起作用了!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55957923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档