php - 如何验证 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);
}
?>
但是我还需要获取订阅详细信息以保存它,我找不到任何关于订阅的好教程。
解决方案
使用当前的订阅 API,或注册订阅 webhook 事件。
这些东西都没有受支持的服务器 SDK;使用直接 HTTPS 集成,或者根据需要调整 Checkout SDK 的源代码以执行这些其他调用。
推荐阅读
- eclipse - Spring Tool Suite - 运行配置 - JUnit - 显示命令行 - 类路径信息在哪里?
- node.js - ReactJS 中的 API 调用并设置对状态的响应
- c++ - 将二进制数据 (.tec) 读入 C++ 程序变量矩阵
- mysql - 关于Mysql文件打孔,何时以及如何报“no space left”错误?
- python - 如何从文本中提取提及特定单词和/或短语的推文?
- javascript - TypeError:stripHtml 不是函数
- node.js - Sonos Simulator 无法编译节点包
- regex - 在 pyspark 中使用 rlike 加入数据帧时包括括号
- python - 好奇~在下面的代码中的作用
- excel - 如何在 VBA 中将变量添加到 Excel 公式中?