【问题标题】:How to Send Multiple Variables Through PayPal IPN如何通过 PayPal IPN 发送多个变量
【发布时间】:2017-05-31 04:21:14
【问题描述】:

这是客流:

访问网站 -> 使用他们的信息填写表格 -> 单击“立即购买”并使用 PayPal 结帐 -> 返回网站 -> 使用结帐时传递的信息通过 @ 在服务器上运行 PHP 脚本987654322@(假设结账成功)。好吧,无论如何,这就是计划。我遇到的问题是弄清楚如何实际传递变量(总共有 8 个......数组???。我目前在网站上有一个快速结帐按钮,它将用户重定向到 PayPal 以完成交易。我一直在 YouTube 或 S.O. 上寻找一个好的教程,但没有成功。有什么想法可以做到这一点吗?

谢谢

【问题讨论】:

  • 虽然这个过程是可以理解的,但你的问题是模糊的。你指的是什么“变量”?我的意思是,我们是在为您的网站/用户谈论自定义变量吗?在这种情况下,PayPal 提供了一个“自定义”选项。如果您能详细说明并提供您当前的代码,那将有所帮助。
  • @JeffreyKastner 是的,自定义变量。字符串和布尔值的混合体。

标签: php paypal paypal-ipn


【解决方案1】:

在您的 PayPal 表单中,只需为您的自定义字段使用类似以下内容..

例子:

<input type="hidden" name="custom" value="<?php echo $custom1.','.$custom2.','.$custom3; ?>">

或;

<input type="hidden" name="custom" value="custom1,custom2,custom3">

简而言之,PayPal 接受自定义名称,您可以使用逗号分隔变量。

PayPal 将在 IPN 中将自定义字段传回给您。


编辑

以下是您可以使用自定义执行的示例:

  $custom = $_POST['custom'];
  $pattern = ",";
  $pieces = explode($pattern,$custom, 3);
  // 3 is how many custom fields there are
  $custom1 = $pieces[0];
  $custom2 = $pieces[1];
  if (isset($pieces[2])) {
      //an example checking to see if there is a third custom variable
      $custom3 = $pieces[2];
  }

【讨论】:

【解决方案2】:

您可以使用 json 通过 PayPal 中的 custom 变量传递多个值..

创造你的价值观:

$custom = array();
$custom['value1'] = "foo";
$custom['value2'] = "bar";
$custom =  json_encode($custom);

然后你可以POST这个数据到某个地方:

<input type="hidden" name="custom" value="<?php echo htmlentities($custom) ?>"/>

然后从这样的地方获取数据:

$data = json_decode($_POST['custom']);
echo $data->value2;

输出应该是bar

【讨论】:

    猜你喜欢
    • 2012-06-30
    • 2019-05-02
    • 2016-06-10
    • 2013-08-17
    • 2013-02-25
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多