首页 > 解决方案 > 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");
    }
?>

标签: paypalfetch

解决方案


您的客户端将数据作为字符串发送,因此您可能需要先将字符串转换为 PHP 端的关联数组。

前任:

$retour = json_decode($_POST["retour_1"]);

https://www.php.net/manual/en/function.json-decode.php


推荐阅读