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

内农·诺娜(Nenon Nona)

我有一个网站,该网站的会员资格共有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 Personal或Business帐户付款时,一切都正常进行,我收到了错误提示...

这是我得到的错误:

致命错误:未捕获的PayPalHttp \ HttpException:{“名称”:“ RESOURCE_NOT_FOUND”,“详细信息”:[{“位置”:“路径”,“问题”:“ INVALID_RESOURCE_ID”,“描述”:“指定的资源ID不存在。请检查资源ID,然后重试。“}],”消息“:”指定的资源不存在。“,” debug_id“:” 17a56f649394f“,”链接“:[{” href“:” https:/ / home / superrab / public_html / beta / vendor中的/developer.paypal.com/docs/api/orders/v2/#error-INVALID_RESOURCE_ID","re​​l":"information_link“,”方法“:” GET“}]}} /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(Object(PayPalCheckoutSdk \ Orders \ OrdersGetRequest)) #2 /home/superrab/public_html/beta/transaction-completed.php(65):Sample \ GetOrder :: getOrder('7KM15574UC31371 ...',true)#3 {main}放在/ home / superrab / public_html /中beta / vendor / paypal / paypalhttp / lib / PayPalHttp / HttpClient.php行215true)#3 {main}在第215行的/home/superrab/public_html/beta/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php中抛出true)#3 {main}在第215行的/home/superrab/public_html/beta/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php中抛出

任何帮助表示赞赏

普雷斯顿PHX

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


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

(但再次重申,理想的情况是整个段落都没有意义,您应该更多地关注第1段)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从Paypal API获取订单详细信息

尝试创建客户端服务库时,wsimport失败

创建Web服务客户端时出错

创建客户端时出现ElasticSearch AbstractMethodError

通过JavaScript或dll或jar文件获取客户端信息?

如何获取WooCommerce订单详细信息

如何在Java中使用Jenkins客户端获取Jenkins工作详细信息列表

在WooCommerce 3中获取订单运送物品的详细信息

OAuth客户端凭据流程-调用客户端详细信息作为声明

如何获取客户端的浏览器信息?

创建带有订单详细信息的Woocommerce简码

保持贝宝付款时如何通过邮件获取订单详细信息?

Spring Security Oauth2资源所有者密码流:当我发送REST请求时,我的用户详细信息服务始终获取客户端ID而不是用户名

如何从订单ID Magento获取所有订单详细信息,包括付款客户和运输详细信息

通过订单ID获取订单详细信息

获取symfony2中的客户端ip和客户端位置

woocommerce结帐后获取订单详细信息

SQL返回每个客户的最后订单详细信息

使用客户端加密获取用户信息的好处

Maven - 打包jar时如何创建ejb客户端

使用javascript获取客户端信息的Django URL

Spring OAUTH2 在 oauth 客户端上获取用户详细信息

从数据库中获取woocommerce订单详细信息

从zookeeper客户端获取主机信息

如何使用 SoftLayer Python 客户端获取计费项目详细信息?

使用 kubernetes 客户端 API 创建 pod 时出错

Paypal rest api 获取使用 nvp api 放置的订单的订单详细信息

在 Spring Boot 中添加与客户的多条关系中的帐户详细信息时出错

显示 Woocommerce 客户上次下订单的详细信息时出现问题