php - 沙盒 Paypal 结帐(PHP,Laravel)

标签 php laravel paypal

我正在尝试对我的 Laravel Api(连接到 Ionic 应用程序)实现 Paypal 结帐,当我在应用程序中按下结帐按钮并在登录时转到 Paypal(到目前为止一切正常)时,它会卡住屏幕。我发现它很奇怪,因为它不允许我使用我的沙盒帐户甚至我的真实帐户登录,错误是相同的:“您的某些信息不正确。请重试。”通过打开开发人员工具,这些是我得到的错误(见屏幕截图)。我真的找不到我在这里犯错的地方。也许你可以帮助我。下面是屏幕截图和使用 Paypal 结账的代码。让我知道我是否应该在此处添加任何额外信息!非常感谢!

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

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'];
});

最佳答案

所以我对我的沙箱帐户进行了密码重置,并且成功了!

关于php - 沙盒 Paypal 结帐(PHP,Laravel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55957923/

相关文章:

php - 外键值不显示

php - 浏览器不读取解码的 html_entity_decode 文本

php - 将博客 Paypal 按钮上的 "Donate"更改为 "Give Back"

php - Laravel 如何像使用数组一样使用 app 对象?

java - Paypal 交易已过期

php - 动态 PHP 表过滤和排序

php - 如何根据我的网站收到的电子邮件在数据库中创建记录?

javascript - 在这种情况下 CORS 策略适用于其他资源时出现问题

php - paypal的 'HKD'方法支持货币 "DoDirectPayment"?

ruby-on-rails - 使用 ActiveMerchant 和 PayPal 在实时网站上接受虚拟信用卡