获取在客户端创建的PayPal v2订单的详细信息时出错

如何解决获取在客户端创建的PayPal v2订单的详细信息时出错

我有一个拥有3个页面的会员资格的网站,一个用于展示会员资格(带有我的PayPal按钮),一个带有注册表格(用于将会员添加到我的数据库中),最后一个在完成所有操作后说(例如“您现在可以登录”)。

我刚刚在YouTube上观看了一个视频,添加了“贝宝”按钮,供我的会员在开始填写注册表之前先付款。

我正在使用PayPal SDK。这是我的代码:

第一页(account-step1.php)

<!DOCTYPE html>
<html lang="en">
 <?php
  // Include HEADER  
  include ("includes/head.php");
  ?>
    <!-- SPECIFIC CSS -->
    <link href="css/booking-sign_up.css" rel="stylesheet">

    <style type="text/css">
    .circle {
      width: 70px;
      height: 70px;
      line-height: 70px;
      border-radius: 50%;
      font-size: 24px;
      color: red;
      text-align: center;
      background: gold;
      font-weight: bold;
    }
    /* Media query for mobile viewport */
    @media screen and (max-width: 400px) {
        #paypal-button-container {
            width: 100%;
        }
    }
        
    /* Media query for desktop viewport */
    @media screen and (min-width: 400px) {
        #paypal-button-container {
            width: 250px;
        }
    }
    </style>
    <script src="https://www.paypal.com/sdk/js?client-id=sb&currency=USD"></script>
</head>

<body>
                
    <header class="header_in clearfix">
        <div class="container">
        <div id="logo">
            <a href="index.php">
                <img src="img/logo_sticky.svg" width="250" height="40" alt="" class="logo_sticky">
            </a>
        </div>
        <?php include ("includes/topmenu.php"); ?>
        <a href="#0" class="open_close">
            <i class="icon_menu"></i><span>Menu</span>
        </a>
        <?php include ("includes/menu.php"); ?>
    </div>
    </header>
    <!-- /header -->
    
    <main class="bg_gray pattern">
        
        <div class="container margin_60_40">        
            <div class="main_title center">
                <span><em></em></span>
                <h2><?php echo _e("Our Subscription Plan"); ?></h2>
                <p>VIP 2021 - 2022</p>
            </div>

            <div class="row justify-content-center">
                <div class="col-lg-12">
                    <div class="sign_up">
                        <div class="head">
                            <div class="title">
                            <h3>1 YEAR SUBSCRIPTION</h3>
                        </div>
                        </div>
                        <!-- /head -->
                        <div class="main text-center" style="font-size:16px;">
                                <p><i class="icon_star"></i> <?php echo _e("VIP Membership Card"); ?> <i class="icon_star"></i></p>
                                <p><i class="icon_star"></i> <?php echo _e("Take advantage of original discounts at all our partners everywhere near you"); ?> <i class="icon_star"></i></p>
                                <p><i class="icon_star"></i> <?php echo _e("Your subscription pays for itself in just 1 or 2 uses of discounts"); ?> <i class="icon_star"></i></p>
                                <p><i class="icon_star"></i> <?php echo _e("Each year your easy-to-use privileges are recharged in the application to make you enjoy again"); ?> <i class="icon_star"></i></p>
                                <p><i class="icon_star"></i> <?php echo _e("Contribute to better nutritional health for our children with $ 1 donated to the Club des petits déjeuners by subscription"); ?> <i class="icon_star"></i></p>
                                <p class="text-center">
                                <center>
                                <div class="circle">20$</div>
                                </center>
                                </p>
                                <hr>
                                <center><div id="paypal-button-container"></div></center>
                        </div>
                    </div>
                    <!-- /box_booking -->
                </div>
                <!-- /col -->

            </div>
            <!-- /row -->
        </div>
        <!-- /container -->
        
    </main>
    <!-- /main -->

    <?php include ("includes/footer.php"); ?>

    <div id="toTop"></div><!-- Back to top button -->
    
    <div class="layer"></div><!-- Opacity Mask Menu Mobile -->
    
    <?php include("includes/signin-modal.php"); ?>
    
    <!-- COMMON SCRIPTS -->
    <script src="js/common_scripts.min.js"></script>
    <script src="js/common_func.js"></script>
    <script src="assets/validate.js"></script>
    <!-- Include the PayPal JavaScript SDK -->
    <script src="https://www.paypal.com/sdk/js?client-id=AeQdfTQ2soaOdV7vgLYyTsnsSC3ptpSJJWFsDGwkTXmQocaCBfYPYWV7mHO-iPGX3_ZiLdCqxmqY9h6H&currency=USD"></script>

    <script>
  paypal.Buttons({
    style: {
    color:   'gold',shape:   'pill',label:   'pay'
  },createOrder: function(data,actions) {
      // This function sets up the details of the transaction,including the amount and line item details.
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '20.00'
          }
        }]
      });
    },onApprove: function(data,actions) {
      // This function captures the funds from the transaction.
      return actions.order.capture().then(function() {
        window.location = "transaction-completed.php?&orderID="+data.orderID;

      });
    }
  }).render('#paypal-button-container');
  //This function displays Smart Payment Buttons on your web page.
</script>

</body>
</html>

transaction-completed.php

<?php

namespace Sample;

require __DIR__ . '/vendor/autoload.php';
//1. Import the PayPal SDK client that was created in `Set up Server-Side SDK`.
use Sample\PayPalClient;
use PayPalCheckoutSdk\Orders\OrdersGetRequest;
require 'paypal-client.php';
$orderID = $_GET['orderID'];

class GetOrder
{

  // 2. Set up your server to receive a call from the client
  /**
   *You can use this function to retrieve an order by passing order ID as an argument.
   */
  public static function getOrder($orderId)
  {

    // 3. Call PayPal to get the transaction details
    $client = PayPalClient::client();
    $response = $client->execute(new OrdersGetRequest($orderId));

    // Transaction Details
    $orderID = $response->result->id;
    $email = $response->result->payer->email_address;
    $pre_name = $response->result->payer->given_name;
    $last_name = $response->result->payer->surname;
    $full_name = $pre_name.$last_name;

    // INSERT DATA INTO DATABASE
    include('db_paypal.php'); //CONNECT DATABASE
    // PREPARE AND BIND
    $stmt = $con->prepare("INSERT INTO payments (fullname,orderID) VALUES (?,?) ");
    $stmt->bind_param("ss",$name,$orderID);
    $stmt->execute();

    //TRY TO EXECUTE QUERY
    if (!$stmt) {
      echo 'Error SQL' .mysqli_error($con);
    }
    else{
      session_start(); //START SESSION
      $_SESSION['orderID'] = $orderID; //STORE orderID INTO SESSION VAR
      header("Location:account-step3.php"); //REDIRECT TO NEXT STEP
    }

    $stmt->close(); //CLOSE STATEMENT
    $con->close(); //CLOSE CONNECTION SQL

  }
}

/**
 *This driver function invokes the getOrder function to retrieve
 *sample order details.
 *
 *To get the correct order ID,this sample uses createOrder to create an order
 *and then uses the newly-created order ID with GetOrder.
 */
if (!count(debug_backtrace()))
{
  GetOrder::getOrder($orderID,true);
}
?>

paypal-client.php

<?php

namespace Sample;

use PayPalCheckoutSdk\Core\PayPalHttpClient;
// GO LIVE \LiveEnvironment
use PayPalCheckoutSdk\Core\SandboxEnvironment;

ini_set('error_reporting',E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors','1');
ini_set('display_startup_errors','1');

class PayPalClient
{
    /**
     * Returns PayPal HTTP client instance with environment that has access
     * credentials context. Use this instance to invoke PayPal APIs,provided the
     * credentials have access.
     */
    public static function client()
    {
        return new PayPalHttpClient(self::environment());
    }

    /**
     * Set up and return PayPal PHP SDK environment with PayPal access credentials.
     * This sample uses SandboxEnvironment. In production,use \LiveEnvironment.
     */
    public static function environment()
    {
        $clientId = getenv("CLIENT_ID") ?: "AeQdfTQ2soaOdV7vgLYyTsnsSC3ptpSJJWFsDGwkTXmQocaCBfYPYWV7mHO-iPGX3_ZiLdCqxmqY9h6H";
        $clientSecret = getenv("CLIENT_SECRET") ?: "ECMtmwnFIMs09g_UFAGBAabjkOgykKORvIC9Y9xW2Mn2aZRx0bH7DpHyXDFg3klRkzV9nUI8T6HRI1e8";
        return new SandboxEnvironment($clientId,$clientSecret);
    }
}

db_paypal.php

<?php 

$server = "localhost";
$user = "root";
$password = "password";
$db = "superrabais";

$con = new mysqli($server,$user,$password,$db);
if ($con->connect_error) {
    die("Connection Failed:" . $con->connect_error);
}

 ?>

最后一个注册表格如下: account-step2.php

<!DOCTYPE html>
<html lang="en">
 <?php
  // Include HEADER  
  include ("includes/head.php");
  ?>
<?php if (empty($_SESSION['orderID'])) {
echo "<script type='text/javascript'>location.replace('../index.php');</script>";
}else{}
?>
    <!-- SPECIFIC CSS -->
    <link href="css/booking-sign_up.css" rel="stylesheet">
</head>

<body>
                
    <header class="header_in clearfix">
        <div class="container">
        <div id="logo">
            <a href="index.php">
                <img src="img/logo_sticky.svg" width="250" height="40" alt="" class="logo_sticky">
            </a>
        </div>
        <?php include ("includes/topmenu.php"); ?>
        <a href="#0" class="open_close">
            <i class="icon_menu"></i><span>Menu</span>
        </a>
        <?php include ("includes/menu.php"); ?>
    </div>
    </header>
    <!-- /header -->
    
    <main class="bg_gray pattern">
        
        <div class="container margin_60_40">
            <div class="row justify-content-center">
                <div class="col-lg-4">
                    <div class="sign_up">
                        <div class="head">
                            <div class="title">
                            <h3><?php echo _e("Registration") ?></h3>
                        </div>
                        </div>
                        <!-- /head -->
                        <div class="main">
                        <form action="includes/register.php" method="post" id="payment-form">
                        <h6><?php echo _e("Personal details") ?></h6>
                            <div class="form-group">
                                <input class="form-control" placeholder="<?php echo _e("First and Last Name");?>" id="full_name" name="full_name" required>
                                <i class="icon_pencil"></i>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="<?php echo _e("Apartment (Optional)");?>" id="apartment" name="apartment">
                                <i class="icon_house_alt"></i>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="<?php echo _e("Adress");?>" id="adress" name="adress" required>
                                <i class="icon_house_alt"></i>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="<?php echo _e("City");?>" id="city" name="city" required>
                                <i class="icon_house_alt"></i>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="<?php echo _e("Postal Code");?>" id="postalcode" name="postalcode" maxlength="6" minlength="6" required>
                                <i class="icon_house_alt"></i>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="<?php echo _e("Phone (888-888-8888)");?>" id="phone" name="phone" type="tel" pattern="[0-9]{3}[0-9]{3}[0-9]{4}" maxlength="10" minlength="10" required>
                                <i class="icon_phone"></i>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="<?php echo _e("Email Address");?>" id="email" name="email" required>
                                <i class="icon_mail"></i>
                            </div>
                            <div class="form-group add_bottom_15">
                                <input class="form-control" placeholder="<?php echo _e("Password (8 character minimum)");?>" id="password" name="password" minlength="8" required>
                                <i class="icon_lock"></i>
                            </div>
                            <input type="hidden" class="form-control" name="refer" id="refer" value="<?php if(!empty($_SESSION['pid'])){echo $_SESSION['pid'];}else{}?>">
                            <input type="submit" class="btn_1 full-width mb_5" name="submit" value="<?php echo _e("Sign up Now");?>">
                        </form>
                        </div>
                    </div>
                    <!-- /box_booking -->
                </div>
                <!-- /col -->

            </div>
            <!-- /row -->
        </div>
        <!-- /container -->
        
    </main>
    <!-- /main -->

    <?php include ("includes/footer.php"); ?>

    <div id="toTop"></div><!-- Back to top button -->
    
    <div class="layer"></div><!-- Opacity Mask Menu Mobile -->
    
    <?php include("includes/signin-modal.php"); ?>
    
    <!-- COMMON SCRIPTS -->
    <script src="js/common_scripts.min.js"></script>
    <script src="js/common_func.js"></script>
    <script src="assets/validate.js"></script>

</body>
</html>

当我尝试使用Sandbox个人或企业帐户付款时,一切都工作正常,我得到了一个错误...

这是我得到的错误:

致命错误:未捕获的PayPalHttp \ HttpException: {“名称”:“ RESOURCE_NOT_FOUND”,“详细信息”:[{“位置”:“路径”,“问题”:“ INVALID_RESOURCE_ID”,“说明”:“已指定 资源ID不存在。请检查资源ID并尝试 再次。“}],”消息“:”指定的资源不 存在。“,” debug_id“:” 17a56f649394f“,”链接“:[{” href“:” https://developer.paypal.com/docs/api/orders/v2/#error-INVALID_RESOURCE_ID“,” rel“ :“ information_link”,“方法”:“ GET”}]} /home/superrab/public_html/beta/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php:215 堆栈跟踪:#0 /home/superrab/public_html/beta/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php(100): PayPalHttp \ HttpClient-> parseResponse(Object(PayPalHttp \ Curl))#1 /home/superrab/public_html/beta/transaction-completed.php(24): PayPalHttp \ HttpClient-> execute(对象(PayPalCheckoutSdk \ Orders \ OrdersGetRequest)) #2 /home/superrab/public_html/beta/transaction-completed.php(65):Sample \ GetOrder :: getOrder('7KM15574UC31371 ...',true)#3 {main} throw 在 /home/superrab/public_html/beta/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php 在第215行

感谢您的帮助

解决方法

我看到这是用于支付创建和捕获的仅客户端集成,然后在该客户端捕获之后,您使用server = side AI调用来获取订单的详细信息。那是一个非常奇怪的混合体,有人想知道为什么不集成“设置事务”和“捕获事务on the server side(并与approval JS for a server side integration配对)以获得该健壮性的所有好处,然后您不需要额外的API调用即可获取订单的详细信息,因为在服务器端捕获后就已经拥有了该订单,并能够自动进行存储。基本上,似乎您真的应该切换到该位置,而不要尝试这种不必要的混合动力。


但是,如果您坚持要做没人建议的奇怪而不可取的事情,那么服务器端代码不会创建订单ID(例如7KM15574UC313712P),因此无法通过这种方式进行访问。您可以尝试的是从purchase_units[0].captures.id中查找JS中成功的Capture ID(而不是Order ID),并将该实际的PayPal交易ID传递给服务器代码。然后使用它获取v2 / payment捕获对象,该对象将使用不同的API / SDK调用-在您的情况下,此对象为:https://github.com/paypal/Checkout-PHP-SDK/blob/develop/lib/PayPalCheckoutSdk/Payments/CapturesGetRequest.php

(但同样,理想的是整个段落都没有意义,您应该更加注意第1段)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-