首页 > 解决方案 > 如何验证 PayPal 订阅

问题描述

我正在尝试验证订阅并将信息保存到数据库中,在我的最后一个问题中,我设置了一个允许双重结帐的结帐,用于订单和订阅。我在这里验证订单:

<?php
    namespace Sample;

    require __DIR__ . '/vendor/autoload.php';
    use Sample\PayPalClient;
    use PayPalCheckoutSdk\Orders\OrdersGetRequest;
    require 'paypal-client.php';
    $orderID = $_GET['orderID'];
    class GetOrder
    {
      public static function getOrder($orderId)
      {
          

          // 3. Call PayPal to get the transaction details
          $client = PayPalClient::client();
          $response = $client->execute(new OrdersGetRequest($orderId));
              
          $orderID = $response->result->id;
          $email = $response->result->payer->email_address;
          $name = $response->result->purchase_units[0]->shipping->name->full_name;
          $payerid = $response->result->payer->payer_id;
          $id = $_GET["UserID"];
          include "include/connect.php";
          //echo "#################### $orderID ###### $email ######### $name ######### $payerid";
          $stmt = $conn->prepare("UPDATE User SET Active='2', OrderID='$orderID', PPemail='$email', PPname='$name', PPID='$payerid' WHERE ID = $id");
          $stmt->execute();
          if(!$stmt){
              echo "error" . mysqli_error($con);
          }else{
              header("Location:success.php?id=$id");
          }
        ?>
        <pre>
        <?php
        //echo json_encode($response->result, JSON_PRETTY_PRINT);
        ?>
        </pre>
        <?php
      }
    }

    /**
     *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);
    }
    ?>

但是我还需要获取订阅详细信息以保存它,我找不到任何关于订阅的好教程。

标签: phppaypalpaypal-subscriptions

解决方案


使用当前的订阅 API,或注册订阅 webhook 事件

这些东西都没有受支持的服务器 SDK;使用直接 HTTPS 集成,或者根据需要调整 Checkout SDK 的源代码以执行这些其他调用。


推荐阅读