如何验证贝宝订阅

时间:2021-07-14 03:21:57

标签: php paypal paypal-subscriptions

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

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

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

1 个答案:

答案 0 :(得分:0)

使用the current Subscriptions API,或注册Subscriptions webhook events

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