paypal - Paypal - 在 php 中获取 onApprove 获取变量
问题描述
我想在付款获得批准后发送一个带有 fetch 的 post 变量“success”。这个变量将被一个 php 文件捕获,如果没问题,它将发送一封邮件。但是我的代码不起作用。你有解决方案吗 ?
非常感谢你的帮助
朱利安
贝宝脚本:
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
return fetch("my-site-example.com/return.php", {
method: "POST",
headers: {
'Accept': 'application/json',
'content-type': 'application/json'
},
body: JSON.stringify({
retour_1: "success"})
}).then(response => {
return response.json();
}).then(jsonResponse => {
console.log(jsonResponse);
}).catch (error => {
console.log(error)
})
和 return.php :
<?php
$retour = $_POST["retour_1"];
if ($retour == "success"){
require("../facture/mail_notification1.php");
}
?>
解决方案
您的客户端将数据作为字符串发送,因此您可能需要先将字符串转换为 PHP 端的关联数组。
前任:
$retour = json_decode($_POST["retour_1"]);
推荐阅读
- javascript - 在 URL 中捕获网页的状态
- google-cloud-sql - Cloud Run 和 Cloud SQL 之间的连接(内部 IP)
- python - 如何检查矩形轮廓内部是否包含数字?(OpenCV - Python)
- neo4j - Neo4J 中的 WHERE 问题,反序列化错误
- python - 如何在消息框中添加枚举或简单计数器
- python - 是否有一个 python 包可以从我的数据中找到最有影响力的组(分类特征)?
- java - 为什么我们需要在创建 java web 时为放入服务器的类实现 Serializable
- swift - 如何快速将相同的随机数分配给 2 个变量?
- python - 如何将字典列表附加到python中的相同列表?
- swift - Swift 字符串标记器/解析器