0

我们有一个 PHP 系统,我们正在使用 Micah Carrick 的“PHP Paypal IPN 集成类”(http://www.micahcarrick.com/php-paypal-ipn-integration-class.html)。

在他的示例代码中,他建议我们在将 POST 变量传递到 PayPal 之前对其进行验证

switch ($_GET['action']) {

   case 'process':      // Process and order...

... 
      // This is where you would have your form validation  and all that jazz.
      // You would take your POST vars and load them into the class like below,
      // only using the POST values instead of constant string expressions.
      // For example, after ensureing all the POST variables from your custom
      // order form are valid, you might have:
      //
      // $p->add_field('first_name', $_POST['first_name']);
      // $p->add_field('last_name', $_POST['last_name']);

... 
    $custom=$_SESSION['sess_user_id']."~".$_POST['promo_code'];
    $p->add_field('user_id', $_SESSION['sess_user_id']);
    $p->add_field('custom', $custom);
    $p->add_field('amount', $_POST['amount']);
...
    $p->submit_paypal_post(); // submit the fields to paypal
      break;

但是,我们并没有对上面提到的变量这样做。

我们应该在 (a) 这个阶段还是在 PayPal (b) 返回数据的阶段进行验证,还是两者兼而有之?

我们还应该如何验证数据?

4

3 回答 3

1

您应该在将它们发送到 PayPal 之前对其进行验证。您应该检查空变量、类型是否正确(例如金额不应包含字母)、字符数量(如果适用)是否正确。基本上,这些字段应该反映您期望在那里找到的内容。

于 2011-01-14T12:52:12.780 回答
1

我的猜测是两种情况。

发送数据之前的验证是强制性的。

在回应时,我认为这是一件好事。

于 2011-01-14T12:52:52.530 回答
1

您应该在两端验证和验证您的数据 - 在您将用户发送到 PayPal 之前,以及当您收到确认付款的 PayPal IPN 消息时。

验证之前确保用户支付正确的金额,他们被发送到正确的 PayPal 帐户,并且您有一个针对交易的标识符(在“自定义”变量中),以允许您将付款与正确的用户结合/purchase 经 PayPal 确认后购买。

Validation After 再次确保支付了正确的金额,交易标识符存在、有效且正确,并且更新了用户/购买以反映交易结果。

于 2011-01-14T12:56:12.157 回答